Issue: Tool Calls not beeing saved to Memory

Issue

The way the AI Agent node saves messages into memory is flawed when it comes to tool calls.
The tool calls and the tool responses appear not to be saved in the memory as per my testing.

This is a major issue. Here are some real examples of issues:

  1. An LLM that sees that it previously responded to a question by hallucinating a response instead of checking with a tool call (which it actually did, but that tool call is not saved in the memory).
    => This will lead to the LLM actually hallucinating a response instead of using a tool to verify.

  2. If a stateful tool returned important information and the user asks one message later about that information, the AI Agent can’t answer the question, as the Tool response is not visible anymore and rerunning it will lead to a different response or might trigger processes again.

And I could name many more examples.

I can not stress enough how critical it is to have the tool calls and the tool responses saved to memory.

Context

I usually code my AI Agents in python, but I really like the AI Agent node simplicity, especially with memory.
But this problem makes it unusable in complex long live conversations where the agent has tools.
Would really love for this to change or be a ‘Option’ I can set.

I do understand that this is a bit difficult, because different LLM providers want different tool JSON structures, but I think it’s needed.

Would love to hear any feedback.
I can also help with this if required.

Information on my n8n setup

  • n8n version: 1.84
  • Database (default: SQLite): simple memory default
  • Running n8n via: webapp

Hey @Merlin_Richter
You have a good point there, but memory nodes that are attached straight to Agent are there just to store chat history (messages between agent and the user).
For more complex scenarios you are free to update your chat history with additional data and you have few options for that:

  1. If you are using external service, like Redis, you can use tool outputs and store them manually using Redis node
  2. Use built-in memory manager node to enrich your chat history in a similar way

You will also probably want to make sure that all this data is fed back to the agent with every subsequent message.

Hi @milorad , just a quick follow up on this topic, if possible.

What would be the pattern to use the memory manager node to store the tools responses? I don’t see where in the workflow we can plug it in a way that we can retrieve the tool response and insert it on the memory… Maybe I’m missing something here?

Thanks

1 Like

@milorad do you have an example of how to set this up, I am using MongoDB for the memory and have the same issue and would like to store the tool output back in the history so It can keep track as it does multiple calls?

I became so annoyed about that problem that I created a new AI Agent node that fixes it. It correctly saves Tool and Tool Result messages to the conversation history.

Link here: n8n-nodes-better-ai-agent - npm and can be installed as a community node

Also added a “Webhook URL” that you can define to send intermediate steps as they happen, instead of having to wait for the entire output.

2 Likes

that’s awesome! and i see, downloads are growing. I wonder if n8n team can join to collaborate to make one better node together

Just downloaded and will give it a try! Thanks putting in the legwork!