New Tool Radar

AI Agents & Automation

How to Add Short-Term Memory So an Agent Remembers the Conversation

Give an agent short-term memory of the current conversation, so it stops asking for facts the user already gave.

Schematic illustration with three step boxes: keep the message history, summarise when it grows, and test a follow-up.

Short-term memory is the conversation itself: the messages so far, kept in the context window so the agent can refer back to them. Without it, every turn starts fresh and the agent asks for the order number twice. With it, a follow-up question such as what about the warranty can be answered from the earlier turn. The cost is tokens: every prior message re-enters the count with each new turn.

Before you start

An agent loop that can pass the message history back to the model, and a test conversation with a follow-up question.

Keep the message history in the call

Send the full message history with each new turn: system message, user messages, assistant replies and tool results, in order. The model needs the history to know what was already said.

Keep the tool results in the history too: the agent’s memory of what it found lives in those results, not only in the chat text.

Summarise the history when it grows

When the history nears the context budget, summarise the oldest turns into a short note and keep the recent turns whole. A summary keeps the facts and drops the wording.

Write the summary with the model itself, and check it keeps the key facts: names, numbers, decisions. A summary that drops the order number is worse than no summary.

Test a follow-up question

Run a two-turn conversation: give the agent a fact in the first turn, such as the order number, and ask a follow-up in the second that needs that fact. The agent should answer without asking for the fact again.

If it asks again, the history is not reaching the model: check the message list, not the prompt.

Practice check: fictional Maple Corner support chat, 2 turns

The table below is fictional practice material, worked out by hand from the stated conversation. It is the expected result for the practice chat, not a run of any agent.

Turn User says Agent does Verdict
1 Order ORD-4821 arrived broken Looks up ORD-4821 Pass
2 What about the warranty? Answers from turn 1 order Pass – remembers
2, no memory What about the warranty? Asks: which order? Fail – forgot

With the history kept, the agent answers the warranty question from the order in turn 1. Without it, the agent has to ask which order, which is the failure short-term memory prevents.

Expected result. UNTESTED: the turns in the practice table are worked out by hand, not measured by running an agent. Run your own two-turn conversation, give a fact in the first turn, and check that the follow-up uses it without asking again.

Limits

  • History costs tokens: every prior message re-enters the token count with each new turn, so summarise old turns.
  • Short-term memory lasts one conversation: it does not survive a restart or a new session.

Sources

See all