AutoGen Memory: How to Add Memory to AutoGen Agents

Agent FrameworksAI Agent MemoryMaximem Team29 May 20267 min read
AutoGen Memory: How to Add Memory to AutoGen Agents
On this page
  1. Where AutoGen Excels
  2. How AutoGen Memory Works Today
  3. What Synap Adds
  4. Technical Deep Dive
  5. What Synap Adds to AutoGen
  6. What Production Teams Gain
  7. How to Get Started
  8. If You Are Moving to Microsoft Agent Framework
  9. Memory Is Infrastructure

AutoGen AgentChat gives an agent memory through its Memory protocol: pass a list of stores to the memory parameter of AssistantAgent, and each adds what it retrieves to the model context. ListMemory keeps entries in order; ChromaDBVectorMemory, RedisMemory and Mem0Memory add vector search and persistent storage. Conversation state is saved with save_state and restored with load_state, as a dictionary you write to a file or database. The protocol stores what your code adds, so which facts to keep, for which user, and what replaces a changed fact stays with you or the backend. Maximem Synap adds a search tool and a store tool, scoped by user_id and an optional customer_id.

One thing to know before you invest further: the AutoGen README now says the project is in maintenance mode, will not receive new features, and that new users should start with Microsoft Agent Framework, which Microsoft describes as the direct successor to both AutoGen and Semantic Kernel (a migration guide exists). This guide is for teams already running AutoGen 0.4 or later. For a new project, skip to the Agent Framework section near the end; Synap has a separate package for it.


Where AutoGen Excels

AutoGen made structured multi-agent conversation practical. AgentChat gives you AssistantAgent for a single tool-using agent and teams such as RoundRobinGroupChat and SelectorGroupChat for managed turn-taking between several, and every agent takes a model client, a list of tools and a model context. If your system needs agents that delegate, review each other's output or wait for a human, that dialogue control is what AutoGen does well.


How AutoGen Memory Works Today

AutoGen has more memory surface than it is usually given credit for, in three layers.

Model context decides which messages reach the LLM. UnboundedChatCompletionContext keeps everything, BufferedChatCompletionContext keeps the most recent messages, HeadAndTailChatCompletionContext keeps the first and last, and TokenLimitedChatCompletionContext (marked experimental) stays under a token limit. These manage one conversation's window.

The Memory protocol has five methods: add, query, update_context, clear and close. ListMemory is the simple in-order store. ChromaDBVectorMemory persists to disk through a persistence_path, RedisMemory stores vectors in a Redis instance, and Mem0Memory connects to Mem0, cloud or local. Several of these survive a restart.

State is the third layer. save_state on an agent or a team returns a dictionary, which for AssistantAgent contains its model context, and load_state restores it on a new instance.

What remains is the policy on top. A vector store returns what is similar to the query; it does not decide what was worth storing, notice that a preference changed, or link two names for the same person. That work is either your code or the job of the backend behind the store.


What Synap Adds

Synap is agentic context management. The AutoGen package, maximem-synap-autogen 0.2.1, depends on autogen-core 0.4 or later and exports four classes.

SynapSearchTool and SynapStoreTool are BaseTool implementations. The model sees them as search_memory(query), which returns a formatted context string from the user's memory, and store_memory(content), which submits a new memory and returns an ingestion id. Scope is fixed when you construct the tool, through user_id and an optional customer_id, so the model only ever supplies the query or the content. Both tools honor AutoGen's CancellationToken: cancelling the run cancels the Synap call in flight.

SynapShortTermChatContext is a ChatCompletionContext you pass as model_context. On every get_messages() it prepends Synap's compacted summary and recent turns for the conversation as a system message, ahead of whatever the inner context returns.

SynapStreamingChatContext wraps a model context and reports each user turn, assistant turn, tool call and tool result on Synap's live stream. It needs await sdk.instance.listen() to be running; without a stream it does nothing, which is deliberate, and it means the two tools are the only write path for a caller who has not opened one.

We built this because structured agents kept stalling in production. The problem was not bad orchestration. It was missing context that lived in a different session last Tuesday. Production testing hit 92% LongMemEval, 93.2% on LoCoMo.

For why context management is infrastructure and not a feature, read What Is Agentic Context Management?. For build-versus-buy numbers, see The Real Cost of DIY Agent Memory.


Technical Deep Dive

LongMemEval Benchmark

LongMemEval tests whether agents recall facts across long, multi-turn conversations spanning multiple sessions. The benchmark simulates production conditions where users return days apart and expect the agent to remember prior context. Synap scores 92% on this benchmark.

Entity Resolution Mechanism

When the same person, place or thing appears across conversations under different labels ("John", "Mr. Smith", "my manager"), Synap's ingestion pipeline links them to one canonical entity. This happens during ingestion, not at query time, and it respects scope: entities resolved for one user do not leak to another.

Compaction and Short-Term Context

Synap keeps a compacted summary plus the recent turns for each conversation. SynapShortTermChatContext is how an AutoGen agent reads it, in a style of structured, narrative or bullet_points. If the call to Synap fails, the default is to return the inner context's messages unchanged, so the agent keeps running on its own history.

Fast and Accurate Retrieval Modes

The SDK documents fast mode as vector similarity only. Accurate mode adds a graph layer that traverses relationships between entities, then re-ranks, and it is the slower of the two. SynapSearchTool defaults to mode="accurate"; pass mode="fast" when the agent searches on every turn.

Multi-Tenant Scoping

