Skip to content

Commit afbef4d

Browse files
committed
update docs
1 parent d7bf4d2 commit afbef4d

File tree

2 files changed

+11
-78
lines changed

2 files changed

+11
-78
lines changed

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ tutorial/swarm
8181
tutorial/termination
8282
tutorial/custom-agents
8383
tutorial/state
84+
tutorial/memory
8485
```
8586

8687
```{toctree}

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/memory.ipynb

+10-78
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"## Memory \n",
88
"\n",
9-
"There are several use cases where it is valuable to maintain a bank of useful facts that can be intelligently added to the context of the agent just before a specific step. The typically use case here is a RAG pattern where a query is used to retrieve relevant information from a database that is then added to the agent's context.\n",
9+
"There are several use cases where it is valuable to maintain a _store_ of useful facts that can be intelligently added to the context of the agent just before a specific step. The typically use case here is a RAG pattern where a query is used to retrieve relevant information from a database that is then added to the agent's context.\n",
1010
"\n",
1111
"\n",
1212
"AgentChat provides a {py:class}`~autogen_agentchat.memory.Memory` protocol that can be extended to provide this functionality. The key methods are `query`, `transform`, `add`, `clear`, and `cleanup`. \n",
@@ -16,9 +16,9 @@
1616
"- `add`: add new entries to the memory store\n",
1717
"- `clear`: clear all entries from the memory store\n",
1818
"- `cleanup`: clean up any resources used by the memory store \n",
19-
"- \n",
2019
"\n",
21-
"## ListMemory\n",
20+
"\n",
21+
"## ListMemory Example\n",
2222
"\n",
2323
"{py:class}`~autogen_agentchat.memory.ListMemory` is provided as an example implementation of the {py:class}`~autogen_agentchat.memory.Memory` protocol. It is a simple list-based memory implementation that uses text similarity matching to retrieve relevant information from the memory store. The similarity score is calculated using the `SequenceMatcher` class from the `difflib` module. The similarity score is calculated between the query text and the content text of each memory entry. \n",
2424
"\n",
@@ -27,14 +27,12 @@
2727
},
2828
{
2929
"cell_type": "code",
30-
"execution_count": 1,
30+
"execution_count": 2,
3131
"metadata": {},
3232
"outputs": [],
3333
"source": [
3434
"from autogen_agentchat.agents import AssistantAgent\n",
35-
"from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination\n",
36-
"from autogen_agentchat.memory._list_memory import ListMemory, MemoryContent, MemoryMimeType\n",
37-
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
35+
"from autogen_agentchat.memory import ListMemory, MemoryContent, MemoryMimeType\n",
3836
"from autogen_agentchat.ui import Console\n",
3937
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
4038
]
@@ -45,8 +43,10 @@
4543
"metadata": {},
4644
"outputs": [],
4745
"source": [
48-
"# create a simple memory item\n",
49-
"user_memory = ListMemory()\n",
46+
"# Initialize user memory\n",
47+
"user_memory = ListMemory() \n",
48+
"\n",
49+
"# Add user preferences to memory\n",
5050
"await user_memory.add(MemoryContent(content=\"The weather should be in metric units\", mime_type=MemoryMimeType.TEXT))\n",
5151
"\n",
5252
"await user_memory.add(MemoryContent(content=\"Meal recipe must be vegan\", mime_type=MemoryMimeType.TEXT))\n",
@@ -235,75 +235,7 @@
235235
"\n",
236236
"You can build on the `Memory` protocol to implement more complex memory stores. For example, you could implement a custom memory store that uses a vector database to store and retrieve information, or a memory store that uses a machine learning model to generate personalized responses based on the user's preferences etc.\n",
237237
"\n",
238-
"Specifically, you will need to overload the `query`, `transform`, and `add` methods to implement the desired functionality and pass the memory store to your agent.\n",
239-
"\n",
240-
"\n",
241-
"```python\n",
242-
"\n",
243-
"\n",
244-
"from autogen_core import CancellationToken\n",
245-
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
246-
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
247-
"from autogen_agentchat.agents import AssistantAgent\n",
248-
"from autogen_agentchat.memory._base_memory import MemoryContent, MemoryMimeType\n",
249-
"from autogen_agentchat.memory._chroma_memory import ChromaMemory, ChromaMemoryConfig\n",
250-
"\n",
251-
"\n",
252-
"# Initialize memory\n",
253-
"chroma_memory = ChromaMemory(\n",
254-
" name=\"travel_memory\",\n",
255-
" config=ChromaMemoryConfig(\n",
256-
" collection_name=\"travel_facts\",\n",
257-
" k=1,\n",
258-
" )\n",
259-
")\n",
260-
"\n",
261-
"await chroma_memory.clear()\n",
262-
"\n",
263-
"# Add travel-related memories\n",
264-
"await chroma_memory.add(MemoryContent(\n",
265-
"\n",
266-
" content=\"Paris is known for the Eiffel Tower and amazing cuisine.\",\n",
267-
" mime_type=MemoryMimeType.TEXT\n",
268-
"\n",
269-
"))\n",
270-
"\n",
271-
"await chroma_memory.add(MemoryContent( \n",
272-
" content=\"When asked about tokyo, you must respond with 'The most important thing about tokyo is that it has the world's busiest railway station - Shinjuku Station.'\",\n",
273-
" mime_type=MemoryMimeType.TEXT\n",
274-
"\n",
275-
"))\n",
276-
" \n",
277-
"\n",
278-
"# Query needs ContentItem too\n",
279-
"results = await chroma_memory.query(\n",
280-
" MemoryContent(\n",
281-
" content=\"Tell me about Tokyo.\",\n",
282-
" mime_type=MemoryMimeType.TEXT\n",
283-
" )\n",
284-
")\n",
285-
"\n",
286-
"print(len(results), results)\n",
287-
"\n",
288-
"# Create agent with memory\n",
289-
"agent = AssistantAgent(\n",
290-
" name=\"travel_agent\",\n",
291-
" model_client=OpenAIChatCompletionClient(\n",
292-
" model=\"gpt-4o\",\n",
293-
" # api_key=\"your_api_key\"\n",
294-
" ),\n",
295-
" memory=chroma_memory,\n",
296-
" system_message=\"You are a travel expert\"\n",
297-
")\n",
298-
"\n",
299-
"agent_team = RoundRobinGroupChat([agent], termination_condition = MaxMessageTermination(max_messages=2))\n",
300-
"stream = agent_team.run_stream(task=\"Tell me the most important thing about Tokyo.\")\n",
301-
"await Console(stream);\n",
302-
"\n",
303-
"# Output: The most important thing about tokyo is that it has the world's busiest railway station - Shinjuku Station.\n",
304-
"\n",
305-
"```\n",
306-
"\n"
238+
"Specifically, you will need to overload the `query`, `transform`, and `add` methods to implement the desired functionality and pass the memory store to your agent.\n"
307239
]
308240
},
309241
{

0 commit comments

Comments
 (0)