Skip to main content

smaran-agent-framework

Memory tools and middleware for Microsoft Agent Framework with Smaran.

Three ways to add memory, usable independently or together:

  • SmaranChatMiddleware — automatically recalls relevant memories and injects them into the system prompt on every call, and can save conversations after.
  • SmaranContextProvider — the idiomatic Agent Framework pattern (same shape as the built-in Mem0 integration), hooking into before_run/after_run on a session.
  • SmaranTools — explicit search_memories/add_memory function tools the model can call itself.

Installation

pip install smaran-agent-framework

Quick Start

Chat middleware (recommended for most agents)

import asyncio
from agent_framework.openai import OpenAIResponsesClient
from smaran_agent_framework import AgentSmaran, SmaranChatMiddleware, SmaranMiddlewareOptions

async def main():
    conn = AgentSmaran(
        api_key="your-smaran-api-key",   # or set SMARAN_API_KEY
        base_url="https://your-smaran-deployment",  # or set SMARAN_URL
        user_id="user-123",
    )

    middleware = SmaranChatMiddleware(
        conn,
        options=SmaranMiddlewareOptions(verbose=True, save_conversations=True),
    )

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

    response = await agent.run("What's my favorite programming language?")
    print(response.text)

asyncio.run(main())

Context provider (idiomatic session pattern)

from agent_framework import AgentSession
from agent_framework.openai import OpenAIResponsesClient
from smaran_agent_framework import AgentSmaran, SmaranContextProvider

conn = AgentSmaran(api_key="your-smaran-api-key", user_id="user-123")
provider = SmaranContextProvider(conn, store_conversations=True)

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

session = AgentSession()
response = await agent.run("What's my favorite programming language?", session=session)

Explicit memory tools

from smaran_agent_framework import AgentSmaran, SmaranTools

conn = AgentSmaran(api_key="your-smaran-api-key", user_id="user-123")
tools = SmaranTools(conn)

response = await agent.run(
    "Remember that I prefer tea over coffee",
    tools=tools.get_tools(),
)

All three share the same AgentSmaran connection, so middleware/provider/tools can be combined on one agent without duplicating configuration.

Configuration

SmaranMiddlewareOptions(
    verbose=False,            # Enable detailed logging
    search_limit=5,           # Max memories recalled per turn
    save_conversations=False, # Save the conversation as a memory after each run
)

AgentSmaran takes api_key, base_url, user_id (memory scope), entity_context (static text prepended to every recall), and conversation_id (defaults to a random UUID; used to group saved messages).

Error Handling

from smaran_agent_framework import (
    SmaranConfigurationError,
    SmaranAPIError,
    SmaranNetworkError,
    SmaranMemoryOperationError,
)

try:
    conn = AgentSmaran(user_id="user-123")  # raises if SMARAN_API_KEY/SMARAN_URL are unset
except SmaranConfigurationError as e:
    print(f"Configuration issue: {e}")
  • SmaranError — base class for all exceptions here
  • SmaranConfigurationError — missing API key or base URL
  • SmaranAPIError — API request failures (includes status code)
  • SmaranNetworkError — network connectivity issues
  • SmaranMemoryOperationError — recall/save operation failures

Environment Variables

  • SMARAN_API_KEY — your Smaran API key
  • SMARAN_URL — your self-hosted or managed Smaran API base URL

Development

cd packages/agent-framework-python
uv sync --dev
uv run pytest
uv run mypy src/smaran_agent_framework

License

MIT

Download files

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

Source Distribution

smaran_agent_framework-0.1.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

smaran_agent_framework-0.1.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file smaran_agent_framework-0.1.1.tar.gz.

File metadata

  • Download URL: smaran_agent_framework-0.1.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smaran_agent_framework-0.1.1.tar.gz
Algorithm Hash digest
SHA256 31e3a6f5367df6a21535ba97f2f325570fb104b7d290f34277adb78a7bed3a54
MD5 bf673ed6f3d9a3a6de9c14649800f1d1
BLAKE2b-256 a697de2e67896f881e054f53409750a162fa3b455390ba4f1f35f28df0e2b860

See more details on using hashes here.

Provenance

The following attestation bundles were made for smaran_agent_framework-0.1.1.tar.gz:

Publisher: publish-agent-framework-python.yml on Ayushpani/smaran

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

File details

Details for the file smaran_agent_framework-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for smaran_agent_framework-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 acfd6074186ca0d1828278c2df0e68dac0e54d0f93fa4e35187dfdafa9c3fefa
MD5 162513941decec0254742d09eabb4552
BLAKE2b-256 79558565cb4bdd3c88c0cd592bad34b6ef497ae7becbe3069e3dd601589f9d06

See more details on using hashes here.

Provenance

The following attestation bundles were made for smaran_agent_framework-0.1.1-py3-none-any.whl:

Publisher: publish-agent-framework-python.yml on Ayushpani/smaran

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

Release history Release notifications | RSS feed

This release

0.1.1 This release

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