Tool Call Limit
This cookbook shows how to use tool call limit to control the number of tool calls an agent can make.
1"""2Tool Call Limit3=============================45This cookbook shows how to use tool call limit to control the number of tool calls an agent can make.6"""78from kern.agent import Agent9from kern.models.openai import OpenAIResponses10from kern.tools.yfinance import YFinanceTools1112# ---------------------------------------------------------------------------13# Create Agent14# ---------------------------------------------------------------------------15agent = Agent(16 model=OpenAIResponses(id="gpt-5-mini"),17 tools=[YFinanceTools()],18 tool_call_limit=1,19)2021# ---------------------------------------------------------------------------22# Run Agent23# ---------------------------------------------------------------------------24if __name__ == "__main__":25 # It should only call the first tool and fail to call the second tool.26 agent.print_response(27 "Find me the current price of TSLA, then after that find me the latest news about Tesla.",28 stream=True,29 )Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/04_tools45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python tool_call_limit.py