Skip to content

Manage context and caching

Two defaults keep a long conversation coherent and affordable. A model can only read so much text at once, its context window; context management keeps the conversation within that limit as it grows, and prompt caching reuses the stable parts of each request. Both are on by default and need no configuration for the common case.

With context_manager on, Strands harness keeps the relevant history in the model’s window, summarizing older turns as the conversation grows so a long task does not overflow the context. It also appends a context offloader: bulky tool results are moved to storage and replaced with a short preview and a reference the agent can follow to pull the full content back when it actually needs it.

The option takes "auto" (the default), "agentic", or off:

from strands_harness import create_harness
agent = create_harness(context_manager="agentic")

"auto" and "agentic" select the Strands Harness SDK’s context-management strategy; both keep the offloader on. Turning context management off (False/null, or off on the CLI) disables offloading too, so the full history stays in the window and you own the size of it.

When a session is active, offloaded artifacts persist under the session directory; without a session they go to a temporary directory that does not outlive the process. For the underlying mechanisms, see context management and the context offloader.

Prompt caching reuses the parts of a request that do not change between turns (the system prompt, tool definitions, and prior conversation), so the stable prefix of a long conversation is cheaper and faster to process each turn. It is on by default.

How caching reaches the provider depends on the provider:

  • On Amazon Bedrock and Anthropic direct, Strands harness configures cache points and cached tool definitions.
  • On OpenAI, Google, and bedrock-mantle, caching happens automatically server-side, so there is nothing for Strands harness to configure.

Pass caching off to disable what Strands harness configures:

from strands_harness import create_harness
agent = create_harness(caching=False)

Turning caching off has no effect where caching is automatic. Enabling caching explicitly on a pre-built Model instance is ignored with a warning, because Strands harness cannot know the instance’s provider: configure caching on the instance itself in that case. For the provider-side details, see Amazon Bedrock prompt caching.

For the full option list, see the configuration reference.