mirror of https://github.com/microsoft/autogen.git
Add Zep ecosystem doc and notebook (#3681)
* Add Zep ecosystem doc and notebook * fix linting and formatting issues * Fix url * Update agent-memory-with-zep.md * add notebook metadata * newline --------- Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
This commit is contained in:
parent
1960eaba1a
commit
76a4bd05d9
|
@ -0,0 +1,532 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Building an Agent with Long-term Memory using Autogen and Zep\n",
|
||||
"\n",
|
||||
"This notebook 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.\n",
|
||||
"\n",
|
||||
"In this notebook we will:\n",
|
||||
"- Create an Autogen Agent class that extends `ConversableAgent` by adding long-term memory\n",
|
||||
"- Create a Mental Health Assistant Agent, CareBot, that acts as a counselor and coach.\n",
|
||||
"- Create a user Agent, Cathy, who stands in for our expected user.\n",
|
||||
"- Demonstrate preloading chat history into Zep.\n",
|
||||
"- Demonstrate the agents in conversation, with CareBot recalling facts from previous conversations with Cathy.\n",
|
||||
"- Inspect Facts within Zep, and demonstrate how to use Zep's Fact Ratings to improve the quality of returned facts.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Requirements\n",
|
||||
"\n",
|
||||
"````{=mdx}\n",
|
||||
":::info Requirements\n",
|
||||
"Some extra dependencies are needed for this notebook, which can be installed via pip:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install autogen~=0.3 zep-cloud python-dotenv\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"For more information, please refer to the [installation guide](/docs/installation/).\n",
|
||||
":::\n",
|
||||
"````"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"flaml.automl is not available. Please install flaml[automl] to enable AutoML functionalities.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import uuid\n",
|
||||
"from typing import Dict, Union\n",
|
||||
"\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"\n",
|
||||
"from autogen import Agent, ConversableAgent\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"\n",
|
||||
"config_list = [\n",
|
||||
" {\n",
|
||||
" \"model\": \"gpt-4o-mini\",\n",
|
||||
" \"api_key\": os.environ.get(\"OPENAI_API_KEY\"),\n",
|
||||
" \"max_tokens\": 1024,\n",
|
||||
" }\n",
|
||||
"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## initiualize the Zep Client\n",
|
||||
"\n",
|
||||
"You can sign up for a Zep account here: https://www.getzep.com/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from zep_cloud import FactRatingExamples, FactRatingInstruction, Message\n",
|
||||
"from zep_cloud.client import AsyncZep\n",
|
||||
"\n",
|
||||
"MIN_FACT_RATING = 0.3\n",
|
||||
"\n",
|
||||
"# Configure Zep\n",
|
||||
"zep = AsyncZep(api_key=os.environ.get(\"ZEP_API_KEY\"))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def convert_to_zep_messages(chat_history: list[dict[str, str | None]]) -> list[Message]:\n",
|
||||
" \"\"\"\n",
|
||||
" Convert chat history to Zep messages.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" chat_history (list): List of dictionaries containing chat messages.\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" list: List of Zep Message objects.\n",
|
||||
" \"\"\"\n",
|
||||
" return [\n",
|
||||
" Message(\n",
|
||||
" role_type=msg[\"role\"],\n",
|
||||
" role=msg.get(\"name\", None),\n",
|
||||
" content=msg[\"content\"],\n",
|
||||
" )\n",
|
||||
" for msg in chat_history\n",
|
||||
" ]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ZepConversableAgent\n",
|
||||
"\n",
|
||||
"The `ZepConversableAgent` is a custom implementation of the `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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class ZepConversableAgent(ConversableAgent):\n",
|
||||
" \"\"\"\n",
|
||||
" A custom ConversableAgent that integrates with Zep for long-term memory.\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" def __init__(\n",
|
||||
" self,\n",
|
||||
" name: str,\n",
|
||||
" system_message: str,\n",
|
||||
" llm_config: dict,\n",
|
||||
" function_map: dict,\n",
|
||||
" human_input_mode: str,\n",
|
||||
" zep_session_id: str,\n",
|
||||
" ):\n",
|
||||
" super().__init__(\n",
|
||||
" name=name,\n",
|
||||
" system_message=system_message,\n",
|
||||
" llm_config=llm_config,\n",
|
||||
" function_map=function_map,\n",
|
||||
" human_input_mode=human_input_mode,\n",
|
||||
" )\n",
|
||||
" self.zep_session_id = zep_session_id\n",
|
||||
" # store the original system message as we will update it with relevant facts from Zep\n",
|
||||
" self.original_system_message = system_message\n",
|
||||
" self.register_hook(\"a_process_last_received_message\", self.persist_user_messages)\n",
|
||||
" self.register_hook(\"a_process_message_before_send\", self.persist_assistant_messages)\n",
|
||||
"\n",
|
||||
" async def persist_assistant_messages(\n",
|
||||
" self, sender: Agent, message: Union[Dict, str], recipient: Agent, silent: bool\n",
|
||||
" ):\n",
|
||||
" \"\"\"Agent sends a message to the user. Add the message to Zep.\"\"\"\n",
|
||||
"\n",
|
||||
" # Assume message is a string\n",
|
||||
" zep_messages = convert_to_zep_messages([{\"role\": \"assistant\", \"name\": self.name, \"content\": message}])\n",
|
||||
" await zep.memory.add(session_id=self.zep_session_id, messages=zep_messages)\n",
|
||||
"\n",
|
||||
" return message\n",
|
||||
"\n",
|
||||
" async def persist_user_messages(self, messages: list[dict[str, str]] | str):\n",
|
||||
" \"\"\"\n",
|
||||
" User sends a message to the agent. Add the message to Zep and\n",
|
||||
" update the system message with relevant facts from Zep.\n",
|
||||
" \"\"\"\n",
|
||||
" # Assume messages is a string\n",
|
||||
" zep_messages = convert_to_zep_messages([{\"role\": \"user\", \"content\": messages}])\n",
|
||||
" await zep.memory.add(session_id=self.zep_session_id, messages=zep_messages)\n",
|
||||
"\n",
|
||||
" memory = await zep.memory.get(self.zep_session_id, min_rating=MIN_FACT_RATING)\n",
|
||||
"\n",
|
||||
" # Update the system message with the relevant facts retrieved from Zep\n",
|
||||
" self.update_system_message(\n",
|
||||
" self.original_system_message\n",
|
||||
" + f\"\\n\\nRelevant facts about the user and their prior conversation:\\n{memory.relevant_facts}\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" return messages"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Zep User and Session Management\n",
|
||||
"\n",
|
||||
"### Zep User\n",
|
||||
"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).\n",
|
||||
"\n",
|
||||
"### Zep Session\n",
|
||||
"A 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.\n",
|
||||
"\n",
|
||||
"### Fact Rating\n",
|
||||
" \n",
|
||||
"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.\n",
|
||||
" \n",
|
||||
"Fact Rating helps ensure the most relevant information, especially in long or complex conversations, is used to ground the agent.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Session(classifications=None, created_at='2024-10-07T21:12:13.952672Z', deleted_at=None, ended_at=None, fact_rating_instruction=FactRatingInstruction(examples=FactRatingExamples(high=\"The user received news of a family member's serious illness.\", low='The user bought a new brand of toothpaste.', medium='The user completed a challenging marathon.'), instruction='Rate the facts by poignancy. Highly poignant \\nfacts have a significant emotional impact or relevance to the user. \\nLow poignant facts are minimally relevant or of little emotional \\nsignificance.'), fact_version_uuid=None, facts=None, id=774, metadata=None, project_uuid='00000000-0000-0000-0000-000000000000', session_id='f3854ad0-5bd4-4814-a814-ec0880817953', updated_at='2024-10-07T21:12:13.952672Z', user_id='Cathy1023', uuid_='31ab3314-5ac8-4361-ad11-848fb7befedf')"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"bot_name = \"CareBot\"\n",
|
||||
"user_name = \"Cathy\"\n",
|
||||
"\n",
|
||||
"user_id = user_name + str(uuid.uuid4())[:4]\n",
|
||||
"session_id = str(uuid.uuid4())\n",
|
||||
"\n",
|
||||
"await zep.user.add(user_id=user_id)\n",
|
||||
"\n",
|
||||
"fact_rating_instruction = \"\"\"Rate the facts by poignancy. Highly poignant\n",
|
||||
" facts have a significant emotional impact or relevance to the user.\n",
|
||||
" Low poignant facts are minimally relevant or of little emotional significance.\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"fact_rating_examples = FactRatingExamples(\n",
|
||||
" high=\"The user received news of a family member's serious illness.\",\n",
|
||||
" medium=\"The user completed a challenging marathon.\",\n",
|
||||
" low=\"The user bought a new brand of toothpaste.\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"await zep.memory.add_session(\n",
|
||||
" user_id=user_id,\n",
|
||||
" session_id=session_id,\n",
|
||||
" fact_rating_instruction=FactRatingInstruction(\n",
|
||||
" instruction=fact_rating_instruction,\n",
|
||||
" examples=fact_rating_examples,\n",
|
||||
" ),\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Preload a prior conversation into Zep\n",
|
||||
"\n",
|
||||
"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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"SuccessResponse(message='OK')"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"chat_history = [\n",
|
||||
" {\n",
|
||||
" \"role\": \"assistant\",\n",
|
||||
" \"name\": \"carebot\",\n",
|
||||
" \"content\": \"Hi Cathy, how are you doing today?\",\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"role\": \"user\",\n",
|
||||
" \"name\": \"Cathy\",\n",
|
||||
" \"content\": \"To be honest, I've been feeling a bit down and demotivated lately. It's been tough.\",\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"role\": \"assistant\",\n",
|
||||
" \"name\": \"CareBot\",\n",
|
||||
" \"content\": \"I'm sorry to hear that you're feeling down and demotivated, Cathy. It's understandable given the challenges you're facing. Can you tell me more about what's been going on?\",\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"role\": \"user\",\n",
|
||||
" \"name\": \"Cathy\",\n",
|
||||
" \"content\": \"Well, I'm really struggling to process the passing of my mother.\",\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"role\": \"assistant\",\n",
|
||||
" \"name\": \"CareBot\",\n",
|
||||
" \"content\": \"I'm deeply sorry for your loss, Cathy. Losing a parent is incredibly difficult. It's normal to struggle with grief, and there's no 'right' way to process it. Would you like to talk about your mother or how you're coping?\",\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"role\": \"user\",\n",
|
||||
" \"name\": \"Cathy\",\n",
|
||||
" \"content\": \"Yes, I'd like to talk about my mother. She was a kind and loving person.\",\n",
|
||||
" },\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Convert chat history to Zep messages\n",
|
||||
"zep_messages = convert_to_zep_messages(chat_history)\n",
|
||||
"\n",
|
||||
"await zep.memory.add(session_id=session_id, messages=zep_messages)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Review all facts in Zep\n",
|
||||
"\n",
|
||||
"We query all session facts for this user session. Only facts that meet the `MIN_FACT_RATING` threshold are returned."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"created_at='2024-10-07T21:12:15.96584Z' fact='Cathy describes her mother as a kind and loving person.' rating=0.5 uuid_='6a086a73-d4b8-4c1b-9b2f-08d5d326d813'\n",
|
||||
"created_at='2024-10-07T21:12:15.96584Z' fact='Cathy has been feeling down and demotivated lately.' rating=0.5 uuid_='e19d959c-2a01-4cc7-9d49-108719f1a749'\n",
|
||||
"created_at='2024-10-07T21:12:15.96584Z' fact='Cathy is struggling to process the passing of her mother.' rating=0.75 uuid_='d6c12a5d-d2a0-486e-b25d-3d4bdc5ff466'\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"response = await zep.memory.get_session_facts(session_id=session_id, min_rating=MIN_FACT_RATING)\n",
|
||||
"\n",
|
||||
"for r in response.facts:\n",
|
||||
" print(r)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Create the Autogen agent, CareBot, an instance of `ZepConversableAgent`\n",
|
||||
"\n",
|
||||
"We pass in the current `session_id` into the CareBot agent which allows it to retrieve relevant facts related to the conversation with Cathy."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"carebot_system_message = \"\"\"\n",
|
||||
"You are a compassionate mental health bot and caregiver. Review information about the user and their prior conversation below and respond accordingly.\n",
|
||||
"Keep responses empathetic and supportive. And remember, always prioritize the user's well-being and mental health. Keep your responses very concise and to the point.\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"agent = ZepConversableAgent(\n",
|
||||
" bot_name,\n",
|
||||
" system_message=carebot_system_message,\n",
|
||||
" llm_config={\"config_list\": config_list},\n",
|
||||
" function_map=None, # No registered functions, by default it is None.\n",
|
||||
" human_input_mode=\"NEVER\", # Never ask for human input.\n",
|
||||
" zep_session_id=session_id,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Create the Autogen agent, Cathy\n",
|
||||
"\n",
|
||||
"Cathy is a stand-in for a human. When building a production application, you'd replace Cathy with a human-in-the-loop pattern.\n",
|
||||
"\n",
|
||||
"**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. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cathy = ConversableAgent(\n",
|
||||
" user_name,\n",
|
||||
" system_message=\"You are returning to your conversation with CareBot, a mental health bot. Ask the bot about your previous session.\",\n",
|
||||
" llm_config={\"config_list\": config_list},\n",
|
||||
" human_input_mode=\"NEVER\", # Never ask for human input.\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Start the conversation\n",
|
||||
"\n",
|
||||
"We use Autogen's `a_initiate_chat` method to get the two agents conversing. CareBot is the primary agent.\n",
|
||||
"\n",
|
||||
"**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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"result = await agent.a_initiate_chat(\n",
|
||||
" cathy,\n",
|
||||
" message=\"Hi Cathy, nice to see you again. How are you doing today?\",\n",
|
||||
" max_turns=3,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Review current facts in Zep\n",
|
||||
"\n",
|
||||
"Let's see how the facts have evolved as the conversation has progressed."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"created_at='2024-10-07T20:04:28.397184Z' fact=\"Cathy wants to reflect on a previous conversation about her mother and explore the topic of her mother's passing further.\" rating=0.75 uuid_='56488eeb-d8ac-4b2f-8acc-75f71b56ad76'\n",
|
||||
"created_at='2024-10-07T20:04:28.397184Z' fact='Cathy is struggling to process the passing of her mother and has been feeling down and demotivated lately.' rating=0.75 uuid_='0fea3f05-ed1a-4e39-a092-c91f8af9e501'\n",
|
||||
"created_at='2024-10-07T20:04:28.397184Z' fact='Cathy describes her mother as a kind and loving person.' rating=0.5 uuid_='131de203-2984-4cba-9aef-e500611f06d9'\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"response = await zep.memory.get_session_facts(session_id, min_rating=MIN_FACT_RATING)\n",
|
||||
"\n",
|
||||
"for r in response.facts:\n",
|
||||
" print(r)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Search over Facts in Zep's long-term memory\n",
|
||||
"\n",
|
||||
"In addition to the `memory.get` method which uses the current conversation to retrieve facts, we can also search Zep with our own keywords. Here, we retrieve facts using a query. Again, we use fact ratings to limit the returned facts to only those with a high poignancy rating.\n",
|
||||
"\n",
|
||||
"The `memory.search_sessions` API may be used as an Agent tool, enabling an agent to search across user memory for relevant facts."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"created_at='2024-10-07T20:04:28.397184Z' fact='Cathy describes her mother as a kind and loving person.' rating=0.5 uuid_='131de203-2984-4cba-9aef-e500611f06d9'\n",
|
||||
"created_at='2024-10-07T20:04:28.397184Z' fact='Cathy is struggling to process the passing of her mother and has been feeling down and demotivated lately.' rating=0.75 uuid_='0fea3f05-ed1a-4e39-a092-c91f8af9e501'\n",
|
||||
"created_at='2024-10-07T20:04:28.397184Z' fact=\"Cathy wants to reflect on a previous conversation about her mother and explore the topic of her mother's passing further.\" rating=0.75 uuid_='56488eeb-d8ac-4b2f-8acc-75f71b56ad76'\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"response = await zep.memory.search_sessions(\n",
|
||||
" text=\"What do you know about Cathy's family?\",\n",
|
||||
" user_id=user_id,\n",
|
||||
" search_scope=\"facts\",\n",
|
||||
" min_fact_rating=MIN_FACT_RATING,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"for r in response.results:\n",
|
||||
" print(r.fact)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"front_matter": {
|
||||
"tags": [
|
||||
"memory"
|
||||
],
|
||||
"description": "Agent Memory with Zep."
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
# Agent Memory with Zep
|
||||
|
||||
<img src="https://raw.githubusercontent.com/getzep/zep/refs/heads/main/assets/zep-logo-icon-gradient-rgb.svg?raw=true" style="width: 20%;" alt="Zep logo"/>
|
||||
|
||||
[Zep](https://www.getzep.com/?utm_source=autogen) is a long-term memory service for agentic applications used by both startups and enterprises. With Zep, you can build personalized, accurate, and production-ready agent applications.
|
||||
|
||||
Zep's memory continuously learns facts from interactions with users and your changing business data. With [just two API calls](https://help.getzep.com/memory?utm_source=autogen), you can persist chat history to Zep and recall facts relevant to the state of your agent.
|
||||
|
||||
Zep is powered by a temporal Knowledge Graph that allows reasoning with facts as they change. A combination of semantic and graph search enables accurate and low-latency fact retrieval.
|
||||
|
||||
Sign up for [Zep Cloud](https://www.getzep.com/?utm_source=autogen) or visit the [Zep Community Edition Repo](https://github.com/getzep/zep).
|
||||
|
||||
| Feature | Description |
|
||||
| ---------------------------------------------- | ------------------------------------------------------------------------------------- |
|
||||
| 💬 **Capture Detailed Conversational Context** | Zep's Knowledge Graph-based memory captures episodic, semantic, and temporal contexts |
|
||||
| 🗄️ **Business Data is Context, too** | Zep is able to extract facts from JSON and unstructured text as well |
|
||||
| ⚙️ **Tailor For Your Business** | Fact Ratings and other tools allow you to fine-tune retrieval for your use case |
|
||||
| ⚡️ **Instant Memory Retrieval** | Retrieve relevant facts in under 100ms |
|
||||
| 🔐 **Compliance & Security** | User Privacy Management, SOC 2 Type II certification, and other controls |
|
||||
| 🖼️ **Framework Agnostic & Future-Proof** | Use with AutoGen or any other framework, current or future |
|
||||
|
||||
<details>
|
||||
<summary><b><u>Zep Community Edition Walkthrough</u></b></summary>
|
||||
<a href="https://vimeo.com/1013045013">
|
||||
<img src="img/ecosystem-zep-ce-walkthrough.png" alt="Zep Fact Ratings" />
|
||||
</a>
|
||||
</details>
|
||||
|
||||
<details open>
|
||||
<summary><b><u>User Chat Session and Facts</u></b></summary>
|
||||
<a href="https://help.getzep.com/chat-history-memory/facts?utm_source=autogen">
|
||||
<img src="img/ecosystem-zep-session.gif" style="width: 100%;" alt="Chat Session and Facts"/>
|
||||
</a>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b><u>Implementing Fact Ratings</u></b></summary>
|
||||
<a href="https://vimeo.com/989192145">
|
||||
<img src="img/ecosystem-zep-fact-ratings.png" alt="Zep Fact Ratings" />
|
||||
</a>
|
||||
</details>
|
||||
|
||||
## How Zep works
|
||||
|
||||
1. Add chat messages or data artifacts to Zep during each user interaction or agent event.
|
||||
2. Zep intelligently integrates new information into the user's (or groups of users) Knowledge Graph, updating existing context as needed.
|
||||
3. Retrieve relevant facts from Zep for subsequent interactions or events.
|
||||
|
||||
Zep's temporal Knowledge Graph maintains contextual information about facts, enabling reasoning about state changes and providing data provenance insights. Each fact includes `valid_at` and `invalid_at` dates, allowing agents to track changes in user preferences, traits, or environment.
|
||||
|
||||
## Zep is fast
|
||||
|
||||
Retrieving facts is simple and very fast. Unlike other memory solutions, Zep does not use agents to ensure facts are relevant. It precomputes facts, entity summaries, and other artifacts asynchronously. For on-premise use, retrieval speed primarily depends on your embedding service's performance.
|
||||
|
||||
## Zep supports many types of data
|
||||
|
||||
You can add a variety of data artifacts to Zep:
|
||||
|
||||
- Adding chat history messages.
|
||||
- Ingestion of JSON and unstructured text.
|
||||
|
||||
Zep supports chat session, user, and group-level graphs. Group graphs allow for capturing organizational knowledge.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Zep Cloud
|
||||
|
||||
1. Sign up for [Zep Cloud](https://www.getzep.com?utm_source=autogen) and create a [Project API Key](https://help.getzep.com/projects?utm_source=autogen).
|
||||
|
||||
2. Install one of the [Zep Python, TypeScript or Go SDKs](https://help.getzep.com/sdks?utm_source=autogen). Python instructions shown below.
|
||||
|
||||
```shell
|
||||
pip install zep-cloud
|
||||
```
|
||||
|
||||
3. Initialize a client
|
||||
|
||||
```python
|
||||
import os
|
||||
from zep_cloud.client import AsyncZep
|
||||
|
||||
API_KEY = os.environ.get('ZEP_API_KEY')
|
||||
client = AsyncZep(
|
||||
api_key=API_KEY,
|
||||
)
|
||||
```
|
||||
|
||||
3. Review the Zep and Autogen [notebook example](/docs/notebooks/agent_memory_using_zep/) for agent-building best practices.
|
||||
|
||||
### Zep Community Edition
|
||||
|
||||
Follow the [Getting Started guide](https://help.getzep.com/ce/quickstart?utm_source=autogen) or visit the [GitHub Repo](https://github.com/getzep/zep?utm_source=autogen).
|
||||
|
||||
## Autogen + Zep examples
|
||||
|
||||
- [Autogen Agents with Zep Memory Notebook](/docs/notebooks/agent_memory_using_zep/)
|
||||
|
||||
## Extra links
|
||||
|
||||
- [📙 Documentation](https://help.getzep.com/?utm_source=autogen)
|
||||
- [🐦 Twitter / X](https://x.com/zep_ai/)
|
||||
- [📢 Discord](https://discord.com/invite/W8Kw6bsgXQ)
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c0829b29a48ca05e2694aca00446ef5768c1b8edec56ce5035527f25f9ee4c81
|
||||
size 421633
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:179241bd4fa3ed89d721deeb1810a31b9838e7f54582d521bd91f29cbae044f2
|
||||
size 233905
|
Binary file not shown.
After Width: | Height: | Size: 10 MiB |
Loading…
Reference in New Issue