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
Metadata
Release files for smaran-agent-framework 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| smaran_agent_framework-0.1.1.tar.gz | 9.9 kB | With provenance | Details for smaran_agent_framework-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smaran_agent_framework-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for smaran_agent_framework-0.1.1-py3-none-any.whl |
Total release size: 23.2 kB
Release files / smaran_agent_framework-0.1.1.tar.gz
| Download URL | smaran_agent_framework-0.1.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31e3a6f5367df6a21535ba97f2f325570fb104b7d290f34277adb78a7bed3a54
|
|
BLAKE2b-256 checksum How to use checksums |
a697de2e67896f881e054f53409750a162fa3b455390ba4f1f35f28df0e2b860
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logRelease files / smaran_agent_framework-0.1.1-py3-none-any.whl
| Download URL | smaran_agent_framework-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acfd6074186ca0d1828278c2df0e68dac0e54d0f93fa4e35187dfdafa9c3fefa
|
|
BLAKE2b-256 checksum How to use checksums |
79558565cb4bdd3c88c0cd592bad34b6ef497ae7becbe3069e3dd601589f9d06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logSecurity for smaran-agent-framework 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for smaran_agent_framework-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.