when my ai agent uses any tool to do anything the memory node gives me an error that is the key field is undefined btw i am not using a chat trigger because my trigger is a webhook and my workflow is a chatbot on instagram. so summary is when i send a message that doesnt require using any tools the memory node works fine but when it does use a tool the key field become undefined btw i am putting the timestamp in the key field and i also tried putting the sender id that the webhook sends but still the same error and this error happened to me in both postgres memory node and in the simple memory.
What is the error message (if any)? Key parameter is empty
Provide a key to use as session ID in the ‘Key’ parameter or use the ‘Connected Chat Trigger Node’ option to use the session ID from your Chat Trigger
Welcome @amazingzizo to our community! I’m Jay and I am a n8n verified creator.
The problem is that inside tool execution, the memory node loses the session context because it can’t access the parent workflow’s node data the same way. Instead of referencing a node in the Key field, hardcode a stable session ID from your webhook payload using {{ $('Webhook').first().json.entry[0].messaging[0].sender.id }} - adjust the path to match your actual Instagram payload structure. Using .first() is important here because during sub-tool execution the current item context may be different. If that still fails, check your webhook payload structure in the Webhook node output to confirm the exact path to the sender ID.
@amazingzizo when Memory runs INSIDE the AI Agent’s tool execution, $(‘Webhook’) doesnt resolve because the agent’s input is whats in scope, not the workflow context. fix is to extract the session ID in a Set node BEFORE the agent runs, then reference it via $json. drop this Set node between ur Webhook and AI Agent:
then change ur Memory Key field to just: {{ $json.sessionId }}
the agent forwards its input to the memory tool, so sessionId stays accessible inside tool execution.