Skip to main content

Supermemory Microsoft Agent Framework SDK

Memory tools and middleware for Microsoft Agent Framework with Supermemory integration.

This package provides both automatic memory injection middleware and manual memory tools for the Microsoft Agent Framework.

Installation

Install using uv (recommended):

uv add supermemory-agent-framework

Or with pip:

pip install supermemory-agent-framework

Quick Start

Automatic Memory Injection (Recommended)

The easiest way to add memory capabilities is using the SupermemoryChatMiddleware:

import asyncio
from agent_framework.openai import OpenAIResponsesClient
from supermemory_agent_framework import (
    AgentSupermemory,
    SupermemoryChatMiddleware,
    SupermemoryMiddlewareOptions,
)

async def main():
    connection = AgentSupermemory(
        api_key="your-supermemory-api-key",
        container_tag="user-123",
    )

    middleware = SupermemoryChatMiddleware(
        connection,
        options=SupermemoryMiddlewareOptions(
            mode="full",        # "profile", "query", or "full"
            verbose=True,       # Enable logging
            add_memory="always" # Automatically save conversations
        ),
    )

    # Create agent with middleware
    agent = OpenAIResponsesClient().as_agent(
        name="MemoryAgent",
        instructions="You are a helpful assistant with memory.",
        middleware=[middleware],
    )

    # Use normally - memories are automatically injected!
    response = await agent.run(
        "What's my favorite programming language?"
    )
    print(response.text)

asyncio.run(main())

Context Provider (Recommended for Sessions)

The most idiomatic way to add memory in Agent Framework, using the same pattern as the built-in Mem0 integration:

import asyncio
from agent_framework import AgentSession
from agent_framework.openai import OpenAIResponsesClient
from supermemory_agent_framework import AgentSupermemory, SupermemoryContextProvider

async def main():
    connection = AgentSupermemory(
        api_key="your-supermemory-api-key",
        container_tag="user-123",
    )

    provider = SupermemoryContextProvider(
        connection,
        mode="full",
        store_conversations=True,
    )

    # Create agent with context provider
    agent = OpenAIResponsesClient().as_agent(
        name="MemoryAgent",
        instructions="You are a helpful assistant with memory.",
        context_providers=[provider],
    )

    # Use with a session - memories are automatically fetched and injected
    session = AgentSession()
    response = await agent.run(
        "What's my favorite programming language?",
        session=session,
    )
    print(response.text)

asyncio.run(main())

Using Memory Tools

For explicit tool-based memory access:

import asyncio
from agent_framework.openai import OpenAIResponsesClient
from supermemory_agent_framework import AgentSupermemory, SupermemoryTools

async def main():
    connection = AgentSupermemory(
        api_key="your-supermemory-api-key",
        container_tag="user-123",
    )
    tools = SupermemoryTools(connection)

    # Create agent
    agent = OpenAIResponsesClient().as_agent(
        name="MemoryAgent",
        instructions="You are a helpful assistant with access to user memories.",
    )

    # Run with memory tools
    response = await agent.run(
        "Remember that I prefer tea over coffee",
        tools=tools.get_tools(),
    )
    print(response.text)

asyncio.run(main())

Combining Middleware and Tools

For maximum flexibility, use both middleware (automatic context injection) and tools (explicit memory operations):

import asyncio
from agent_framework.openai import OpenAIResponsesClient
from supermemory_agent_framework import (
    AgentSupermemory,
    SupermemoryChatMiddleware,
    SupermemoryMiddlewareOptions,
    SupermemoryTools,
)

async def main():
    api_key = "your-supermemory-api-key"
    connection = AgentSupermemory(
        api_key=api_key,
        container_tag="user-123",
    )

    middleware = SupermemoryChatMiddleware(
        connection,
        options=SupermemoryMiddlewareOptions(mode="full"),
    )

    tools = SupermemoryTools(connection)

    agent = OpenAIResponsesClient().as_agent(
        name="MemoryAgent",
        instructions="You are a helpful assistant with memory.",
        middleware=[middleware],
    )

    # Middleware injects context automatically,
    # tools let the agent explicitly search/add memories
    response = await agent.run(
        "What do you remember about me?",
        tools=tools.get_tools(),
    )
    print(response.text)

asyncio.run(main())

Middleware Configuration

Memory Modes

"profile" mode (default)

Injects all static and dynamic profile memories into every request.

SupermemoryMiddlewareOptions(mode="profile")

"query" mode

Searches for memories relevant to the current user message.

SupermemoryMiddlewareOptions(mode="query")

"full" mode

Combines both profile and query modes.

SupermemoryMiddlewareOptions(mode="full")

Memory Storage

# Always save conversations as memories
SupermemoryMiddlewareOptions(add_memory="always")

