Cache Team Response
Cache team leader and member responses in two layers.
Demonstrates two-layer caching for team leader and member responses.
"""
Cache Team Response
=============================
Demonstrates two-layer caching for team leader and member responses.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.team import Team
# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
researcher = Agent(
name="Researcher",
role="Research and gather information",
model=OpenAIResponses(id="gpt-5.2", cache_response=True),
)
writer = Agent(
name="Writer",
role="Write clear and engaging content",
model=OpenAIResponses(id="gpt-5.2", cache_response=True),
)
# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
content_team = Team(
members=[researcher, writer],
model=OpenAIResponses(id="gpt-5.2", cache_response=True),
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
content_team.print_response(
"Write a very very very explanation of caching in software"
)Cache scope
Each cache_response=True setting caches that model's responses on disk; this is not a cache of the whole Team run. The default directory is ~/.agno/cache/model_responses, with no time-based expiry unless cache_ttl is set. This script makes one team call. Repeat an identical model request to observe a hit; changed messages or generated tool results can prevent reuse.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as caching.py, then run:
python caching.pyFull source: cookbook/03_teams/01_quickstart/09_caching.py