Mem0 Integration for Microsoft Agent Framework

1.0.0b260409 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `Mem0Memory` and interact with it using asynchronous calls. It requires the `MEM0_API_KEY` environment variable for authentication with the Mem0 service. The example shows adding memories and then retrieving them based on a query for a specific user ID.

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())

view raw JSON →