Skip to content

Strands Agents sessions

Strands Agents persist sessions through a session manager. strands-persql is a drop-in replacement for FileSessionManager / S3SessionManager that stores sessions, agent state, and messages in a PerSQL database — an isolated SQLite database you can query like any other.

pip install strands-persql
import os
from strands import Agent
from persql import PerSQL
from strands_persql import PerSQLSessionManager
client = PerSQL(token=os.environ["PERSQL_TOKEN"])
manager = PerSQLSessionManager("user-42", client.database("acme/agent-state"))
agent = Agent(session_manager=manager)
agent("hi")
agent("remember me?") # history and state persist across restarts

PerSQLSessionRepository is also exported for use with RepositorySessionManager or your own manager. Multi-agent (Graph and Swarm) state persists too.

Sessions are keyed by session id and can share one database. For hard isolation, give each tenant its own database instead:

manager = PerSQLSessionManager(session_id, client.database(f"acme/tenant-{tenant_id}"))

PerSQL databases are provisioned on first write and billed by usage, so per-tenant session stores cost what they’re actually used for.

SELECT message_id, json_extract(data, '$.message.role') AS role, created_at
FROM strands_messages
WHERE session_id = 'user-42'
ORDER BY message_id;