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.
from praisonaiagents import Agent

agent = Agent(
    instructions="You are a helpful assistant",
    llm="openai/gpt-4o",
    memory=True,
)

agent.start("Summarise the latest report")
# Turn 2+ reuses cached system prompt + memory prefix
agent.start("What changed since yesterday?")
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:
from praisonaiagents import Agent

agent = Agent(
    instructions="You are a helpful assistant",
    llm="openai/gpt-4o",
    memory=True,
)

agent.start("Summarise the latest report")
2

With Configuration

Make prompt caching explicit:
from praisonaiagents import Agent, CachingConfig

agent = Agent(
    instructions="You are a helpful assistant",
    llm="anthropic/claude-sonnet-4-20250514",
    memory=True,
    caching=CachingConfig(prompt_caching=True),
)

agent.start("Analyse the data trends")

How It Works

BehaviourWhat it does
Deterministic tool orderTools sorted by function name — reordering tools does not break cache
Stable memory prefixMemory sections in fixed order via build_cache_optimized_context()
Cache boundary markerSplits stable prefix from variable user turn
Check model support:
from praisonaiagents.llm.model_capabilities import supports_prompt_caching

supports_prompt_caching("openai/gpt-4o")  # True
supports_prompt_caching("ollama/llama3")  # False

Configuration Options

OptionTypeDefaultDescription
enabledboolTrueResponse caching
prompt_cachingOptional[bool]NoneProvider prompt-cache hints (Anthropic manual, OpenAI automatic when eligible)
Set via Agent(caching=True) or Agent(caching=CachingConfig(...)).

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