Skip to main content

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 Strands SessionRepository (all 8 CRUD methods) and mixes in RepositorySessionManager, so the Strands session lifecycle (message indexing, restore, removed_message_count offsetting, 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 so list_messages(offset, limit) is a native ordered range scan).

Storage only, by design. Message pruning in Strands is a ConversationManager concern, 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

strands_agents_session-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

strands_agents_session-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file strands_agents_session-0.1.2.tar.gz.

File metadata

  • Download URL: strands_agents_session-0.1.2.tar.gz
  • Upload date:
  • Size: 5.7 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

Hashes for strands_agents_session-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2fd4960f84d45ebad1d25c90f9621e0edf8d52d15ab0bce8689ea37be906b5a2
MD5 41207269b80132e9fc9c39c3a400e87c
BLAKE2b-256 79e05d291a9646af2528f933c5cc5beafc3f2218ef16d19617b27f1f87e52bc5

See more details on using hashes here.

File details

Details for the file strands_agents_session-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: strands_agents_session-0.1.2-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

Hashes for strands_agents_session-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd631d580104f28007afe0ddd5ba843fceeefa73738781fbf50059fecf8c806e
MD5 f8becb4c30b126b47a16368c3918ece9
BLAKE2b-256 d9180e060d6ab60c0ddc2635a58ef2a4143f642845bae83224f1eb67b00691b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page