Mem0 Integration for Microsoft Agent Framework
The `agent-framework-mem0` library provides a robust integration for Mem0, a memory framework for AI agents, with the Microsoft Agent Framework. It enables agents built on Microsoft's framework to leverage Mem0's stateful, long-term, and short-term memory capabilities, enhancing agent context and decision-making. As of the current version `1.0.0b260409`, the library is in beta, indicating active development and potential for rapid evolution. Its release cadence involves frequent beta updates.
Warnings
- breaking As a beta library, API interfaces, configuration options, and internal implementations are subject to frequent breaking changes without prior notice. Always check the latest GitHub README and changelog.
- gotcha Authentication requires a `MEM0_API_KEY` which must be provided either directly during initialization or via the `MEM0_API_KEY` environment variable. Forgetting this will lead to authentication errors.
- gotcha The library primarily exposes an asynchronous API. All interactions with `Mem0Memory` methods (e.g., `add`, `get`) must be `await`-ed within an `async` function and run using `asyncio.run()` or similar asynchronous event loop management.
- gotcha The library typically pins specific versions of its core dependencies (`mem0` and `microsoft-agent-framework`). This can lead to dependency conflicts if other libraries in your project require different versions of these same packages.
Install
-
pip install agent-framework-mem0
Imports
- Mem0Memory
from agent_framework_mem0.memories import Mem0Memory
Quickstart
import asyncio
import os
from agent_framework_mem0.memories import Mem0Memory
async def main():
mem0_api_key = os.environ.get("MEM0_API_KEY", "")
if not mem0_api_key:
print("Please set the MEM0_API_KEY environment variable. You can get one from mem0.ai")
return
memory = Mem0Memory(mem0_api_key=mem0_api_key)
# Example usage: Add and retrieve memory
await memory.add(user_id="test_user", text="I like pizza.")
print("Added memory: 'I like pizza.'")
retrieved_memory = await memory.get(user_id="test_user", query="What do I like?")
print(f"Retrieved memory for 'What do I like?': {retrieved_memory}")
await memory.add(user_id="test_user", text="My favorite color is blue.")
print("Added memory: 'My favorite color is blue.'")
retrieved_memory_2 = await memory.get(user_id="test_user", query="What is my favorite color?")
print(f"Retrieved memory for 'What is my favorite color?': {retrieved_memory_2}")
if __name__ == "__main__":
asyncio.run(main())