-
Notifications
You must be signed in to change notification settings - Fork 655
feat: Add ZepGraphMemory to autogen example #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
paul-paliychuk
merged 5 commits into
main
from
add-graph-support-to-autogen-integration
Aug 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a82286
feat: Add ZepGraphMemory to autogen example
paul-paliychuk dcf615a
chore: Update readme, fix linter and tests
paul-paliychuk 838ec0a
chore: Add claude md and tools to autogen project
paul-paliychuk f263a80
polish
paul-paliychuk b7f5e89
chore: Bump zep SDK version for context string updates
paul-paliychuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
155 changes: 155 additions & 0 deletions
155
integrations/python/zep_autogen/examples/autogen_graph.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import asyncio | ||
| import os | ||
| import uuid | ||
|
|
||
| from autogen_agentchat.agents import AssistantAgent | ||
| from autogen_core.memory import MemoryContent, MemoryMimeType | ||
| from autogen_ext.models.openai import OpenAIChatCompletionClient | ||
| from pydantic import Field | ||
| from zep_cloud import SearchFilters | ||
| from zep_cloud.client import AsyncZep | ||
| from zep_cloud.external_clients.ontology import EntityModel, EntityText | ||
|
|
||
| from zep_autogen.graph_memory import ZepGraphMemory | ||
|
|
||
| class ProgrammingLanguage(EntityModel): | ||
| """ | ||
| A programming language entity. | ||
| """ | ||
| paradigm: EntityText = Field( | ||
| description="programming paradigm (e.g., object-oriented, functional)", | ||
| default=None | ||
| ) | ||
| use_case: EntityText = Field( | ||
| description="primary use cases for this language", | ||
| default=None | ||
| ) | ||
|
|
||
| class Framework(EntityModel): | ||
| """ | ||
| A software framework or library. | ||
| """ | ||
| language: EntityText = Field( | ||
| description="the programming language this framework is built for", | ||
| default=None | ||
| ) | ||
| purpose: EntityText = Field( | ||
| description="primary purpose of this framework", | ||
| default=None | ||
| ) | ||
|
|
||
| class Concept(EntityModel): | ||
| """ | ||
| A programming concept or technique. | ||
| """ | ||
| category: EntityText = Field( | ||
| description="category of concept (e.g., design pattern, algorithm)", | ||
| default=None | ||
| ) | ||
| difficulty: EntityText = Field( | ||
| description="difficulty level (beginner, intermediate, advanced)", | ||
| default=None | ||
| ) | ||
|
|
||
| async def main(): | ||
| # Initialize AsyncZep client | ||
| zep_client = AsyncZep(api_key=os.environ.get("ZEP_API_KEY")) | ||
|
|
||
| await zep_client.graph.set_ontology( | ||
| entities={ | ||
| "ProgrammingLanguage": ProgrammingLanguage, | ||
| "Framework": Framework, | ||
| "Concept": Concept, | ||
| }, | ||
| ) | ||
|
|
||
| graph_id = f"graph_{uuid.uuid4().hex[:16]}" | ||
|
|
||
| try: | ||
| # Create graph for storing knowledge | ||
| await zep_client.graph.create(graph_id=graph_id, name="Knowledge Graph") | ||
| print(f"Created graph: {graph_id}") | ||
| except Exception as e: | ||
| print(f"Graph creation failed: {e}") | ||
|
|
||
| # Initialize Zep graph memory bound to the assistant | ||
| memory = ZepGraphMemory( | ||
| client=zep_client, | ||
| graph_id=graph_id, | ||
| search_filters=SearchFilters( | ||
| node_labels=["ProgrammingLanguage", "Framework", "Concept"], | ||
| ), | ||
| ) | ||
|
|
||
| # Create assistant agent with Zep graph memory | ||
| agent = AssistantAgent( | ||
| name="GraphMemoryAssistant", | ||
| model_client=OpenAIChatCompletionClient(model="gpt-4.1-mini"), | ||
| memory=[memory], | ||
| ) | ||
|
|
||
| # Helper function to store data in graph memory | ||
| async def add_data(data: str, data_type: str = "data"): | ||
| """Store data in graph memory""" | ||
| metadata = {"type": data_type} | ||
|
|
||
| await memory.add( | ||
| MemoryContent(content=data, mime_type=MemoryMimeType.TEXT, metadata=metadata) | ||
| ) | ||
|
|
||
| # Example conversation with graph memory storage | ||
| try: | ||
| print("\n=== Starting conversation with graph memory ===") | ||
|
|
||
| # Store some facts and knowledge | ||
| await add_data("Python is a popular programming language for AI development") | ||
| await add_data("Machine learning models require large datasets for training") | ||
| await add_data("AutoGen is a framework for building multi-agent conversations") | ||
| await add_data("Graph databases are useful for storing connected information") | ||
| print("Stored knowledge in graph memory") | ||
| await asyncio.sleep(50) # Wait for graph processing | ||
|
paul-paliychuk marked this conversation as resolved.
|
||
| # Store some episode/message data | ||
| user_msg1 = "Tell me about Python and machine learning." | ||
| print(f"\nUser: {user_msg1}") | ||
| await memory.add( | ||
| MemoryContent(content=user_msg1, mime_type=MemoryMimeType.TEXT, metadata={"type": "message"}) | ||
| ) | ||
|
|
||
| response1 = await agent.run(task=user_msg1) | ||
| agent_msg1 = response1.messages[-1].content | ||
| print(f"Agent: {agent_msg1}") | ||
|
|
||
| await memory.add( | ||
| MemoryContent(content=agent_msg1, mime_type=MemoryMimeType.TEXT, metadata={"type": "message"}) | ||
| ) | ||
|
|
||
| # Second interaction - agent should use graph context | ||
| user_msg2 = "What can you tell me about building AI agents?" | ||
| print(f"\nUser: {user_msg2}") | ||
| await memory.add( | ||
| MemoryContent(content=user_msg2, mime_type=MemoryMimeType.TEXT, metadata={"type": "message"}) | ||
| ) | ||
|
|
||
| response2 = await agent.run(task=user_msg2) | ||
| agent_msg2 = response2.messages[-1].content | ||
| print(f"Agent: {agent_msg2}") | ||
|
|
||
| await memory.add( | ||
| MemoryContent(content=agent_msg2, mime_type=MemoryMimeType.TEXT, metadata={"type": "message"}) | ||
| ) | ||
|
|
||
| # Test querying graph memory directly | ||
| print(f"\n=== Querying graph memory directly ===") | ||
| query_result = await memory.query("What technologies are useful for AI?", limit=5) | ||
| print(f"Query results ({len(query_result.results)} items):") | ||
| for i, result in enumerate(query_result.results[:3], 1): | ||
| print(f"{i}. {result.content[:100]}...") | ||
|
|
||
| print("\n=== Graph memory demonstration complete ===") | ||
|
|
||
| except Exception as e: | ||
| print(f"Error during conversation: {e}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.