Skip to content

Persist sessions

Session management persists a conversation so a long-running task survives a restart. Strands harness keeps sessions on by default: without a session id, each agent starts fresh under a new random id.

Pass session={"id": ...} and Strands harness persists the conversation to disk, then rehydrates it the next time you build an agent with the same id. Reuse the id to resume; use a new id to start clean.

from strands_harness import create_harness
agent = create_harness(session={"id": "refactor-parser"})
agent("Let's refactor the parser. Where should we start?")
# ...later, in a new process...
resumed = create_harness(session={"id": "refactor-parser"})
resumed("Where did we leave off?")

The id is sanitized to lowercase alphanumerics, hyphens, and underscores, so "Refactor Parser" and "refactor-parser" resolve to the same session.

By default session state is written under ./.agent/sessions. Set session={"dir": ...} to put it elsewhere:

from strands_harness import create_harness
agent = create_harness(session={"id": "refactor-parser",
"dir": "/var/lib/agent/sessions"})

When a session is active, offloaded tool results (from context management) are kept under the session directory too, so they stay durable across restarts alongside the conversation. Without a session, they stay in memory and do not outlive the process.

Sessions and long-term memory are separate. A session persists one conversation, replayed only when you resume that id. Memory distills durable facts that the agent recalls across every conversation, with or without a session. Use a session to continue a specific task; rely on memory to carry knowledge between unrelated runs.

Both SDKs write session snapshots to local files, but through different classes. The Python SDK uses a SnapshotSessionManager backed by LocalFileStorage. The TypeScript SDK composes the shared Storage abstraction, using a SessionManager whose snapshot storage is a file storage under the session directory. Either way the on-disk result is a local session store rooted at the session directory.

To supply your own session manager (for example an S3-backed one), pass it through to the Agent; your explicit manager wins over the one Strands harness would build from session. Pass storage along with it too: without it, offloaded tool results are embedded in every snapshot the manager writes instead of being stored once. For the storage backends, see storage. For the full option list, see the configuration reference.