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 intobefore_run/after_runon a session.SmaranTools— explicitsearch_memories/add_memoryfunction 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 hereSmaranConfigurationError— missing API key or base URLSmaranAPIError— API request failures (includes status code)SmaranNetworkError— network connectivity issuesSmaranMemoryOperationError— recall/save operation failures
Environment Variables
SMARAN_API_KEY— your Smaran API keySMARAN_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31e3a6f5367df6a21535ba97f2f325570fb104b7d290f34277adb78a7bed3a54
|
|
| MD5 |
bf673ed6f3d9a3a6de9c14649800f1d1
|
|
| BLAKE2b-256 |
a697de2e67896f881e054f53409750a162fa3b455390ba4f1f35f28df0e2b860
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smaran_agent_framework-0.1.1.tar.gz -
Subject digest:
31e3a6f5367df6a21535ba97f2f325570fb104b7d290f34277adb78a7bed3a54 - Sigstore transparency entry: 2726263456
- Sigstore integration time:
-
Permalink:
Ayushpani/smaran@424c5a332d6e13a2adb3c2ba6a9554ea4cb12662 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ayushpani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-agent-framework-python.yml@424c5a332d6e13a2adb3c2ba6a9554ea4cb12662 -
Trigger Event:
push
-
Statement type:
File details
Details for the file smaran_agent_framework-0.1.1-py3-none-any.whl.
File metadata
- Download URL: smaran_agent_framework-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acfd6074186ca0d1828278c2df0e68dac0e54d0f93fa4e35187dfdafa9c3fefa
|
|
| MD5 |
162513941decec0254742d09eabb4552
|
|
| BLAKE2b-256 |
79558565cb4bdd3c88c0cd592bad34b6ef497ae7becbe3069e3dd601589f9d06
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smaran_agent_framework-0.1.1-py3-none-any.whl -
Subject digest:
acfd6074186ca0d1828278c2df0e68dac0e54d0f93fa4e35187dfdafa9c3fefa - Sigstore transparency entry: 2726263501
- Sigstore integration time:
-
Permalink:
Ayushpani/smaran@424c5a332d6e13a2adb3c2ba6a9554ea4cb12662 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ayushpani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-agent-framework-python.yml@424c5a332d6e13a2adb3c2ba6a9554ea4cb12662 -
Trigger Event:
push
-
Statement type: