Muokkaa

Mem0

Mem0 extracts durable memories from agent conversations and retrieves relevant memories in later runs. Configure storage and retrieval scopes when memories should be available across sessions.

This integration uses the memory pattern: it extracts and recalls selected durable information rather than replaying the complete conversation transcript.

Important

Mem0 is a third-party system. Review its data handling, retention, regional boundaries, and service terms before sending application data.

Note

Mem0 integration isn't currently available for Agent Framework .NET.

Install the package

pip install agent-framework-mem0 --pre

Set MEM0_API_KEY or pass an API key directly. Configure storage and retrieval separately:

  • user_id, agent_id, and application_id are storage scopes. Mem0 stamps them on each stored memory.
  • search_user_id, search_agent_id, and search_application_id are retrieval scopes. Mem0 uses them to select which memories it searches.

The application scopes require the Mem0 Platform client (AsyncMemoryClient). The OSS AsyncMemory client supports only user and agent scopes.

Retrieval scope doesn't inherit from storage scope. If you don't set any search_* scope, the provider stores memories but doesn't recall them.

For per-user memory, set user_id and search_user_id to the same stable identifier:

async def main() -> None:
    """Example of memory usage with Mem0 context provider."""
    print("=== Mem0 Context Provider Example ===")
    # Each record in Mem0 should be associated with agent_id or user_id or application_id.
    # In this example, we associate Mem0 records with user_id.
    user_id = str(uuid.uuid4())
    # For Azure authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
    # authentication option.
    # For Mem0 authentication, set Mem0 API key via "api_key" parameter or MEM0_API_KEY environment variable.
    async with (
        AzureCliCredential() as credential,
        Agent(
            client=FoundryChatClient(credential=credential),
            name="FriendlyAssistant",
            instructions="You are a friendly assistant.",
            tools=retrieve_company_report,
            context_providers=[Mem0ContextProvider(source_id="mem0", user_id=user_id, search_user_id=user_id)],
        ) as agent,
    ):

Mem0 processes memories asynchronously. In production, use retry or service-aware consistency handling instead of relying on a fixed delay.

Note

Mem0 integration isn't currently available for Agent Framework Go. See the Agent Framework Go repository for the latest status.

Next steps

Go deeper: