A session manager for Valkey/Redis using Strands
Project description
Strands Valkey / Redis Session Manager
A high-performance session manager for Strands Agents that uses Valkey / Redis for persistent storage. This enables agents to maintain conversation history and state across multiple interactions, even in distributed environments.
Tested with Elasticache Serverless (Redis 7.1, Valkey 8.1), Elasticache (Redis 7.1, Valkey 8.2) and Upstash.
Features
- Persistent Sessions: Store agent conversations and state in Valkey/Redis
- Distributed Ready: Share sessions across multiple application instances
- High Performance: Leverage Valkey's speed for fast session operations
- JSON Storage: Native JSON support for complex data structures
- Automatic Cleanup: Built-in session management and cleanup capabilities
Installation
pip install strands-valkey-session-manager
Quick Start
from strands import Agent
from strands_valkey_session_manager import ValkeySessionManager
from uuid import uuid4
import valkey
# Create a Valkey client
client = valkey.Valkey(host="host", port=6379, decode_responses=True)
# Create a session manager with a unique session ID
session_manager = ValkeySessionManager(
session_id=str(uuid4()),
client=client
)
# Create an agent with the session manager
agent = Agent(session_manager=session_manager)
# Use the agent - all messages and state are automatically persisted
agent("Hello! Tell me about Valkey.")
# The conversation is now stored in Valkey and can be resumed later
Storage Structure
The ValkeySessionManager stores data using the following key structure:
session:<session_id> # Session metadata
session:<session_id>:agent:<agent_id> # Agent state and metadata
session:<session_id>:agent:<agent_id>:message:<message_id> # Individual messages
API Reference
ValkeySessionManager
ValkeySessionManager(
session_id: str,
client: Union[valkey.Valkey, valkey.ValkeyCluster]
)
Parameters:
session_id: Unique identifier for the sessionclient: Configured Valkey client instance (only synchronous versions are supported)
Methods (Note that these methods are used transparently by Strands):
create_session(session): Create a new sessionread_session(session_id): Retrieve session datadelete_session(session_id): Remove session and all associated datacreate_agent(session_id, agent): Store agent in sessionread_agent(session_id, agent_id): Retrieve agent dataupdate_agent(session_id, agent): Update agent statecreate_message(session_id, agent_id, message): Store messageread_message(session_id, agent_id, message_id): Retrieve messageupdate_message(session_id, agent_id, message): Update messagelist_messages(session_id, agent_id, limit=None): List all messages
Contributing
Setup
# Clone the repository
git clone https://github.com/jeromevdl/strands-valkey-session-manager
cd strands-valkey-session-manager
# Install in development mode with Hatch
hatch shell dev
Running Tests
# Run unit tests only (default)
hatch run dev:test
# Run all tests including integration tests
hatch run dev:test-all
# Run with coverage
hatch run dev:test-cov
Integration Tests
Integration tests require a running Valkey/Redis instance:
# Start Redis with JSON (Docker)
docker run -d -p 6379:6379 redislabs/rejson:latest
# Run integration tests
hatch run dev:test-integration
Requirements
- Python 3.10+
- Valkey/Redis server
- strands-agents >= 1.0.0
- valkey >= 6.0.0
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
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_valkey_session_manager-0.1.0.tar.gz.
File metadata
- Download URL: strands_valkey_session_manager-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e7dbdc7955d499bbdb6fa0d8200f16dd2d062aac367c584ddeaf5b9ba1f9363
|
|
| MD5 |
74c7d1a2e3bbd3633b68a1a68f2fda87
|
|
| BLAKE2b-256 |
4447b5b2ecb56ce3bacdf6ed02f69b220f5decfd477479fd1b37193d2df46e80
|
Provenance
The following attestation bundles were made for strands_valkey_session_manager-0.1.0.tar.gz:
Publisher:
pypi-publish-on-release.yml on jeromevdl/strands-valkey-session-manager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strands_valkey_session_manager-0.1.0.tar.gz -
Subject digest:
1e7dbdc7955d499bbdb6fa0d8200f16dd2d062aac367c584ddeaf5b9ba1f9363 - Sigstore transparency entry: 612461566
- Sigstore integration time:
-
Permalink:
jeromevdl/strands-valkey-session-manager@439c0950c8bdbbdb217c3cc9aa1de15f06f71dbe -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/jeromevdl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish-on-release.yml@439c0950c8bdbbdb217c3cc9aa1de15f06f71dbe -
Trigger Event:
release
-
Statement type:
File details
Details for the file strands_valkey_session_manager-0.1.0-py3-none-any.whl.
File metadata
- Download URL: strands_valkey_session_manager-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b73762c228deec3df0860bb4fb8116faa94adf0bfba9fbd9545d34a05cce2c0
|
|
| MD5 |
6438be68a18a04b692e452b43402de7c
|
|
| BLAKE2b-256 |
0c8570a759fe7d1bda49c469ab609c87610ffe74e8f138009348d3b13df56dfe
|
Provenance
The following attestation bundles were made for strands_valkey_session_manager-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish-on-release.yml on jeromevdl/strands-valkey-session-manager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strands_valkey_session_manager-0.1.0-py3-none-any.whl -
Subject digest:
6b73762c228deec3df0860bb4fb8116faa94adf0bfba9fbd9545d34a05cce2c0 - Sigstore transparency entry: 612461626
- Sigstore integration time:
-
Permalink:
jeromevdl/strands-valkey-session-manager@439c0950c8bdbbdb217c3cc9aa1de15f06f71dbe -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/jeromevdl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish-on-release.yml@439c0950c8bdbbdb217c3cc9aa1de15f06f71dbe -
Trigger Event:
release
-
Statement type: