Confirmation Toolkit
Human-in-the-Loop: Adding User Confirmation to Tool Calls.
1"""2Confirmation Toolkit3=============================45Human-in-the-Loop: Adding User Confirmation to Tool Calls.6"""78from kern.agent import Agent9from kern.db.sqlite import SqliteDb10from kern.models.openai import OpenAIResponses11from kern.tools.websearch import WebSearchTools12from kern.utils import pprint13from rich.console import Console14from rich.prompt import Prompt1516console = Console()1718# ---------------------------------------------------------------------------19# Create Agent20# ---------------------------------------------------------------------------21agent = Agent(22 model=OpenAIResponses(id="gpt-5-mini"),23 tools=[WebSearchTools(requires_confirmation_tools=["web_search"])],24 markdown=True,25 db=SqliteDb(db_file="tmp/confirmation_required_toolkit.db"),26)2728# ---------------------------------------------------------------------------29# Run Agent30# ---------------------------------------------------------------------------31if __name__ == "__main__":32 run_response = agent.run("What is the current stock price of Apple?")33 if run_response.is_paused: # Or agent.run_response.is_paused34 for requirement in run_response.active_requirements:35 if requirement.needs_confirmation:36 # Ask for confirmation37 console.print(38 f"Tool name [bold blue]{requirement.tool_execution.tool_name}({requirement.tool_execution.tool_args})[/] requires confirmation."39 )40 message = (41 Prompt.ask(42 "Do you want to continue?", choices=["y", "n"], default="y"43 )44 .strip()45 .lower()46 )4748 if message == "n":49 requirement.reject()50 else:51 requirement.confirm()5253 run_response = agent.continue_run(54 run_id=run_response.run_id,55 requirements=run_response.requirements,56 )57 pprint.pprint_run_response(run_response)Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/10_human_in_the_loop45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python confirmation_toolkit.py