Describe the problem/error/question
i have a problem with my workflow. When the AI uses the cerrar_conversacion tool, for some reason all past variables and info become undefined, making impossible to close the chat. why is this?
Please share your workflow
Information on your n8n setup
- n8n version: latest stable
- Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
Welcome, @Sergio_Jimenez
In your âReset User Flowâ node, the filter is currently empty. It looks like this in your code: "keyValue": "="
Because the phone number is missing, n8n searches your database for a user with no phone number, finds nothing, and returns an empty result.
Because âReset User Flowâ found no one to reset, it produced 0 results. Consequently, the next node, âSend AI Responseâ, never receives any data to work with. When you look at the execution, it appears as âundefinedâ because the âwaterâ stopped flowing before it reached the end.
So this is what happened:-
Your AI is successfully calling the tool ->-> the IF node successfully detects the âGoodbyeâ ->-> but the Reset User Flow node is searching for a âblankâ user ->-> the flow stops ->-> the final message is never sent.
Can you try this?
Hi @kjooleng, thank you for your response. I tried fixing the Reset user node, i even deleted it but still nothing. It looks like that when the AI Agent uses the cerrar_conversacion tool, somehow all the info in the past nodes become undefined, but ONLY when the AI uses that tool.
Again, thanks for your excellent response, but im still facing the problem 
Did you turn on âAlways Output Dataâ?
Also, did you try the workflow that I had posted?
yup, i have the always output data and i copied your workflow, still nothing
@SergioJimenez when the agent calls cerrarconversacion, the sub-execution loses the $(âWhatsApp Triggerâ) reference since tools run in their own context, so contacts[0].waid is undefined. Pass waid as a tool argument via $fromAI() instead:
{ "parameters": { "operation": "send", "phoneNumberId": "1070498016153785", "recipientPhoneNumber": "={{ $fromAI('wa_id', 'WhatsApp ID of the user', 'string') }}", "textBody": "=ConversaciĂłn cerrada. ÂĄHasta pronto!" }, "type": "n8n-nodes-base.whatsAppTool" }
Reattach your WhatsApp creds and the agent passes wa_id automatically.
This was the problem, i had to pass the parameters to the AI so that it would return to me on the âSend AI Responseâ node, becoming magically available, i still donât understand why using a really simple tool would break completely my instance, but itâs solved. If anyone knows a better way to do what i need on my chatbot, it would be really appreciated.
Thanks for all your responses.
Glad you got it working @Sergio_Jimenez! And thanks for sharing the solution, it helps everyone who hits this later.
To answer your âwhyâ question: this is actually expected behavior in how n8n AI Agent tools work, not a bug.
When the AI Agent calls a tool (like your cerrar_conversacion tool), execution context resets for that toolâs sub-execution. The tool runs in its own isolated scope, so it doesnât automatically inherit variables from the parent workflow or from nodes upstream of the Agent node. The Agent is designed this way intentionally, because tools are meant to be modular and reusable.
The standard pattern to handle this is exactly what you found: pass the required data as tool parameters from the AIâs conversation context. The AI agent includes those parameters in its tool call, and they arrive at your toolâs input properly.
Best practice for chatbots:
- Store session data (phone number, user ID, chat ID) in your toolâs input parameters
- The Agent LLM is smart enough to extract and pass these from the conversation if you define the parameter descriptions clearly in the tool
- For persistent data across tool calls in the same session, use a memory store (like Redis or a simple Google Sheet as a session store) keyed by session ID
If this explanation helps clarify things, feel free to mark one of the replies as a Solution so the thread is easier to find for others with the same question!