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.
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
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.