Tool Result Caching

Cache tool results to reduce repeated API calls and improve performance.

Tool result caching is designed to avoid unnecessary recomputation by storing the results of function calls on disk. This is useful during development and testing to speed up the development process, avoid rate limiting, and reduce costs.

This is supported for all Kern Toolkits

On Toolkit

Pass cache_results=True to the Toolkit constructor to enable caching for that Toolkit.

1import asyncio
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.tools.hackernews import HackerNewsTools
6from kern.tools.yfinance import YFinanceTools
7
8agent = Agent(
9 model=OpenAIResponses(id="gpt-5.2"),
10 tools=[HackerNewsTools(cache_results=True), YFinanceTools(cache_results=True)],
11)
12
13asyncio.run(
14 agent.aprint_response(
15 "What is the current stock price of AAPL and top stories on HackerNews?",
16 markdown=True,
17 )
18)

On @tool

Pass cache_results=True to the @tool decorator to enable caching for that tool.

1from kern.tools import tool
2
3@tool(cache_results=True)
4def get_stock_price(ticker: str) -> str:
5 """Get the current stock price of a given ticker"""
6
7 # ... Long running operation
8
9 return f"The current stock price of {ticker} is 100"