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 Agent
2from kern.db.sqlite import SqliteDb
3from kern.models.openai import OpenAIResponses
4from kern.tools.yfinance import YFinanceTools
5from kern.utils import pprint
6from rich.console import Console
7from rich.prompt import Prompt
8
9console = Console()
10
11agent = 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)
17
18run_response = agent.run("What is the current stock price of Apple?")
19if run_response.is_paused: # Or agent.run_response.is_paused
20 for requirement in run_response.active_requirements:
21 if requirement.needs_confirmation:
22 # Ask for confirmation
23 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 )
31
32 if message == "n":
33 requirement.reject()
34 else:
35 requirement.confirm()
36
37 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.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U kern-ai openai yfinance rich

Export 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