Skip to content

Storage

To persist agent state between restarts, pass a Storage backend to the plugins that need it. You pick the backend once; plugins like Context Offloader, Session Management, and Memory handle the rest.

The SDK ships three backends. Pick one based on where you need your data to live:

BackendWhere data livesBest for
InMemoryStorageProcess memoryTests, short-lived agents
LocalFileStorageLocal filesystemDevelopment, single-machine
S3StorageAmazon S3Production, multi-instance

Pass a storage instance to whichever plugin needs persistence:

storage = LocalFileStorage()
agent = Agent(plugins=[
ContextOffloader(storage=storage)
])

Data lives in process memory. No constructor arguments. Fast, zero-config, gone when the process exits.

storage = InMemoryStorage()

Each key becomes a file under a base directory. Writes are atomic (temp file + rename).

ParameterDefaultDescription
base_dirbaseDir"./.strands/"Root directory
sandboxsandboxNone/undefinedOptional Sandbox
storage = LocalFileStorage("./my-data/")

You can also bind a sandbox after construction with for_sandbox(sandbox)forSandbox(sandbox), which returns a new instance routed through the sandbox.

Stores data as objects in an S3 bucket. The AWS SDK loads lazily, so applications that never construct an S3Storage pay nothing.

ParameterDefaultDescription
bucket(required)S3 bucket name
prefix""Key prefix (namespace within the bucket)
region_nameregionNone/undefinedAWS region override
boto_sessions3ClientNone/undefinedPre-configured client
storage = S3Storage("my-bucket", prefix="agents/prod/")

You cannot pass both a region and a pre-configured client; pick one or the other.

Implement four async methods (write, read, delete, listwrite, read, delete, list) and pass your class anywhere a Storage is accepted. In Python, Storage is a protocol; in TypeScript, implement the interface.

Community backends can add methods beyond the core four (e.g. search for vector similarity, or structured queries for databases like DynamoDB). Plugins that only need basic persistence use the four standard methods; plugins that need richer access can check for and use the extra surface your backend provides.

Plugins scope their own keys automatically, so you don’t need to worry about collisions between session data and offloaded content.