Three ids set scope: user_id identifies the person and is required, customer_id identifies the tenant on B2B Synap instances (a B2C instance does not accept one), and conversation_id, which must be a UUID, identifies one conversation. Construct fresh tool instances for each user's run; a tool holds its ids for its lifetime.


What Synap Adds to AutoGen

Persistence

AutoGen Native. save_state and load_state for conversation state; persistent Memory stores for facts your code adds. With Synap. Hosted per-user memory that the agent reads and writes through two tools.


Entity Resolution

AutoGen Native. Depends on the memory backend; not part of the protocol. With Synap. Mentions of the same entity under different labels are linked during ingestion, inside the user's scope.


Compaction

AutoGen Native. Buffered, head-and-tail and token-limited model contexts trim the window. With Synap. A compacted summary plus recent turns through SynapShortTermChatContext.


Long-Term Recall

AutoGen Native. Not benchmarked for cross-session recall. With Synap. 92% on LongMemEval.


Failure Handling

AutoGen Native. AssistantAgent turns an exception raised inside a tool into an error result the model can read, and the run continues. With Synap. Both tools wrap SDK failures in SynapIntegrationError, logged once at ERROR with the operation name. A failed search raises as well; it does not come back as an empty result.


User Scoping

AutoGen Native. Yours to implement per store. With Synap. user_id and optional customer_id fixed per tool instance.


What Production Teams Gain

Cross-session continuity. Your user chats on Monday and returns on Wednesday. search_memory recalls what was established, and store_memory persists new facts the agent learns.

Accuracy that ships. 92% LongMemEval, 93.2% on LoCoMo measures whether agents recall facts across long, multi-turn conversations spanning multiple sessions. This benchmark tests the specific failure mode that breaks production agents: accurate recall over distance and time.

Writes that do not hold the turn. store_memory returns as soon as Synap accepts the ingestion job; extraction runs afterwards on the server.


How to Get Started

Step 1: Install

pip install maximem-synap-autogen autogen-agentchat "autogen-ext[openai]"

The Synap package brings maximem-synap and autogen-core. The other two are AutoGen's own packages for AssistantAgent and the OpenAI model client.

Step 2: Initialize and register the tools

import asyncio
import os

from autogen_agentchat.agents import AssistantAgent from autogen_ext.models.openai import OpenAIChatCompletionClient from maximem_synap import MaximemSynapSDK from synap_autogen import SynapSearchTool, SynapStoreTool

async def main(): sdk = MaximemSynapSDK(api_key=os.environ["SYNAP_API_KEY"]) await sdk.initialize()

# Create scoped memory tools for this user
search_tool = SynapSearchTool(sdk=sdk, user_id="user_123")
store_tool = SynapStoreTool(sdk=sdk, user_id="user_123")

# Register them with an AssistantAgent
agent = AssistantAgent(
    name="support_agent",
    model_client=OpenAIChatCompletionClient(model="gpt-4o"),
    tools=[search_tool, store_tool],
    system_message=(
        "Call search_memory to recall prior context before answering. "
        "Call store_memory to save durable facts the user provides."
    ),
    reflect_on_tool_use=True,
)

result = await agent.run(task="What did I tell you about my billing plan?")
print(result.messages[-1].content)

await sdk.shutdown()

asyncio.run(main())

Step 3: Deploy

Construct the tools per user run, add customer_id= on a B2B instance, and watch your logs for SynapIntegrationError: inside an AssistantAgent the model sees a failed memory call as a tool error, and the log line is how you see it.

Full config, scoping rules, and error handling: https://docs.maximem.ai/integrations/autogen


If You Are Moving to Microsoft Agent Framework

Agent Framework has context providers for agent memory, and Synap's package for it is maximem-synap-microsoft-agent 0.3.1, which requires agent-framework 1.0 or later.

pip install maximem-synap-microsoft-agent
from agent_framework.openai import OpenAIChatClient
from synap_microsoft_agent import SynapContextProvider, SynapHistoryProvider

# sdk is an initialized MaximemSynapSDK, as in Step 2

client = OpenAIChatClient(model="gpt-4o-mini")

agent = client.as_agent( name="MemoryAgent", instructions="You are a helpful assistant.", context_providers=[ SynapContextProvider(sdk=sdk, user_id="user_123"), SynapHistoryProvider(sdk=sdk, user_id="user_123"), ], )

SynapContextProvider fetches Synap context before each run and records the turn after it, so memory no longer depends on the model choosing to call a tool. SynapHistoryProvider persists the message log and loads it on session resume. The package also backs the memory and file stores of Agent Framework's harness, which needs agent-framework 1.13 or later and is marked experimental upstream.


Memory Is Infrastructure

AutoGen gave developers a framework for structured multi-agent conversations, with a real protocol for plugging memory in. Deciding what to remember about each user, keeping it correct as it changes and retrieving it weeks later is a different layer of the stack, and it stays the same layer when you move to Agent Framework.

Memory is infrastructure, not a feature.

Start building AutoGen agents that remember across sessions (https://synap.maximem.ai)

Synap pricing is usage-based. You pay for memory operations: storage, retrieval, compaction. No per-seat or per-framework surcharge. The $49/month starter plan includes a base allocation; usage beyond that is metered by operation. Every new account gets $25 in free credits to test before committing. See full pricing at https://synap.maximem.ai/pricing.


Related Posts

From the team at Maximem

Stop rebuilding agent memory from scratch

Maximem Synap is the context management layer we built after hitting every problem in this post ourselves. Persistent recall across sessions, entity resolution and conscious forgetting, in Python, TypeScript and REST.

Related posts

Looking for more to read? See our directory of the best engineering blogs to follow.