Skip to main content

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 persist under the ag2::<session> session scope with deterministic idempotency seeds — retries and multi-agent echoes converge on one write. Each turn is distilled server-side into durable facts; no raw transcript rows land in the user's memory.
  • Roles follow the speaker, not the hook. A message sent by an agent that speaks for a person — a UserProxyAgent, or any agent whose human_input_mode is not "NEVER" — is persisted as a human turn even when the capability is attached to that agent too; every other agent's outgoing message is an ai turn. Only human turns become facts, so this is what makes "attach it to both sides" store the person's words as memory (1.0.2; 1.0.1 labelled them ai when the proxy carried the capability, and they left no memory).
  • Tool/function messages are never persisted.
  • register_memory_tools(memory, caller=..., executor=...) adds search_memory + save_memory tools (the caller needs an llm_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      # 25 tests through REAL ConversableAgent chats

The suite includes a reproduction of zep-ag2's documented multi-agent double-store scenario (we store once), a UserProxyAgent + assistant chat with the capability on both sides (the person's words persist as a human turn), and a chat driven from inside asyncio.run() (no deadlock).

License

MIT

Metadata

Release files for ag2-memorysync 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ag2-memorysync 1.0.2
File Size Uploaded
ag2_memorysync-1.0.2.tar.gz 19.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ag2-memorysync 1.0.2
File Interpreter ABI Platform
ag2_memorysync-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / ag2_memorysync-1.0.2.tar.gz

Download URL ag2_memorysync-1.0.2.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a25de58f162490df9e0de83ff12f02dd1146e1c0f81e2f35b3b4e318077ffeff
BLAKE2b-256 checksum
How to use checksums
cc6f1880bcdc1b69e4af3d5f5aa30b7032d49b04a73dd3d5754fd035bb3f377a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / ag2_memorysync-1.0.2-py3-none-any.whl

Download URL ag2_memorysync-1.0.2-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1419d4d3e1aece3ed6662014f6a162e7ff8bc8f5844c4d1cc577244d5be61182
BLAKE2b-256 checksum
How to use checksums
72ddd952972b5b21acaaee6234fe6ba8c7328ba74a6e722b82193d3928ae7e9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

1.1.0

2 release files

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page