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 the package:Get your Supermemory API key from console.supermemory.ai.
Connection
All integration points share a singleAgentSupermemory connection. This ensures the same API client, container tag, and conversation ID are used across middleware, tools, and context providers.
Connection options
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | env var | Supermemory API key. Falls back to SUPERMEMORY_API_KEY |
container_tag | str | "msft_agent_chat" | Memory scope (e.g., user ID) |
conversation_id | str | auto-generated | Groups messages into a conversation |
entity_context | str | None | Custom context about the user, prepended to memories |
Context provider (recommended)
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
before_run()— Searches Supermemory for the user’s profile and relevant memories, then injects them into the session context as additional instructionsafter_run()— Ifstore_conversations=True, saves the conversation to Supermemory so future sessions have more context
Configuration options
| Parameter | Type | Default | Description |
|---|---|---|---|
connection | AgentSupermemory | required | Shared connection |
mode | str | "full" | "profile", "query", or "full" |
store_conversations | bool | False | Save conversations after each run |
context_prompt | str | built-in | Custom prompt describing the memories |
verbose | bool | False | Enable detailed logging |
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 queryadd_memory— Store new information for later recallget_profile— Fetch the user’s full profile (static + dynamic facts)
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
| Mode | What it fetches | Best for |
|---|---|---|
"profile" | User profile (static + dynamic facts) only | Personalization without query overhead |
"query" | Memories relevant to the current message only | Targeted recall, no profile data |
"full" (default) | Profile + query search combined | Maximum context |
Example: support agent with memory
A support agent that remembers customers across sessions:Error handling
The package provides specific exception types:| Exception | When |
|---|---|
SupermemoryConfigurationError | Missing API key or invalid config |
SupermemoryAPIError | API returned an error response |
SupermemoryNetworkError | Connection failure |
SupermemoryTimeoutError | Request timed out |
SupermemoryMemoryOperationError | Memory add/search failed |
Related docs
User profiles
How automatic profiling works
Search
Filtering and search modes
OpenAI Agents SDK
Memory for OpenAI Agents SDK
LangChain
Memory for LangChain apps