feat(integrations): Add zep-ag2 — Zep memory integration for AG2#511
Merged
Conversation
Contributor
Author
|
Hi @danielchalef! We've put together a new It follows the same structure and patterns as the existing All quality gates pass (ruff, mypy, 66 tests at 96% coverage), and we've verified it end-to-end with real Zep and OpenAI APIs. We'd love to get your feedback on this when you have a chance. Thank you! |
Add zep-ag2 package providing Zep memory integration for AG2 (community AutoGen fork, 400K+ monthly PyPI downloads). Key design: AG2 has no formal Memory base class like MS AutoGen v4, so the integration uses composition — tool factories for @register_for_llm/@register_for_execution and ZepMemoryManager for system message injection. Tools are synchronous (AG2 executes tools synchronously) with a background event loop for async Zep SDK calls. Each tool coroutine creates its own AsyncZep instance to avoid event-loop binding issues. - ZepMemoryManager: system message injection + conversation memory - ZepGraphMemoryManager: knowledge graph operations - 4 tool factories: search_memory, add_memory, search_graph, add_graph_data - register_all_tools() convenience function - 66 tests, 96% coverage - 4 examples + manual integration test
…ations/ag2/python Relocates the AG2 integration to the platform-first path and applies code-review fixes: - Fix Python 3.13 sync-bridge crash: replace asyncio.get_event_loop() in the manager sync wrappers with a shared _run_sync() that submits coroutines to a single daemon background event loop via run_coroutine_threadsafe. - Eliminate the per-call AsyncZep leak and private _client_wrapper.api_key access: tools now reuse the caller-supplied AsyncZep, driven on the shared background loop (verified httpx loop affinity allows this). - Never log message content / raw exceptions: log type(e).__name__ only and return generic, non-leaking error strings; keep graceful degradation. - Make the dependency guard truthful: verify `import autogen` (AG2) at import. - Add message (4000) and graph-data (9900) size guards with truncate-and-warn (lengths only) across tools and ZepMemoryManager.add_messages. - register_all_tools: register each uniquely-named tool once for LLM and once for execution (no duplicate-execution override warnings). - Validate/normalize message roles to the Zep RoleType set (default assistant). - Guard graph node summary None -> "No summary". - Drop the redundant thread.get(lastn=10) read in get_memory_context. - Align scope handling between create_search_memory_tool and create_search_graph_tool. - Thread-safe lazy background-loop init with documentation and an optional shutdown_background_loop() helper. - Docs/metadata: add SETUP.md; fix README (Python 3.11+, zep-cloud>=3.23.0, reworked background-loop copy); single coherent CHANGELOG 0.1.0 entry; pyproject classifiers, authors, keywords. - Tests: exercise the real client-reuse path (no per-call construction, no _client_wrapper access), the 3.11-3.13 sync bridge, size truncation, role validation, and override-free registration. Validation (Python 3.11/3.12/3.13): ruff check, ruff format --check, mypy src/, and pytest tests/ (83 passed) all green; the 4 previously-failing sync-wrapper tests now pass on 3.13. Co-Authored-By: faridun-ag2 <faridun-ag2@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
513741f to
d33a75e
Compare
Member
|
Thank you for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zep-ag2package: Zep memory integration for AG2 (community AutoGen fork, 500K+ monthly PyPI downloads)integrations/python/zep_ag2/following the established integration pattern@register_for_llm/@register_for_executionpatternZepMemoryManagerfor system message injectionWhy AG2?
AG2 is the most active community fork of AutoGen with 500K+ monthly downloads. It uses a different package (
ag2on PyPI) and API from the existing MS AutoGen integration. Existingzep-autogentargets MS AutoGen v4 (autogen-agentchat/autogen-core) — AG2 users need their own package.Key Design Decisions
run_coroutine_threadsafeto call the async Zep SDKAsyncZepinstance inside the background loop to avoid event-loop binding issuesMemorybase class, so we useZepMemoryManagerfor system message injection and tool factories for agent capabilitiesPackage Structure
Test Plan
make format— cleanmake lint— all checks passedmake type-check— no mypy issuesmake test— 66 passed, 96% coverageautogen_agentchat/autogen_core/autogen_ext) in zep_ag2zep_autogen,zep_crewai,zep_livekitpackages unmodified