zep-ag2 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zep_ag2-0.1.0/.env.example +6 -0
- zep_ag2-0.1.0/.gitignore +104 -0
- zep_ag2-0.1.0/CHANGELOG.md +32 -0
- zep_ag2-0.1.0/Makefile +81 -0
- zep_ag2-0.1.0/PKG-INFO +193 -0
- zep_ag2-0.1.0/README.md +159 -0
- zep_ag2-0.1.0/SETUP.md +61 -0
- zep_ag2-0.1.0/examples/ag2_basic.py +71 -0
- zep_ag2-0.1.0/examples/ag2_graph.py +67 -0
- zep_ag2-0.1.0/examples/ag2_tools_full.py +76 -0
- zep_ag2-0.1.0/examples/ag2_tools_search.py +56 -0
- zep_ag2-0.1.0/examples/manual_test.py +345 -0
- zep_ag2-0.1.0/pyproject.toml +104 -0
- zep_ag2-0.1.0/src/zep_ag2/__init__.py +48 -0
- zep_ag2-0.1.0/src/zep_ag2/exceptions.py +30 -0
- zep_ag2-0.1.0/src/zep_ag2/graph_memory.py +235 -0
- zep_ag2-0.1.0/src/zep_ag2/memory.py +238 -0
- zep_ag2-0.1.0/src/zep_ag2/tools.py +427 -0
- zep_ag2-0.1.0/tests/__init__.py +0 -0
- zep_ag2-0.1.0/tests/test_basic.py +961 -0
- zep_ag2-0.1.0/tests/test_integration.py +304 -0
zep_ag2-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# If you prefer the allow list template instead of the deny list, see community template:
|
|
2
|
+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
|
3
|
+
#
|
|
4
|
+
# Binaries for programs and plugins
|
|
5
|
+
out/
|
|
6
|
+
*.exe
|
|
7
|
+
*.exe~
|
|
8
|
+
*.dll
|
|
9
|
+
*.so
|
|
10
|
+
*.dylib
|
|
11
|
+
|
|
12
|
+
# Secrets
|
|
13
|
+
.env
|
|
14
|
+
.env.local
|
|
15
|
+
|
|
16
|
+
# Test data
|
|
17
|
+
test_data
|
|
18
|
+
|
|
19
|
+
# Test binary, built with `go test -c`
|
|
20
|
+
*.test
|
|
21
|
+
|
|
22
|
+
# Output of the go coverage tool, specifically when used with LiteIDE
|
|
23
|
+
*.out
|
|
24
|
+
|
|
25
|
+
# Dependency directories (remove the comment below to include it)
|
|
26
|
+
# vendor/
|
|
27
|
+
|
|
28
|
+
# Go workspace file
|
|
29
|
+
.idea
|
|
30
|
+
.vscode
|
|
31
|
+
|
|
32
|
+
# VSCode local history
|
|
33
|
+
.history
|
|
34
|
+
|
|
35
|
+
# Python
|
|
36
|
+
__pycache__/
|
|
37
|
+
*.py[cod]
|
|
38
|
+
*$py.class
|
|
39
|
+
*.so
|
|
40
|
+
.Python
|
|
41
|
+
build/
|
|
42
|
+
develop-eggs/
|
|
43
|
+
dist/
|
|
44
|
+
downloads/
|
|
45
|
+
eggs/
|
|
46
|
+
.eggs/
|
|
47
|
+
lib/**/*.py
|
|
48
|
+
lib/**/*.pyc
|
|
49
|
+
lib/**/__pycache__/
|
|
50
|
+
lib/**/site-packages/
|
|
51
|
+
lib64/
|
|
52
|
+
parts/
|
|
53
|
+
sdist/
|
|
54
|
+
var/
|
|
55
|
+
wheels/
|
|
56
|
+
share/python-wheels/
|
|
57
|
+
*.egg-info/
|
|
58
|
+
.installed.cfg
|
|
59
|
+
*.egg
|
|
60
|
+
MANIFEST
|
|
61
|
+
|
|
62
|
+
# Virtual environments
|
|
63
|
+
venv/
|
|
64
|
+
env/
|
|
65
|
+
ENV/
|
|
66
|
+
env.bak/
|
|
67
|
+
venv.bak/
|
|
68
|
+
.venv/
|
|
69
|
+
|
|
70
|
+
# PyCharm
|
|
71
|
+
.idea/
|
|
72
|
+
|
|
73
|
+
# Jupyter Notebook
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
|
|
76
|
+
# pyenv
|
|
77
|
+
.python-version
|
|
78
|
+
|
|
79
|
+
# pytest
|
|
80
|
+
.pytest_cache/
|
|
81
|
+
.coverage
|
|
82
|
+
|
|
83
|
+
# mypy
|
|
84
|
+
.mypy_cache/
|
|
85
|
+
.dmypy.json
|
|
86
|
+
dmypy.json
|
|
87
|
+
|
|
88
|
+
# UV (Python package manager)
|
|
89
|
+
uv.lock
|
|
90
|
+
.uv_cache/
|
|
91
|
+
__pypackages__/
|
|
92
|
+
|
|
93
|
+
# Log files
|
|
94
|
+
*.log
|
|
95
|
+
|
|
96
|
+
# macOS
|
|
97
|
+
.DS_Store
|
|
98
|
+
|
|
99
|
+
# Node.js
|
|
100
|
+
node_modules/
|
|
101
|
+
dist/
|
|
102
|
+
|
|
103
|
+
# Coverage (integration test runs)
|
|
104
|
+
coverage.xml
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the zep-ag2 package will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-06-17
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of zep-ag2 integration package
|
|
12
|
+
- `ZepMemoryManager` for system message injection and conversation memory
|
|
13
|
+
- `ZepGraphMemoryManager` for knowledge graph operations
|
|
14
|
+
- Tool factories: `create_search_memory_tool`, `create_add_memory_tool`,
|
|
15
|
+
`create_search_graph_tool`, `create_add_graph_data_tool`
|
|
16
|
+
- `register_all_tools` convenience function for bulk tool registration
|
|
17
|
+
- Sync tool execution via background event loop (AG2 calls tools synchronously)
|
|
18
|
+
- Async manager classes with sync wrappers for non-async usage
|
|
19
|
+
- Comprehensive test suite with >90% coverage
|
|
20
|
+
- Examples for basic, graph, search-only, and full tool usage
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
- AG2 decorator-compatible tools (`@register_for_llm` / `@register_for_execution`)
|
|
24
|
+
- System message enrichment with Zep memory context
|
|
25
|
+
- Thread-based conversation memory storage
|
|
26
|
+
- User and named knowledge graph support
|
|
27
|
+
- Typed parameters with `Annotated` for AG2 tool descriptions
|
|
28
|
+
- Single shared background event loop and reused Zep client for sync bridging
|
|
29
|
+
(Python 3.11–3.13 compatible)
|
|
30
|
+
- Message (4000 char) and graph-data (9900 char) size guards with truncation
|
|
31
|
+
|
|
32
|
+
[0.1.0]: https://github.com/getzep/zep/releases/tag/zep-ag2-v0.1.0
|
zep_ag2-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Makefile for zep-ag2 development
|
|
2
|
+
|
|
3
|
+
.PHONY: help install format lint type-check test test-cov clean build all
|
|
4
|
+
|
|
5
|
+
# Default target
|
|
6
|
+
help:
|
|
7
|
+
@echo "Available commands:"
|
|
8
|
+
@echo " install - Install package and dependencies in development mode"
|
|
9
|
+
@echo " format - Format code with ruff"
|
|
10
|
+
@echo " lint - Run linting checks"
|
|
11
|
+
@echo " type-check - Run type checking with mypy"
|
|
12
|
+
@echo " test - Run tests"
|
|
13
|
+
@echo " test-cov - Run tests with coverage report"
|
|
14
|
+
@echo " all - Run format, lint, type-check, and test"
|
|
15
|
+
@echo " build - Build the package"
|
|
16
|
+
@echo " clean - Clean build artifacts"
|
|
17
|
+
|
|
18
|
+
# Install package in development mode
|
|
19
|
+
install:
|
|
20
|
+
uv sync --extra dev
|
|
21
|
+
# Workaround: macOS sets UF_HIDDEN on all files inside .venv (dot-directory),
|
|
22
|
+
# causing Python 3.11 to skip all .pth files. We mirror src/zep_ag2 directly
|
|
23
|
+
# into site-packages so the package is importable without .pth.
|
|
24
|
+
@SITE=$$(ls -d .venv/lib/python*/site-packages 2>/dev/null | head -1); \
|
|
25
|
+
if [ -n "$$SITE" ]; then \
|
|
26
|
+
rm -rf "$$SITE/zep_ag2"; \
|
|
27
|
+
cp -r src/zep_ag2 "$$SITE/zep_ag2"; \
|
|
28
|
+
echo "Installed zep_ag2 into $$SITE"; \
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# Format code
|
|
32
|
+
format:
|
|
33
|
+
uv run ruff format .
|
|
34
|
+
|
|
35
|
+
# Run linting checks
|
|
36
|
+
lint:
|
|
37
|
+
uv run ruff check .
|
|
38
|
+
|
|
39
|
+
# Fix linting issues automatically
|
|
40
|
+
lint-fix:
|
|
41
|
+
uv run ruff check --fix .
|
|
42
|
+
|
|
43
|
+
# Run type checking
|
|
44
|
+
type-check:
|
|
45
|
+
uv run mypy src/
|
|
46
|
+
|
|
47
|
+
# Run tests
|
|
48
|
+
test:
|
|
49
|
+
uv run pytest tests/ -v
|
|
50
|
+
|
|
51
|
+
# Run tests with coverage
|
|
52
|
+
test-cov:
|
|
53
|
+
uv run pytest tests/ -v --cov=zep_ag2 --cov-report=term-missing --cov-report=xml
|
|
54
|
+
|
|
55
|
+
# Run all checks (the order matters: format first, then lint, then type-check, then test)
|
|
56
|
+
all: format lint type-check test
|
|
57
|
+
|
|
58
|
+
# Build the package
|
|
59
|
+
build:
|
|
60
|
+
uv build
|
|
61
|
+
|
|
62
|
+
# Clean build artifacts
|
|
63
|
+
clean:
|
|
64
|
+
rm -rf dist/
|
|
65
|
+
rm -rf build/
|
|
66
|
+
rm -rf *.egg-info/
|
|
67
|
+
rm -rf .pytest_cache/
|
|
68
|
+
rm -rf .mypy_cache/
|
|
69
|
+
rm -rf .ruff_cache/
|
|
70
|
+
find . -type d -name __pycache__ -exec rm -rf {} +
|
|
71
|
+
find . -type f -name "*.pyc" -delete
|
|
72
|
+
rm -f coverage.xml
|
|
73
|
+
rm -f .coverage
|
|
74
|
+
|
|
75
|
+
# Development workflow - run this before committing
|
|
76
|
+
pre-commit: lint-fix format lint type-check test
|
|
77
|
+
@echo "All checks passed! Ready to commit."
|
|
78
|
+
|
|
79
|
+
# CI workflow - strict checks without auto-fixing
|
|
80
|
+
ci: lint type-check test
|
|
81
|
+
@echo "CI checks passed!"
|
zep_ag2-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zep-ag2
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zep memory integration for AG2 (AutoGen community fork)
|
|
5
|
+
Project-URL: Homepage, https://github.com/getzep/zep
|
|
6
|
+
Project-URL: Documentation, https://help.getzep.com/integrations/ag2
|
|
7
|
+
Project-URL: Repository, https://github.com/getzep/zep
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/getzep/zep/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/getzep/zep/blob/main/integrations/ag2/python/CHANGELOG.md
|
|
10
|
+
Author: faridun-ag2
|
|
11
|
+
Author-email: Zep AI <support@getzep.com>
|
|
12
|
+
License-Expression: Apache-2.0
|
|
13
|
+
Keywords: ag2,agent,autogen,knowledge-graph,llm,memory,zep
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: ag2>=0.9.0
|
|
25
|
+
Requires-Dist: zep-cloud>=3.23.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: openai>=1.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# zep-ag2
|
|
36
|
+
|
|
37
|
+
Zep memory integration for [AG2](https://ag2.ai)
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install zep-ag2
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### System Message Injection
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import asyncio
|
|
51
|
+
import os
|
|
52
|
+
from autogen import AssistantAgent, UserProxyAgent, LLMConfig
|
|
53
|
+
from zep_cloud.client import AsyncZep
|
|
54
|
+
from zep_ag2 import ZepMemoryManager, register_all_tools
|
|
55
|
+
|
|
56
|
+
async def main():
|
|
57
|
+
zep = AsyncZep(api_key=os.environ["ZEP_API_KEY"])
|
|
58
|
+
|
|
59
|
+
llm_config = LLMConfig(
|
|
60
|
+
{"model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
assistant = AssistantAgent(
|
|
64
|
+
name="assistant",
|
|
65
|
+
llm_config=llm_config,
|
|
66
|
+
system_message="You are a helpful assistant with long-term memory.",
|
|
67
|
+
)
|
|
68
|
+
user_proxy = UserProxyAgent(
|
|
69
|
+
name="user",
|
|
70
|
+
human_input_mode="NEVER",
|
|
71
|
+
code_execution_config=False,
|
|
72
|
+
is_termination_msg=lambda msg: "TERMINATE" in (msg.get("content") or ""),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Enrich agent with memory context
|
|
76
|
+
memory_mgr = ZepMemoryManager(zep, user_id="user123", session_id="session456")
|
|
77
|
+
await memory_mgr.enrich_system_message(assistant, query="conversation topic")
|
|
78
|
+
|
|
79
|
+
# Register memory tools (sync — AG2 calls them automatically)
|
|
80
|
+
register_all_tools(assistant, user_proxy, zep, user_id="user123", session_id="session456")
|
|
81
|
+
|
|
82
|
+
result = user_proxy.initiate_chat(
|
|
83
|
+
assistant, message="What do you remember about me?"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
asyncio.run(main())
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Tool-Based Memory Access
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from zep_ag2 import create_search_graph_tool, create_add_graph_data_tool
|
|
93
|
+
|
|
94
|
+
# Create tools bound to a user's knowledge graph
|
|
95
|
+
search_tool = create_search_graph_tool(zep, user_id="user123")
|
|
96
|
+
add_tool = create_add_graph_data_tool(zep, user_id="user123")
|
|
97
|
+
|
|
98
|
+
# Register with AG2's decorator pattern
|
|
99
|
+
assistant.register_for_llm(description="Search knowledge graph")(search_tool)
|
|
100
|
+
user_proxy.register_for_execution()(search_tool)
|
|
101
|
+
|
|
102
|
+
assistant.register_for_llm(description="Add to knowledge graph")(add_tool)
|
|
103
|
+
user_proxy.register_for_execution()(add_tool)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Features
|
|
107
|
+
|
|
108
|
+
- **Tool-based memory access** — Register Zep search/add as AG2 tools via `@register_for_llm`
|
|
109
|
+
- **System message injection** — Automatically enrich agent context with relevant memories
|
|
110
|
+
- **Knowledge graph** — Access Zep's knowledge graph from AG2 agents
|
|
111
|
+
- **Conversation memory** — Store and retrieve thread-based conversation history
|
|
112
|
+
- **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
|
|
113
|
+
|
|
114
|
+
## API Reference
|
|
115
|
+
|
|
116
|
+
### ZepMemoryManager
|
|
117
|
+
|
|
118
|
+
Manages Zep memory for AG2 agents via system message injection.
|
|
119
|
+
|
|
120
|
+
- `ZepMemoryManager(client, user_id, session_id=None)` — Initialize with Zep client
|
|
121
|
+
- `await enrich_system_message(agent, query=None, limit=5)` — Inject memory context
|
|
122
|
+
- `await get_memory_context(query=None, limit=5)` — Get formatted context string
|
|
123
|
+
- `await add_messages(messages)` — Store messages in Zep thread
|
|
124
|
+
- `await get_session_facts()` — Get extracted session facts
|
|
125
|
+
|
|
126
|
+
### ZepGraphMemoryManager
|
|
127
|
+
|
|
128
|
+
Manages Zep knowledge graph for AG2 agents.
|
|
129
|
+
|
|
130
|
+
- `ZepGraphMemoryManager(client, graph_id)` — Initialize with graph ID
|
|
131
|
+
- `await search(query, limit=5, scope="edges")` — Search the graph
|
|
132
|
+
- `await add_data(data, data_type="text")` — Add data to the graph
|
|
133
|
+
- `await enrich_system_message(agent, query=None, limit=5)` — Inject graph context
|
|
134
|
+
|
|
135
|
+
### Tool Factories
|
|
136
|
+
|
|
137
|
+
All tool factories return **synchronous** callables (AG2 executes tools synchronously).
|
|
138
|
+
Internally they bridge to the async Zep SDK on a single shared background event loop,
|
|
139
|
+
reusing the `AsyncZep` client you pass in (no per-call client construction).
|
|
140
|
+
|
|
141
|
+
- `create_search_memory_tool(client, user_id, session_id=None)` — Search conversation memory
|
|
142
|
+
- `create_add_memory_tool(client, user_id, session_id=None)` — Add conversation memory
|
|
143
|
+
- `create_search_graph_tool(client, user_id=None, graph_id=None)` — Search knowledge graph
|
|
144
|
+
- `create_add_graph_data_tool(client, user_id=None, graph_id=None)` — Add graph data
|
|
145
|
+
- `register_all_tools(agent, executor, client, user_id, ...)` — Register all tools at once
|
|
146
|
+
|
|
147
|
+
## Examples
|
|
148
|
+
|
|
149
|
+
- **[Basic Memory](examples/ag2_basic.py)** — System message injection + memory tools
|
|
150
|
+
- **[Graph Memory](examples/ag2_graph.py)** — Knowledge graph with ZepGraphMemoryManager
|
|
151
|
+
- **[Search Tools](examples/ag2_tools_search.py)** — Read-only search tool registration
|
|
152
|
+
- **[Full Tools](examples/ag2_tools_full.py)** — All tools in a GroupChat with multiple agents
|
|
153
|
+
- **[Manual Test](examples/manual_test.py)** — End-to-end integration test with real APIs
|
|
154
|
+
|
|
155
|
+
## Configuration
|
|
156
|
+
|
|
157
|
+
### Environment Variables
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Required
|
|
161
|
+
export ZEP_API_KEY="your-zep-cloud-api-key"
|
|
162
|
+
|
|
163
|
+
# Required for examples that use LLM
|
|
164
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Development
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
make install # Install dev dependencies
|
|
171
|
+
make pre-commit # Format, lint, type-check, test
|
|
172
|
+
make ci # CI validation
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Requirements
|
|
176
|
+
|
|
177
|
+
- Python 3.11+
|
|
178
|
+
- `ag2>=0.9.0`
|
|
179
|
+
- `zep-cloud>=3.23.0`
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
Apache-2.0 — see [LICENSE](../../../LICENSE) for details.
|
|
184
|
+
|
|
185
|
+
## Support
|
|
186
|
+
|
|
187
|
+
- [Zep Documentation](https://help.getzep.com)
|
|
188
|
+
- [AG2 Documentation](https://docs.ag2.ai)
|
|
189
|
+
- [GitHub Issues](https://github.com/getzep/zep/issues)
|
|
190
|
+
|
|
191
|
+
## Contributing
|
|
192
|
+
|
|
193
|
+
Contributions are welcome! Please see our [Contributing Guide](../../../CONTRIBUTING.md) for details.
|
zep_ag2-0.1.0/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# zep-ag2
|
|
2
|
+
|
|
3
|
+
Zep memory integration for [AG2](https://ag2.ai)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install zep-ag2
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### System Message Injection
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import asyncio
|
|
17
|
+
import os
|
|
18
|
+
from autogen import AssistantAgent, UserProxyAgent, LLMConfig
|
|
19
|
+
from zep_cloud.client import AsyncZep
|
|
20
|
+
from zep_ag2 import ZepMemoryManager, register_all_tools
|
|
21
|
+
|
|
22
|
+
async def main():
|
|
23
|
+
zep = AsyncZep(api_key=os.environ["ZEP_API_KEY"])
|
|
24
|
+
|
|
25
|
+
llm_config = LLMConfig(
|
|
26
|
+
{"model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
assistant = AssistantAgent(
|
|
30
|
+
name="assistant",
|
|
31
|
+
llm_config=llm_config,
|
|
32
|
+
system_message="You are a helpful assistant with long-term memory.",
|
|
33
|
+
)
|
|
34
|
+
user_proxy = UserProxyAgent(
|
|
35
|
+
name="user",
|
|
36
|
+
human_input_mode="NEVER",
|
|
37
|
+
code_execution_config=False,
|
|
38
|
+
is_termination_msg=lambda msg: "TERMINATE" in (msg.get("content") or ""),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Enrich agent with memory context
|
|
42
|
+
memory_mgr = ZepMemoryManager(zep, user_id="user123", session_id="session456")
|
|
43
|
+
await memory_mgr.enrich_system_message(assistant, query="conversation topic")
|
|
44
|
+
|
|
45
|
+
# Register memory tools (sync — AG2 calls them automatically)
|
|
46
|
+
register_all_tools(assistant, user_proxy, zep, user_id="user123", session_id="session456")
|
|
47
|
+
|
|
48
|
+
result = user_proxy.initiate_chat(
|
|
49
|
+
assistant, message="What do you remember about me?"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
asyncio.run(main())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Tool-Based Memory Access
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from zep_ag2 import create_search_graph_tool, create_add_graph_data_tool
|
|
59
|
+
|
|
60
|
+
# Create tools bound to a user's knowledge graph
|
|
61
|
+
search_tool = create_search_graph_tool(zep, user_id="user123")
|
|
62
|
+
add_tool = create_add_graph_data_tool(zep, user_id="user123")
|
|
63
|
+
|
|
64
|
+
# Register with AG2's decorator pattern
|
|
65
|
+
assistant.register_for_llm(description="Search knowledge graph")(search_tool)
|
|
66
|
+
user_proxy.register_for_execution()(search_tool)
|
|
67
|
+
|
|
68
|
+
assistant.register_for_llm(description="Add to knowledge graph")(add_tool)
|
|
69
|
+
user_proxy.register_for_execution()(add_tool)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Features
|
|
73
|
+
|
|
74
|
+
- **Tool-based memory access** — Register Zep search/add as AG2 tools via `@register_for_llm`
|
|
75
|
+
- **System message injection** — Automatically enrich agent context with relevant memories
|
|
76
|
+
- **Knowledge graph** — Access Zep's knowledge graph from AG2 agents
|
|
77
|
+
- **Conversation memory** — Store and retrieve thread-based conversation history
|
|
78
|
+
- **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
|
|
79
|
+
|
|
80
|
+
## API Reference
|
|
81
|
+
|
|
82
|
+
### ZepMemoryManager
|
|
83
|
+
|
|
84
|
+
Manages Zep memory for AG2 agents via system message injection.
|
|
85
|
+
|
|
86
|
+
- `ZepMemoryManager(client, user_id, session_id=None)` — Initialize with Zep client
|
|
87
|
+
- `await enrich_system_message(agent, query=None, limit=5)` — Inject memory context
|
|
88
|
+
- `await get_memory_context(query=None, limit=5)` — Get formatted context string
|
|
89
|
+
- `await add_messages(messages)` — Store messages in Zep thread
|
|
90
|
+
- `await get_session_facts()` — Get extracted session facts
|
|
91
|
+
|
|
92
|
+
### ZepGraphMemoryManager
|
|
93
|
+
|
|
94
|
+
Manages Zep knowledge graph for AG2 agents.
|
|
95
|
+
|
|
96
|
+
- `ZepGraphMemoryManager(client, graph_id)` — Initialize with graph ID
|
|
97
|
+
- `await search(query, limit=5, scope="edges")` — Search the graph
|
|
98
|
+
- `await add_data(data, data_type="text")` — Add data to the graph
|
|
99
|
+
- `await enrich_system_message(agent, query=None, limit=5)` — Inject graph context
|
|
100
|
+
|
|
101
|
+
### Tool Factories
|
|
102
|
+
|
|
103
|
+
All tool factories return **synchronous** callables (AG2 executes tools synchronously).
|
|
104
|
+
Internally they bridge to the async Zep SDK on a single shared background event loop,
|
|
105
|
+
reusing the `AsyncZep` client you pass in (no per-call client construction).
|
|
106
|
+
|
|
107
|
+
- `create_search_memory_tool(client, user_id, session_id=None)` — Search conversation memory
|
|
108
|
+
- `create_add_memory_tool(client, user_id, session_id=None)` — Add conversation memory
|
|
109
|
+
- `create_search_graph_tool(client, user_id=None, graph_id=None)` — Search knowledge graph
|
|
110
|
+
- `create_add_graph_data_tool(client, user_id=None, graph_id=None)` — Add graph data
|
|
111
|
+
- `register_all_tools(agent, executor, client, user_id, ...)` — Register all tools at once
|
|
112
|
+
|
|
113
|
+
## Examples
|
|
114
|
+
|
|
115
|
+
- **[Basic Memory](examples/ag2_basic.py)** — System message injection + memory tools
|
|
116
|
+
- **[Graph Memory](examples/ag2_graph.py)** — Knowledge graph with ZepGraphMemoryManager
|
|
117
|
+
- **[Search Tools](examples/ag2_tools_search.py)** — Read-only search tool registration
|
|
118
|
+
- **[Full Tools](examples/ag2_tools_full.py)** — All tools in a GroupChat with multiple agents
|
|
119
|
+
- **[Manual Test](examples/manual_test.py)** — End-to-end integration test with real APIs
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
### Environment Variables
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Required
|
|
127
|
+
export ZEP_API_KEY="your-zep-cloud-api-key"
|
|
128
|
+
|
|
129
|
+
# Required for examples that use LLM
|
|
130
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
make install # Install dev dependencies
|
|
137
|
+
make pre-commit # Format, lint, type-check, test
|
|
138
|
+
make ci # CI validation
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Requirements
|
|
142
|
+
|
|
143
|
+
- Python 3.11+
|
|
144
|
+
- `ag2>=0.9.0`
|
|
145
|
+
- `zep-cloud>=3.23.0`
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
Apache-2.0 — see [LICENSE](../../../LICENSE) for details.
|
|
150
|
+
|
|
151
|
+
## Support
|
|
152
|
+
|
|
153
|
+
- [Zep Documentation](https://help.getzep.com)
|
|
154
|
+
- [AG2 Documentation](https://docs.ag2.ai)
|
|
155
|
+
- [GitHub Issues](https://github.com/getzep/zep/issues)
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! Please see our [Contributing Guide](../../../CONTRIBUTING.md) for details.
|
zep_ag2-0.1.0/SETUP.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Setup
|
|
2
|
+
|
|
3
|
+
This guide gets you from zero to a running AG2 agent with Zep memory.
|
|
4
|
+
|
|
5
|
+
## 1. Sign up for Zep and get an API key
|
|
6
|
+
|
|
7
|
+
1. Create a free account at [https://www.getzep.com](https://www.getzep.com).
|
|
8
|
+
2. Open the Zep dashboard at [https://app.getzep.com](https://app.getzep.com).
|
|
9
|
+
3. Create (or select) a project and copy its **API key**.
|
|
10
|
+
|
|
11
|
+
## 2. Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install zep-ag2
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This installs the integration along with its runtime dependencies (`ag2` and
|
|
18
|
+
`zep-cloud`).
|
|
19
|
+
|
|
20
|
+
For local development of this package:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
make install # uv sync --extra dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 3. Configure environment variables
|
|
27
|
+
|
|
28
|
+
The examples read configuration from environment variables. Copy the template
|
|
29
|
+
and fill in your keys:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cp .env.example .env
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Required
|
|
37
|
+
export ZEP_API_KEY="your-zep-cloud-api-key"
|
|
38
|
+
|
|
39
|
+
# Required for examples that call an LLM
|
|
40
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 4. Run an example
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python examples/ag2_basic.py
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Other runnable examples live in [`examples/`](examples):
|
|
50
|
+
|
|
51
|
+
- `ag2_basic.py` — system message injection + memory tools
|
|
52
|
+
- `ag2_graph.py` — knowledge graph with `ZepGraphMemoryManager`
|
|
53
|
+
- `ag2_tools_search.py` — read-only search tool registration
|
|
54
|
+
- `ag2_tools_full.py` — all tools across a multi-agent GroupChat
|
|
55
|
+
- `manual_test.py` — end-to-end integration test against real APIs
|
|
56
|
+
|
|
57
|
+
## Next steps
|
|
58
|
+
|
|
59
|
+
- Read the [README](README.md) for the API reference.
|
|
60
|
+
- See the [Zep documentation](https://help.getzep.com) for memory concepts,
|
|
61
|
+
knowledge graphs, and best practices.
|