How It Works
Quick Start
How It Works
| Behaviour | What it does |
|---|---|
| Deterministic tool order | Tools sorted by function name — reordering tools does not break cache |
| Stable memory prefix | Memory sections in fixed order via build_cache_optimized_context() |
| Cache boundary marker | Splits stable prefix from variable user turn |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled | bool | True | Response caching |
prompt_caching | Optional[bool] | None | Provider prompt-cache hints (Anthropic manual, OpenAI automatic when eligible) |
Agent(caching=True) or Agent(caching=CachingConfig(...)).
Best Practices
Use supported models
Use supported models
OpenAI, Anthropic, Bedrock, and Deepseek support caching — local models like Ollama do not.
Keep instructions stable
Keep instructions stable
Changing system prompts between turns breaks the cached prefix.
Enable memory for full optimisation
Enable memory for full optimisation
Without memory, only tool sorting applies —
memory=True activates the cache-optimised context path.Let the SDK sort tools
Let the SDK sort tools
Do not manually reorder tool lists — the SDK sorts deterministically by name.
Related
Prompt Caching
Deterministic memory ordering for cache hits
Prompt Caching CLI
Enable caching from the command line

