Skip to main content
Turn on memory on a supported model — the SDK sorts tools and lays out context so providers can cache the stable prefix.
The user chats across turns; stable prefixes stay cached for lower cost.

How It Works

Quick Start

1

Simple Usage

Automatic on supported models when memory is enabled:
2

With Configuration

Make prompt caching explicit:

How It Works

CACHE_BOUNDARY is a reserved marker constant ("--- CACHE_BOUNDARY ---") on praisonaiagents.memory.memory for future structured-cache metadata. No current provider consumes it, so it is intentionally not appended to the outgoing system prompt. Providers hit the cache because the prefix is deterministic — not because of any marker.
On OpenAI and Gemini the SDK emits no explicit cache markers. Those providers apply prefix caching automatically as long as the request prefix is byte-identical across turns. The optimisations on this page — deterministic tool order, stable memory layout, no wall-clock in the system prompt — are what make automatic caching work.
Anthropic works differently: it gets explicit cache_control breakpoints on the system block and the stable history prefix. See Prompt Caching for the Anthropic breakpoint behaviour and the provider-behaviour table.
Check model support:

Configuration Options

Set via Agent(caching=True) or Agent(caching=CachingConfig(...)). The include_cache_boundary flag on build_cache_optimized_context() controls whether the returned dict contains the marker; it does not affect what is sent on the wire.

Best Practices

OpenAI, Anthropic, Bedrock, and Deepseek support caching — local models like Ollama do not.
Changing system prompts between turns breaks the cached prefix.
Without memory, only tool sorting applies — memory=True activates the cache-optimised context path.
Do not manually reorder tool lists — the SDK sorts deterministically by name.

Prompt Caching

Deterministic memory ordering for cache hits

Prompt Caching CLI

Enable caching from the command line