Skip to content
Changelog

Response cache tells same-named output schemas apart

October 8, 20261 min read

Agno's Model._get_model_cache_key() now turns a Pydantic response_format class into its model_json_schema(), nested field definitions included. Earlier releases used the class name, so two Output classes in different modules collided whenever the prompt matched.

With cache_response=True, the second agent got the first agent's cached JSON. We gave two agents one OpenAIChat with cache_response=True, pointed it at a mocked endpoint that answers whichever schema it receives, and asked both the same question. One output_schema was Output with a total: float field, the other Output with priority: str.

# Before (real output)
cache keys equal: True
Output(total): Output(total=42.0)
WARNING Failed to parse cleaned JSON: 1 validation error for Output
priority
  Field required [type=missing, input_value={'total': 42.0}, input_type=dict]
WARNING Failed to convert response to output_schema
Output(priority): '{"total": 42.0}'
requests sent to the provider: 1
 
# Now (real output)
cache keys equal: False
Output(total): Output(total=42.0)
Output(priority): Output(priority='high')
requests sent to the provider: 2

Classes with identical schemas still share an entry. A model with no JSON schema, such as one with a Callable field, falls back to its module and qualified name.

See the cookbook, and learn more about response caching in the documentation.

Frequently asked questions

With cache_response=True, Agno hashes the messages and request settings, and a Pydantic response_format class contributes its model_json_schema(). Two classes with identical fields still share one cache entry, whatever module they live in.

Earlier releases keyed the schema by its class name. Two agents with different Output classes and the same prompt hit the same entry, and the second agent got the first agent's JSON, which failed to parse into its own class.

A model with fields Pydantic can't describe, such as a Callable, falls back to its module and qualified class name in the key.

Shipped around the same time