Zep memory integration for AG2 (AutoGen community fork)
Project description
zep-ag2
Zep memory integration for AG2
Installation
pip install zep-ag2
Quick Start
System Message Injection
import asyncio
import os
from autogen import AssistantAgent, UserProxyAgent, LLMConfig
from zep_cloud.client import AsyncZep
from zep_ag2 import ZepMemoryManager, register_all_tools
async def main():
zep = AsyncZep(api_key=os.environ["ZEP_API_KEY"])
llm_config = LLMConfig(
{"model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]}
)
assistant = AssistantAgent(
name="assistant",
llm_config=llm_config,
system_message="You are a helpful assistant with long-term memory.",
)
user_proxy = UserProxyAgent(
name="user",
human_input_mode="NEVER",
code_execution_config=False,
is_termination_msg=lambda msg: "TERMINATE" in (msg.get("content") or ""),
)
# Enrich agent with memory context
memory_mgr = ZepMemoryManager(zep, user_id="user123", session_id="session456")
await memory_mgr.enrich_system_message(assistant, query="conversation topic")
# Register memory tools (sync — AG2 calls them automatically)
register_all_tools(assistant, user_proxy, zep, user_id="user123", session_id="session456")
result = user_proxy.initiate_chat(
assistant, message="What do you remember about me?"
)
asyncio.run(main())
Tool-Based Memory Access
from zep_ag2 import create_search_graph_tool, create_add_graph_data_tool
# Create tools bound to a user's knowledge graph
search_tool = create_search_graph_tool(zep, user_id="user123")
add_tool = create_add_graph_data_tool(zep, user_id="user123")
# Register with AG2's decorator pattern
assistant.register_for_llm(description="Search knowledge graph")(search_tool)
user_proxy.register_for_execution()(search_tool)
assistant.register_for_llm(description="Add to knowledge graph")(add_tool)
user_proxy.register_for_execution()(add_tool)
Features
- Tool-based memory access — Register Zep search/add as AG2 tools via
@register_for_llm - System message injection — Automatically enrich agent context with relevant memories
- Knowledge graph — Access Zep's knowledge graph from AG2 agents
- Conversation memory — Store and retrieve thread-based conversation history
- Sync tool execution — Tools run synchronously via a single shared background event loop, compatible with AG2's execution model on Python 3.11–3.13
API Reference
ZepMemoryManager
Manages Zep memory for AG2 agents via system message injection.
ZepMemoryManager(client, user_id, session_id=None)— Initialize with Zep clientawait enrich_system_message(agent, query=None, limit=5)— Inject memory contextawait get_memory_context(query=None, limit=5)— Get formatted context stringawait add_messages(messages)— Store messages in Zep threadawait get_session_facts()— Get extracted session facts
ZepGraphMemoryManager
Manages Zep knowledge graph for AG2 agents.
ZepGraphMemoryManager(client, graph_id)— Initialize with graph IDawait search(query, limit=5, scope="edges")— Search the graphawait add_data(data, data_type="text")— Add data to the graphawait enrich_system_message(agent, query=None, limit=5)— Inject graph context
Tool Factories
All tool factories return synchronous callables (AG2 executes tools synchronously).
Internally they bridge to the async Zep SDK on a single shared background event loop,
reusing the AsyncZep client you pass in (no per-call client construction).
create_search_memory_tool(client, user_id, session_id=None)— Search conversation memorycreate_add_memory_tool(client, user_id, session_id=None)— Add conversation memorycreate_search_graph_tool(client, user_id=None, graph_id=None)— Search knowledge graphcreate_add_graph_data_tool(client, user_id=None, graph_id=None)— Add graph dataregister_all_tools(agent, executor, client, user_id, ...)— Register all tools at once
Examples
- Basic Memory — System message injection + memory tools
- Graph Memory — Knowledge graph with ZepGraphMemoryManager
- Search Tools — Read-only search tool registration
- Full Tools — All tools in a GroupChat with multiple agents
- Manual Test — End-to-end integration test with real APIs
Configuration
Environment Variables
# Required
export ZEP_API_KEY="your-zep-cloud-api-key"
# Required for examples that use LLM
export OPENAI_API_KEY="your-openai-api-key"
Development
make install # Install dev dependencies
make pre-commit # Format, lint, type-check, test
make ci # CI validation
Requirements
- Python 3.11+
ag2>=0.9.0zep-cloud>=3.23.0
License
Apache-2.0 — see LICENSE for details.
Support
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
Project details
Release history Release notifications | RSS feed
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 zep_ag2-0.1.0.tar.gz.
File metadata
- Download URL: zep_ag2-0.1.0.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceff283fbdbe9b15173a5d9b4de5cac1cbf4174aef01a640e3c57e0735644e8b
|
|
| MD5 |
d3b206899e44831ad00edacb979c00f2
|
|
| BLAKE2b-256 |
bc783efa2b446dcbd7fee72800aae72940e977b3c94236070b3bb1f71150de2c
|
Provenance
The following attestation bundles were made for zep_ag2-0.1.0.tar.gz:
Publisher:
release-integrations.yml on getzep/zep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zep_ag2-0.1.0.tar.gz -
Subject digest:
ceff283fbdbe9b15173a5d9b4de5cac1cbf4174aef01a640e3c57e0735644e8b - Sigstore transparency entry: 1953947988
- Sigstore integration time:
-
Permalink:
getzep/zep@db65994287fd6ad943eeabf6abbe45f056065a4c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/getzep
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-integrations.yml@db65994287fd6ad943eeabf6abbe45f056065a4c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file zep_ag2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zep_ag2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c388b255c751fdd41efbc43043ba92c23c2e14639c7dcfffb6b38b2f11fa672a
|
|
| MD5 |
e4f56c3451bf329d45764a428912edb7
|
|
| BLAKE2b-256 |
02053d8c62638cf500fadf49731fded39fa199da099b0629271384e86c5e6e35
|
Provenance
The following attestation bundles were made for zep_ag2-0.1.0-py3-none-any.whl:
Publisher:
release-integrations.yml on getzep/zep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zep_ag2-0.1.0-py3-none-any.whl -
Subject digest:
c388b255c751fdd41efbc43043ba92c23c2e14639c7dcfffb6b38b2f11fa672a - Sigstore transparency entry: 1953948115
- Sigstore integration time:
-
Permalink:
getzep/zep@db65994287fd6ad943eeabf6abbe45f056065a4c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/getzep
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-integrations.yml@db65994287fd6ad943eeabf6abbe45f056065a4c -
Trigger Event:
workflow_dispatch
-
Statement type: