Enabling Caching
Setcache_results=True on the @tool decorator:
Cache TTL
Control how long cached results remain valid:bool
default:"false"
Enable result caching for this tool.
int
default:"3600"
Cache time-to-live in seconds. Results older than this are re-fetched.
str
Directory to store cache files. Defaults to a system temp directory.
How It Works
- When a tool is called, the arguments are serialized to a cache key
- If a cached result exists and is within the TTL, it is returned immediately
- If no cache hit, the function executes and the result is stored
When to Use Caching
Caching works best for:- Expensive API calls — external search, database queries, web scraping
- Deterministic functions — same input always produces the same output
- Frequently repeated calls — agents that search for the same thing multiple times in a conversation