Skip to main content
With an empty cache, the first model call uses the provider and writes the response to disk. A later call with the same cache key returns the stored ModelResponse without contacting the provider. Install the OpenAI integration and set OPENAI_API_KEY before running the examples:
Response caching stores the complete model response locally. Context caching is a provider feature that reuses prompt prefixes while still making a model request.

Cache Key

Agno creates an MD5 cache key from these values: The key does not include the model provider or class, generation settings, message media, tool_choice, tool_call_limit, or tool definitions. Different non-empty tool lists therefore produce the same tool portion of the key. Two schema classes with the same __name__ also produce the same output-format portion.
Keep tools and model settings fixed while reusing a cache directory. A cache hit returns the stored response before tool execution, so tools are not called again. Disable response caching for tool calls with side effects. Use separate cache_dir values to isolate model instances that share an ID.
A cache hit does not reconstruct assistant or tool messages in the model’s working message list. The cached content is returned, but later runs that depend on session history may not see that cached turn. Use response caching for isolated development requests and fixtures, not conversational history.

Configuration

The default directory is shared by model instances and persists across process restarts. Each entry is a JSON file containing a timestamp and the serialized response. Writes use ordinary JSON files without a locking or transactional storage layer. Do not share a writable cache directory across concurrent processes when cache integrity matters. TTL is checked when an entry is read. An expired entry is treated as a cache miss, but its file is not deleted automatically. A successful request for the same key overwrites it with a new timestamp and response.

Agents and Teams

Response caching belongs to each model. Configure it on an agent’s model, a team’s leader model, or a member agent’s model. Use separate directories when team models need isolated caches:

Streaming

Streaming and non-streaming calls use different cache keys. For a completed stream, Agno stores the provider response chunks and replays them in order on a cache hit. Cache hits do not emit the ModelRequestStarted or ModelRequestCompleted lifecycle events. The stream must run to completion before Agno writes the entry. Stopping iteration early or encountering an error leaves that stream uncached.

When to Use Response Caching

Developer Resources