ag2-memorysync
MemorySync for AG2
(the classic AutoGen ConversableAgent framework, pip install autogen):
an automatic memory loop — recall injected before every reply, both sides
persisted, zero extra code per turn.
pip install ag2-memorysync
Quick start
from autogen import ConversableAgent
from ag2_memorysync import MemorySyncCapability
assistant = ConversableAgent("assistant", llm_config=...)
memory = MemorySyncCapability(
api_key="ms_...", # or MEMORYSYNC_API_KEY
user_id="customer-42", # required — who these memories belong to
session_id="support-chat", # scopes the transcript
)
memory.add_to_agent(assistant) # that's the whole integration
From then on every incoming user message is persisted and enriched with
recalled context, and every outgoing reply is persisted — through AG2's
own hook system (process_last_received_message +
process_message_before_send).
Why this one
| Mem0 | Zep (zep-ag2) |
MemorySync | |
|---|---|---|---|
| AG2 adapter exists | ✗ docs show an AutoGen-0.2 recipe with placeholder model names | ✓ | ✓ |
| Multi-agent duplication | — | ✗ documented bug: two attached agents store every utterance twice with conflicting roles | ✓ cross-hook dedup registry + idempotency seeds — one utterance, one row (by test) |
| Sync→async bridge | — | per-call event-loop spin; documented deadlock caveat under asyncio | ✓ one persistent background loop; never touches the caller's loop (asyncio-driven chats pass, by test) |
| Recall latency budget | — | ✗ none | ✓ hard 1.2s default — the reply is never late |
| Framework pin | — | ✗ ag2<1 — breaks on the v1 rewrite |
✓ zero framework dependency (duck-typed attach; works with whichever classic distribution you installed) |
| Injected context re-stored? | — | system-message mutation, last-write-wins | ✓ hook output feeds the LLM only; the ORIGINAL text is what persists |
Semantics worth knowing
- The reply is never stalled and never broken. Recall blocks at most
recall_timeout(default 1.2s); persistence is fire-and-forget off the hot path. Outages and quota exhaustion degrade to "no memories this turn". - Turns store verbatim under the
ag2::<session>transcript scope with deterministic idempotency seeds — retries and multi-agent echoes converge on one stored row. - Tool/function messages are never persisted.
register_memory_tools(memory, caller=..., executor=...)addssearch_memory+save_memorytools (the caller needs anllm_config, as usual for AG2 tools).memory.flush()waits for in-flight writes (shutdown/tests);memory.close()flushes and releases the HTTP client.
Configuration
| Parameter | Default | Meaning |
|---|---|---|
user_id |
— (required) | End user the memories belong to |
session_id |
"default" |
Transcript scope |
top_k |
5 |
Memories considered per turn |
recall_timeout |
1.2 |
Hard recall budget, seconds |
min_prompt_chars |
8 |
Skip recall for trivial messages |
context_template |
built-in | {context} placeholder, brace-safe .replace rendering |
capture |
"both" |
"received" / "sent" to capture one side only |
Development
pip install -e . "autogen[openai]" pytest
python -m pytest tests -q # 22 tests through REAL ConversableAgent chats
The suite includes a reproduction of zep-ag2's documented multi-agent
double-store scenario (we store once) and a chat driven from inside
asyncio.run() (no deadlock).
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ag2_memorysync-1.0.0.tar.gz.
File metadata
- Download URL: ag2_memorysync-1.0.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4088611df6ce5a56f875bff82fe1ec5265e74b268db1f120c98afb4393e9c0bf
|
|
| MD5 |
741218dfca9fc2200fb180e1f3eb4dbc
|
|
| BLAKE2b-256 |
9b2874751cac1c89cc7424392d9b5ec3035950d4f33745e6c9b34a764491d1b2
|
File details
Details for the file ag2_memorysync-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ag2_memorysync-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7231f74cb1e58e25a7969cff9150ea66fb14c61353471f2df9287e645f816815
|
|
| MD5 |
2b7fd88f956edf3cf7668989749611fa
|
|
| BLAKE2b-256 |
d7874d8973b34f3d2d064a1ebdaac80ffd452518dfdd75f7c4a9d5692cefc668
|