Skip to main content
Microsoft’s Agent Framework is a Python framework for building AI agents with tools, handoffs, and context providers. Supermemory integrates natively as a context provider, tool set, or middleware — so your agents remember users across sessions.

What you can do

  • Automatically inject user memories before every agent run (context provider)
  • Give agents tools to search and store memories on their own
  • Intercept chat requests to add memory context via middleware
  • Combine all three for maximum flexibility

Setup

Install adapter version >=2.0.0,<3 with the OpenAI client package:
Or with uv:
The adapter requires supermemory>=5.0.0,<6. The OpenAI examples also require the separate agent-framework-openai package and use its current OpenAIChatClient Responses API client. Older supported framework cores can have different OpenAI client names and model arguments. Set up your environment:
Get your Supermemory API key from console.supermemory.ai.

Connection

All integration points share a single AgentSupermemory connection. This ensures the same API client, container tag, and conversation ID are used across middleware, tools, and context providers.

Connection options

Pass this connection to any integration:

Existing callers and data

Keep the existing container_tag and conversation_id arguments. The adapter sends the container tag as the v5 namespace and the unchanged conversation_<conversation_id> as the document id. Choose a distinct container tag per user or tenant: the default msft_agent_chat scope is shared. Repeated writes append/diff into the same conversation document; they do not replace previous turns. entity_context remains context prepended to retrieved memories, not an ingestion setting. Existing Agent Framework session exports remain loadable because the provider does not change its scoped state. Reconstruct the connection with the same identifiers after loading a session; connections and API credentials are not part of provider state. This adapter migration does not move existing server-side data. Confirm old data is available in the corresponding v5 namespace using the v5 migration guide; the adapter does not delete or rewrite legacy data.
The most idiomatic integration. Follows the same pattern as Agent Framework’s built-in Mem0 provider — memories are automatically fetched before the LLM runs and conversations can be stored afterward.

How it works

  1. before_run() — Searches Supermemory for the user’s profile and relevant memories, then injects them into the session context as additional instructions
  2. after_run() — If store_conversations=True, saves the conversation to Supermemory so future sessions have more context

Configuration options


Memory tools

Give agents explicit control over memory operations. The agent decides when to search or store information.

Available tools

The agent gets three tools:
  • search_memories — Search for relevant memories by query
  • add_memory — Store new information for later recall
  • get_profile — Fetch the user’s full profile (static + dynamic facts)
Tool JSON envelopes are preserved. Profiles still expose string arrays for static, dynamic, and bucket facts. A query passed to get_profile triggers a separate v5 search, returned under search_results with results, timing, and total (the number returned). Search results keep their top-level updated_at timestamp and include v5 metadata; legacy optional fields not returned by v5 remain present as null because their values cannot be reconstructed. The deprecated Python-only include_full_docs argument remains ignored and is not exposed to the model.

Chat middleware

Intercept chat requests to automatically inject memory context. Useful when you want memory injection without the session-based context provider pattern.

Memory modes

V5 profile retrieval does not accept a search query. Full mode makes separate profile and search requests and deduplicates overlapping facts before injection. Profile-associated searches keep the legacy memory-only mode and 0.6 threshold; the explicit search tool keeps hybrid mode and 0.6. Writes are asynchronous; an accepted document may not be immediately searchable, and this migration does not change the SDK’s default processing mode.

Example: support agent with memory

A support agent that remembers customers across sessions:
This example stores conversations through the provider only. Enabling middleware storage as well can submit overlapping content; use both only when intentional.

Error handling

The package provides specific exception types: Tools return operation failures as JSON (success: false, error). Provider retrieval/storage and middleware retrieval failures are logged and let the agent continue without memories. Middleware background write failures are logged rather than raised by wait_for_background_tasks(); a timeout on that wait still raises asyncio.TimeoutError.

User profiles

How automatic profiling works

Search

Filtering and search modes

OpenAI Agents SDK

Memory for OpenAI Agents SDK

LangChain

Memory for LangChain apps