# Never save conversations (default)
SupermemoryMiddlewareOptions(add_memory="never")

Complete Configuration

connection = AgentSupermemory(
    api_key="your-supermemory-api-key",
    container_tag="user-123",               # Memory scope
    conversation_id="chat-session-456",     # Groups stored conversations
    entity_context="User is on the pro plan", # Optional fixed context
)

middleware = SupermemoryChatMiddleware(
    connection,
    options=SupermemoryMiddlewareOptions(
        verbose=True,
        mode="full",
        add_memory="always",
    ),
)

API Reference

SupermemoryTools

Memory tools that integrate with Agent Framework's tool system.

connection = AgentSupermemory(
    api_key="your-api-key",
    container_tag="user-123",
)
tools = SupermemoryTools(connection)

# Get FunctionTool instances for Agent.run()
agent_tools = tools.get_tools()

# Or use directly
result = await tools.search_memories("user preferences")
result = await tools.add_memory("User prefers dark mode")
result = await tools.get_profile()

search_memories uses v4 hybrid search, so results can contain either a structured memory or a source chunk. The old Python-only include_full_docs argument is deprecated and ignored because v4 search does not return full source documents; it is not exposed to the model as a tool parameter.

SupermemoryChatMiddleware

Chat middleware for automatic memory injection.

middleware = SupermemoryChatMiddleware(
    connection,                           # Shared AgentSupermemory connection
    options=SupermemoryMiddlewareOptions(...),
)

SupermemoryContextProvider

Context provider for the Agent Framework session pipeline (like Mem0):

provider = SupermemoryContextProvider(
    connection,                        # Shared AgentSupermemory connection
    mode="full",                      # "profile", "query", or "full"
    store_conversations=True,         # Save conversations after each run
    context_prompt="## Memories\n...",  # Custom header for injected memories
    verbose=True,                     # Enable logging
)

Error Handling

from supermemory_agent_framework import (
    AgentSupermemory,
    SupermemoryConfigurationError,
    SupermemoryAPIError,
    SupermemoryNetworkError,
    SupermemoryMemoryOperationError,
)

try:
    connection = AgentSupermemory(container_tag="user-123")
except SupermemoryConfigurationError as e:
    print(f"Configuration issue: {e}")

Exception Types

  • SupermemoryError - Base class for all Supermemory exceptions
  • SupermemoryConfigurationError - Missing API keys, invalid configuration
  • SupermemoryAPIError - API request failures (includes status codes)
  • SupermemoryNetworkError - Network connectivity issues
  • SupermemoryMemoryOperationError - Memory search/add operation failures
  • SupermemoryTimeoutError - Operation timeouts

Environment Variables

  • SUPERMEMORY_API_KEY - Your Supermemory API key (required)
  • OPENAI_API_KEY - Your OpenAI API key (required for OpenAI-based agents)

Dependencies

Required

  • agent-framework-core>=1.0.0rc3 - Microsoft Agent Framework
  • supermemory>=3.16.0 - Supermemory client with v4 hybrid search support
  • typing-extensions>=4.0.0 - Typing compatibility helpers

Development

# Setup
cd packages/agent-framework-python
uv sync --dev

# Run tests
uv run pytest

# Type checking
uv run mypy src/supermemory_agent_framework

# Formatting
uv run black src/ tests/
uv run isort src/ tests/

License

MIT License - see LICENSE file for details.

Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supermemory_agent_framework-1.0.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supermemory_agent_framework-1.0.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file supermemory_agent_framework-1.0.1.tar.gz.

File metadata

File hashes

Hashes for supermemory_agent_framework-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dbf464071f3a92c7775d761a25e0e6180a7a5e89dac366f4aad6183bddf097f8
MD5 a54bbc16780f75bdae8c81d6f1d488ed
BLAKE2b-256 305a9a10ca1fa93efbcc9dc99ae8467b8d08f729a1d744d785567d175ca036fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for supermemory_agent_framework-1.0.1.tar.gz:

Publisher: publish-agent-framework-python.yml on supermemoryai/supermemory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file supermemory_agent_framework-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for supermemory_agent_framework-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d645daea49fed246c4aa34a3847f20a99be9a8d38a9efdfe37de489d1f6193f0
MD5 30582f293f4a3f39f94c02d11c398551
BLAKE2b-256 7738296ffe4539592c2c34a84515f271aa00239e88b884a1c49e48e6c1659595

See more details on using hashes here.

Provenance

The following attestation bundles were made for supermemory_agent_framework-1.0.1-py3-none-any.whl:

Publisher: publish-agent-framework-python.yml on supermemoryai/supermemory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.2

2 files

This release

1.0.1 This release

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page