AI Agent is Producing the Response in Json Format instead of doing task

when i connect a chat message trigger node with ai agent and also connect google sheet and google mail action node to insert data and send an email. Sometimes the AI Agent is producing a valid output and send a mail and insert data in google sheets. But sometimes it produces the JSON output in the chat response instead of sending a mail and inserting the data in the google sheet.
How can fix this problem.

Hey!

Adjust agent system prompt with clear instructions, even examples. Try use persistent memory.

First try the prompt with the memory detached, when it behaves well attach memory.