AutoGen Memory
A real Memory-protocol implementation for Microsoft AutoGen (autogen-agentchat 0.4+): recalled context injected before every model call under a hard latency budget, role-aware retrieval, duplicate-proof persistence, and a clear() that cannot wipe a customer by accident. Install autogen-memorysync from PyPI.
What installs
pip install autogen-memorysync
update_context runs automatically before every model call: relevant memories are recalled, injected as a SystemMessage, and surfaced to observers as a MemoryQueryEvent — the framework’s own eventing, not a side channel.
| Mem0 (`autogen-ext[mem0]`) | Zep (`zep-autogen`) | Supermemory | MemorySync | |
|---|---|---|---|---|
| Async correctness | ✗ sync client inside async methods — blocks the event loop | ✓ | — no adapter at all | ✓ async httpx throughout |
| Recall latency budget | ✗ none | ✗ none | — | ✓ hard 1.2s default, tested against a slow backend |
| Retrieval query | ✗ messages[-1] — assistant text after a tool result | last context message | — | ✓ last user message, role-aware |
| Explicit query() on failure | ✗ silently returns empty — outage looks like amnesia | logged | — | ✓ raises; only the hot path fails open |
clear() blast radius | ✗ the entire user | ✗ the entire user | — | ✓ session-scoped by default; whole-user wipe is an explicit opt-in |
| Retry safety | ✗ | ✗ | — | ✓ deterministic idempotency seeds |
| Docs for the current API | △ docs page shows the old 0.2 recipe | ✗ integration pages 404 | — | ✓ this page |
The capture loop
By verified design, AutoGen never calls `add()` automatically — retrieval and storage are separated, and storage is the application’s job. add_turn_pair(user_text, assistant_text) reduces that job to one call per exchange: both sides store verbatim under the autogen::<session> transcript scope with deterministic idempotency seeds, so a retried call converges on one stored row instead of a duplicate.
| Guarantee | How |
|---|---|
| A reply is never late | Recall waits at most recall_timeout (default 1.2s); on a miss the agent answers without memories |
| An outage never breaks the agent | update_context catches everything, logs a warning, injects nothing |
| Retries never duplicate | Seeds derived from role + session + content hash |
| Your metadata dict is safe | Copied before reading — never mutated (the Mem0 adapter pops keys out of the dict you handed it) |
clear() cannot nuke a customer | Session-scoped deletion by default; clear_scope="user" is an explicit, documented opt-in |
Memory as agent tools
from autogen_memorysync import create_memory_toolstools = create_memory_tools(memory) # search_memory + save_memoryagent = AssistantAgent("assistant", model_client=...,memory=[memory], tools=tools)
save_memory goes through the server’s extraction path, so the server — not the model — decides whether the text is durable enough to keep. Free-tier quota exhaustion stays silent by design (adds accepted-without-storing, reads empty); evaluation keys surface truthful 429s.
Configuration
| Parameter | Default | Meaning |
|---|---|---|
user_id | — (required) | End user the memories belong to — never auto-generated (a random namespace strands data) |
session_id | default | Transcript scope: autogen::<session> |
top_k | 5 | Memories considered per turn |
recall_timeout | 1.2 | Hard recall budget in seconds |
min_prompt_chars | 8 | Skip recall for trivial prompts |
context_template | built-in | {context} placeholder; brace-safe .replace rendering |
clear_scope | session | clear() blast radius; "user" opt-in wipes everything |
Supported versions
| Surface | Requires | Verified on |
|---|---|---|
autogen-memorysync 1.0.0 | autogen-agentchat / autogen-core 0.4+ (Python 3.10+) | 33 CI checks against the latest autogen-agentchat: a REAL AssistantAgent driven via the official ReplayChatCompletionClient (SystemMessage injection in the true turn order, MemoryQueryEvent emission), the role-aware retrieval regression, the 1.2s budget vs a slow backend, session-scoped clear, seed idempotency, metadata non-mutation, and both monthly-quota server modes |