Feature Request: Add configurable memory persistence policies so AI Agents store only relevant long-term context instead of every intermediate tool call and execution message, reducing token usage and context bloat

Feature Request: Configurable Memory Policies for AI Agent (Temporary Execution Memory vs Persistent Memory)

Hi n8n team,

While building a Data Analyst AI Agent with the native AI Agent node, I noticed a limitation in how memory is currently managed. I believe addressing this would significantly reduce token usage, improve scalability, and give users much finer control over conversational memory.


Current Behavior

Suppose I ask the agent:

“Inspect the database schema.”

The agent performs multiple reasoning steps:

User
   │
   ▼
LLM
   │
   ▼
SQL Tool (List tables)
   │
   ▼
LLM
   │
   ▼
SQL Tool (Inspect customers)
   │
   ▼
LLM
   │
   ▼
SQL Tool (Inspect orders)
   │
   ▼
...
   │
   ▼
Final Answer

This is expected and works well.

However, the Memory node stores the entire execution history, including every intermediate tool interaction.

Example of what gets stored:

System:
You are an expert PostgreSQL Data Analyst.

User:
Inspect schema.

Assistant:
Calling SQL Tool

Tool:
SELECT ...

Assistant:
Calling SQL Tool

Tool:
SELECT ...

Assistant:
Calling SQL Tool

Tool:
SELECT ...

Assistant:
Calling SQL Tool

Tool:
...

Assistant:
Final response...


The Problem

This execution history is then reused for future conversations.

As a result:

  • Every SQL tool call is stored.

  • Every tool output is stored.

  • Intermediate execution details become permanent conversation history.

  • Context size grows rapidly.

  • Token usage increases unnecessarily.

  • Long-running agents become increasingly inefficient.

In my case, a single user prompt resulted in approximately 7 LLM invocations, and the entire execution chain was written into memory.


Proposed Solution

Separate Execution Memory from Persistent Memory.

Execution Memory (Temporary)

During one agent execution:

User
      │
      ▼
Temporary Execution Memory
      │
      ▼
LLM ↔ Tool ↔ LLM ↔ Tool ↔ LLM

This memory exists only while the workflow is running.

It contains:

  • System prompt

  • User message

  • Tool calls

  • Tool outputs

  • Intermediate reasoning

  • Final answer

Once execution finishes, this temporary memory can be discarded.


Persistent Memory

Instead of automatically saving the entire execution, n8n should apply a configurable Memory Policy before writing anything permanently.

For example:

Temporary Execution Memory
            │
            ▼
     Memory Policy
            │
            ▼
Persistent Memory


Suggested Memory Policies

1. Store Everything (Current Behavior)

For users who prefer the existing behavior.


2. Store Only User + Final Assistant Messages

Store:

User:
Inspect schema.

Assistant:
The database contains four tables...

Ignore all intermediate tool interactions.

No additional LLM call required.


3. Ignore Tool Calls

Automatically remove:

  • assistant tool calls

  • tool messages

Keep only the conversational exchange.

No additional LLM call required.


4. Ignore Tool Outputs

Useful when tools return large payloads (SQL results, RAG documents, API responses).

No additional LLM call required.


5. AI Summary (Optional)

Some users may prefer long-term summarized memory.

Example:

Conversation Summary

- Database schema explored.
- Four tables identified.
- User is analyzing ecommerce sales.

This would require one additional LLM call and should be optional.


6. Custom Memory Processor Node

This would be the most flexible solution.

Example:

Temporary Execution Memory
            │
            ▼
Memory Processor Node
            │
            ▼
Persistent Memory

Users could implement:

  • JavaScript filtering

  • Python processing

  • AI summarization

  • Regex extraction

  • Custom business logic

before writing to memory.

This would make memory behavior fully customizable without changing the AI Agent itself.


Why This Matters

Many real-world agents perform dozens of tool calls:

  • SQL

  • RAG

  • MCP servers

  • REST APIs

  • File processing

  • Code execution

These intermediate execution steps are necessary to solve the current task, but they are rarely useful as long-term conversational memory.

Separating temporary execution memory from persistent conversational memory would:

  • Reduce token consumption

  • Improve performance

  • Keep memory relevant

  • Scale better for complex agents

  • Give developers full control over memory retention


Questions

  1. Is the current behavior (persisting the entire execution history) intentional?

  2. Are there any plans to support configurable memory policies?

  3. Would the maintainers consider separating temporary execution memory from persistent memory as described above?

I believe this would be a valuable enhancement for anyone building production AI agents with extensive tool usage.

Thanks for considering this feature request!

1 Like

the k/v table above works until a value changes. UPDATE loses the history, INSERT leaves two contradicting rows and the agent picks one at random. we ended up with: an append-only events table (never touched after insert), a facts table with status (‘active’/‘superseded’) + valid_from, and updates done as insert-new + mark-old-superseded in one transaction. the context query is just WHERE status=‘active’, and the full history stays around for debugging why the agent said something weird.

also, put dates in the injected text itself, like “2026-06-22 (8 weeks ago):”. models won’t reliably work out how old a raw timestamp is, but they read the relative version fine.

I agree with @BigOD2307 's approach: keep the full history and only feed the model what’s currently relevant. I think that also answers the design question here. Rather than deciding what to persist, just persist everything and apply a policy to what you replay. You can then keep the full trail for debugging and can change the policy as needed. It’s what we’ve been doing for our own tool-heavy workflows too.

As a side note: we have ended up building our own community node that covers a lot of the context issues we’ve encountered (this specific case included, as re-sending tool results cost us quite a lot in tokens). Be happy to set you up with it, or you can just have a look here Twigg - Stateful LLM API .

Regardless, I agree with the pain here. Tool-heavy agents do get expensive fast once every turn re-sends everything that came before. It’d be great to see n8n handle this natively in the AI Agent node without needing a workaround.

A workaround that works today, until there’s a native policy setting: take the memory node off the AI Agent and manage the history yourself with the Chat Memory Manager node, so only the user’s message and the final answer are ever stored.

  1. Before the agent: a Chat Memory Manager set to Get Many Messages, connected to your Postgres Chat Memory (session key = your user or chat ID). Keep it to the last 10 or so messages.
  2. AI Agent with no memory attached. Pass the loaded history into the prompt as plain text, followed by the new question. The agent still makes all its SQL tool calls inside the run, but none of that gets written to memory.
  3. After the agent: a second Chat Memory Manager set to Insert Messages, writing two messages: the user’s input as type User and the agent’s output as type AI.

The schema-inspection steps then live only in the execution log, and on the next turn the model sees just the clean question and answer. If some facts from the tool work should persist (say, “orders has a status column”), write those to a separate table the way @BigOD2307 described and inject the active rows into the system message.

Full disclosure: I work on MemorySync, which has an n8n community node for persistent per-user memory, but the native setup above covers this case on its own.