Confirmation Required with Toolkit
This example demonstrates human-in-the-loop functionality using toolkit-based tools that require confirmation. It shows how to handle user confirmation when working with pre-built tool collections like YFinanceTools.
Create a Python file
1from kern.agent import Agent2from kern.db.sqlite import SqliteDb3from kern.models.openai import OpenAIResponses4from kern.tools.yfinance import YFinanceTools5from kern.utils import pprint6from rich.console import Console7from rich.prompt import Prompt89console = Console()1011agent = Agent(12 model=OpenAIResponses(id="gpt-5.2"),13 tools=[YFinanceTools(requires_confirmation_tools=["get_stock_price"])],14 markdown=True,15 db=SqliteDb(db_file="tmp/example.db"),16)1718run_response = agent.run("What is the current stock price of Apple?")19if run_response.is_paused: # Or agent.run_response.is_paused20 for requirement in run_response.active_requirements:21 if requirement.needs_confirmation:22 # Ask for confirmation23 console.print(24 f"Tool name [bold blue]{requirement.tool_execution.tool_name}({requirement.tool_execution.tool_args})[/] requires confirmation."25 )26 message = (27 Prompt.ask("Do you want to continue?", choices=["y", "n"], default="y")28 .strip()29 .lower()30 )3132 if message == "n":33 requirement.reject()34 else:35 requirement.confirm()3637 run_response = agent.continue_run(38 run_id=run_response.run_id,39 requirements=run_response.requirements,40 )41 pprint.pprint_run_response(run_response)Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai openai yfinance richExport your OpenAI API key
1export OPENAI_API_KEY="your_openai_api_key_here"1$Env:OPENAI_API_KEY="your_openai_api_key_here"Run Agent
1python confirmation_required_toolkit.py