Autogen Memory Example
Autogen is a library created by Microsoft for building multi-agent applications. This example demonstrates using Zep for Autogen long-term memory.
Autogen is a library created by Microsoft for building multi-agent applications. This example demonstrates using Zep for Autogen long-term memory.
Autogen 4 has been released. This example is not compatible with Autogen 4. We’ll be updating it soon!
NOTE This example does not include all code required to run the Autogen Agents.
A complete Notebook example of using Zep for Autogen long-term memory may be found in the Zep Python SDK Repository.
This example walks through how to build an Autogen Agent with long-term memory. Zep builds a knowledge graph from user interactions with the agent, enabling the agent to recall relevant facts from previous conversations or user interactions.
In this example we will:
ConversableAgent by adding long-term memoryconfig_listYou can sign up for a Zep account here: https://www.getzep.com/
The ZepConversableAgent is a custom implementation of the Autogen ConversableAgent that integrates with Zep for long-term memory management. This class extends the functionality of the base ConversableAgent by adding Zep-specific features for persisting and retrieving facts from long-term memory.
A Zep User represents an individual interacting with your application. Each User can have multiple Sessions associated with them, allowing you to track and manage interactions over time. The unique identifier for each user is their UserID, which can be any string value (e.g., username, email address, or UUID).
A Zep Session represents a conversation and can be associated with Users in a one-to-many relationship. Chat messages are added to Sessions, with each session having many messages.
Fact Rating is a feature in Zep that allows you to rate the importance or relevance of facts extracted from conversations. This helps in prioritizing and filtering information when retrieving memory artifacts. Here, we rate facts based on poignancy. We provide a definition of poignancy and several examples of highly poignant and low-poignancy facts. When retrieving memory, you can use the min_rating parameter to filter facts based on their importance.
Fact Rating helps ensure the most relevant information, especially in long or complex conversations, is used to ground the agent.
We’ll load a prior conversation into long-term memory. We’ll use facts derived from this conversation when Cathy restarts the conversation with CareBot, ensuring Carebot has context.
We query all session facts for this user session. Only facts that meet the MIN_FACT_RATING threshold are returned.
ZepConversableAgentWe pass in the current session_id into the CareBot agent which allows it to retrieve relevant facts related to the conversation with Cathy.
Cathy is a stand-in for a human. When building a production application, you’d replace Cathy with a human-in-the-loop pattern.
Note that we’re instructing Cathy to start the conversation with CareBit by asking about her previous session. This is an opportunity for us to test whether fact retrieval from Zep’s long-term memory is working.
We use Autogen’s a_initiate_chat method to get the two agents conversing. CareBot is the primary agent.
NOTE how Carebot is able to recall the past conversation about Cathy’s mother in detail, having had relevant facts from Zep added to its system prompt.
Let’s see how the facts have evolved as the conversation has progressed.
In addition to the memory.get method which uses the current conversation to retrieve relevant_facts, we can also search Zep with our own keywords. Here, we retrieve facts using a query.
The zep.graph.search API may be used as an Agent tool, enabling an agent to search across user memory for facts.