Cache Tool Calls

Cache YFinance tool results with cache_results=True to skip repeat API calls.

cache_tool_calls.py
"""
Cache Tool Calls
=============================

Demonstrates cache tool calls.
"""

import asyncio

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.websearch import WebSearchTools
from agno.tools.yfinance import YFinanceTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


agent = Agent(
    model=OpenAIChat(id="gpt-5.6-luna"),
    tools=[WebSearchTools(), YFinanceTools(cache_results=True)],
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    asyncio.run(
        agent.aprint_response(
            "What is the current stock price of AAPL and latest news on 'Apple'?",
            markdown=True,
        )
    )

Only the YFinance current-price tool is cached here; web search and model calls still run. Cached results are stored under the system temporary directory’s agno_cache folder by default, with a 3,600-second TTL. A repeated call with the same arguments may therefore return a quote up to an hour old. Set a shorter cache_ttl or disable caching when fresh prices are required. The single run shown does not itself demonstrate a cache hit.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno ddgs openai yfinance

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as cache_tool_calls.py, then run:

python cache_tool_calls.py

Full source: cookbook/91_tools/other/cache_tool_calls.py