
<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> Shows an example of how to use the `Memory` interface to implement a just-in-time vector memory based on chromadb. ```python import os from pathlib import Path from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.ui import Console from autogen_core.memory import MemoryContent, MemoryMimeType from autogen_ext.memory.chromadb import ChromaDBVectorMemory, PersistentChromaDBVectorMemoryConfig from autogen_ext.models.openai import OpenAIChatCompletionClient # Initialize ChromaDB memory with custom config chroma_user_memory = ChromaDBVectorMemory( config=PersistentChromaDBVectorMemoryConfig( collection_name="preferences", persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"), k=2, # Return top k results score_threshold=0.4, # Minimum similarity score ) ) # a HttpChromaDBVectorMemoryConfig is also supported for connecting to a remote ChromaDB server # Add user preferences to memory await chroma_user_memory.add( MemoryContent( content="The weather should be in metric units", mime_type=MemoryMimeType.TEXT, metadata={"category": "preferences", "type": "units"}, ) ) await chroma_user_memory.add( MemoryContent( content="Meal recipe must be vegan", mime_type=MemoryMimeType.TEXT, metadata={"category": "preferences", "type": "dietary"}, ) ) # Create assistant agent with ChromaDB memory assistant_agent = AssistantAgent( name="assistant_agent", model_client=OpenAIChatCompletionClient( model="gpt-4o", ), tools=[get_weather], memory=[user_memory], ) stream = assistant_agent.run_stream(task="What is the weather in New York?") await Console(stream) await user_memory.close() ``` ```txt ---------- user ---------- What is the weather in New York? ---------- assistant_agent ---------- [MemoryContent(content='The weather should be in metric units', mime_type='MemoryMimeType.TEXT', metadata={'category': 'preferences', 'mime_type': 'MemoryMimeType.TEXT', 'type': 'units', 'score': 0.4342913043162201, 'id': '8a8d683c-5866-41e1-ac17-08c4fda6da86'}), MemoryContent(content='The weather should be in metric units', mime_type='MemoryMimeType.TEXT', metadata={'category': 'preferences', 'mime_type': 'MemoryMimeType.TEXT', 'type': 'units', 'score': 0.4342913043162201, 'id': 'f27af42c-cb63-46f0-b26b-ffcc09955ca1'})] ---------- assistant_agent ---------- [FunctionCall(id='call_a8U3YEj2dxA065vyzdfXDtNf', arguments='{"city":"New York","units":"metric"}', name='get_weather')] ---------- assistant_agent ---------- [FunctionExecutionResult(content='The weather in New York is 23 °C and Sunny.', call_id='call_a8U3YEj2dxA065vyzdfXDtNf', is_error=False)] ---------- assistant_agent ---------- The weather in New York is 23 °C and Sunny. ``` Note that MemoryContent object in the MemoryQuery events have useful metadata like the score and id retrieved memories. ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
Building the AutoGen Documentation
AutoGen documentation is based on the sphinx documentation system and uses the myst-parser to render markdown files. It uses the pydata-sphinx-theme to style the documentation.
Prerequisites
Ensure you have all of the dev dependencies for the autogen-core
package installed. You can install them by running the following command from the root of the python repository:
uv sync
source .venv/bin/activate
Building Docs
To build the documentation, run the following command from the root of the python repository:
poe --directory ./packages/autogen-core/ docs-build
To serve the documentation locally, run the following command from the root of the python repository:
poe --directory ./packages/autogen-core/ docs-serve
[!NOTE]
Sphinx will only rebuild files that have changed since the last build. If you want to force a full rebuild, you can delete the ./packages/autogen-core/docs/build
directory before running the docs-build
command.
Versioning the Documentation
The current theme - pydata-sphinx-theme - supports switching between versions of the documentation.
To version the documentation, you need to create a new version of the documentation by copying the existing documentation to a new directory with the version number. For example, to create a new version of the documentation for version 0.1.0
, you would run the following command:
How are various versions built? - TBD.