Backend-agnostic session management for Strands Agents — a SessionStorage interface + KeyValueSessionManager to build session backends (DynamoDB, Redis, MongoDB, …)
Project description
strands-agents-session
Backend-agnostic session management for Strands Agents. Provides the shared machinery so you can build a session storage backend (DynamoDB, Redis, MongoDB, Postgres, …) by implementing just a handful of methods.
This is the base package of a family. Concrete backends are shipped separately, e.g. strands-session-dynamodb.
What it gives you
KeyValueSessionManager— implements the full StrandsSessionRepository(all 8 CRUD methods) and mixes inRepositorySessionManager, so the Strands session lifecycle (message indexing, restore,removed_message_countoffsetting, tool-use repair, change detection) is reused unchanged.SessionStorage— a tiny ordered keyed-record interface (put/get/query/delete/delete_partition). Implement it and you have a working Strands session backend.InMemorySessionStorage— a ready in-memory backend for tests and local development.keys— shared key/serialization conventions (zero-padded message sort keys solist_messages(offset, limit)is a native ordered range scan).
Storage only, by design. Message pruning in Strands is a
ConversationManagerconcern, deliberately decoupled from storage. This package (and its backends) never prune — doing so at the storage layer would corrupt Strands' message-index/offset restore logic.
Installation
pip install strands-agents-session
Requires Python 3.10+.
Using the in-memory backend
from strands import Agent
from strands_agents_session import KeyValueSessionManager, InMemorySessionStorage
session_manager = KeyValueSessionManager(
session_id="user-123",
storage=InMemorySessionStorage(),
)
agent = Agent(session_manager=session_manager)
Building a backend
Implement SessionStorage and hand it to KeyValueSessionManager:
from strands_agents_session import KeyValueSessionManager, SessionStorage
class MyStorage(SessionStorage):
def put(self, item): ... # item = {"pk", "sk", "data"}
def get(self, pk, sk): ... # -> item | None
def query(self, pk, sk_gte=None, limit=None): ... # ordered by sk asc
def delete(self, pk, sk): ...
def delete_partition(self, pk): ...
class MySessionManager(KeyValueSessionManager):
def __init__(self, session_id, **cfg):
super().__init__(session_id=session_id, storage=MyStorage(**cfg))
That's it — all the SessionRepository methods, restore logic, and pagination come from the base.
License
MIT
Project details
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 strands_agents_session-0.1.0.tar.gz.
File metadata
- Download URL: strands_agents_session-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ca89e3df3355cd22a986335130164b269f5d0d4a4e4ca746b7409d2d76182d7
|
|
| MD5 |
23ecbc3979d974a6df2243c7dea4c144
|
|
| BLAKE2b-256 |
8be07088f6df3e4cdb4c4b4ee902f6e0cade17807efb239e1bff72388e5b5583
|
File details
Details for the file strands_agents_session-0.1.0-py3-none-any.whl.
File metadata
- Download URL: strands_agents_session-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b67c4fabb1e6c4cacca2e030aab731a187572b91ea78aaa25202a4946fd06070
|
|
| MD5 |
1bc0173f710a956e8c421668dbc98d1b
|
|
| BLAKE2b-256 |
117faaaa23a47e14201e0b335f2c14e4227004aeb77988cb8fd6a888443c3ea3
|