Confirmation Required
Demonstrates team-level pause/continue flow for confirmation-required member tools.
1"""2Confirmation Required3=============================45Demonstrates team-level pause/continue flow for confirmation-required member tools.6"""78from kern.agent import Agent9from kern.db.sqlite import SqliteDb10from kern.models.openai import OpenAIResponses11from kern.team import Team12from kern.tools import tool13from kern.utils import pprint14from rich.console import Console15from rich.prompt import Prompt1617# ---------------------------------------------------------------------------18# Setup19# ---------------------------------------------------------------------------20console = Console()2122db = SqliteDb(session_table="team_hitl_sessions", db_file="tmp/team_hitl.db")232425@tool(requires_confirmation=True)26def get_the_weather(city: str) -> str:27 """Get the current weather for a city."""28 return f"It is currently 70 degrees and cloudy in {city}"293031# ---------------------------------------------------------------------------32# Create Members33# ---------------------------------------------------------------------------34weather_agent = Agent(35 name="WeatherAgent",36 model=OpenAIResponses(id="gpt-5.2"),37 tools=[get_the_weather],38 db=db,39 telemetry=False,40)4142# ---------------------------------------------------------------------------43# Create Team44# ---------------------------------------------------------------------------45team = Team(46 name="WeatherTeam",47 model=OpenAIResponses(id="gpt-5.2"),48 members=[weather_agent],49 db=db,50 telemetry=False,51 add_history_to_context=True,52)5354# ---------------------------------------------------------------------------55# Run Team56# ---------------------------------------------------------------------------57if __name__ == "__main__":58 session_id = "team_weather_session"59 run_response = team.run("What is the weather in Tokyo?", session_id=session_id)6061 if run_response.is_paused:62 console.print("[bold yellow]Team is paused - member needs confirmation[/]")6364 for requirement in run_response.active_requirements:65 if requirement.needs_confirmation:66 console.print(67 f"Member [bold cyan]{requirement.member_agent_name}[/] wants to call "68 f"[bold blue]{requirement.tool_execution.tool_name}"69 f"({requirement.tool_execution.tool_args})[/]"70 )7172 message = (73 Prompt.ask(74 "Do you want to approve?", choices=["y", "n"], default="y"75 )76 .strip()77 .lower()78 )7980 if message == "n":81 requirement.reject(note="User declined")82 else:83 requirement.confirm()8485 run_response = team.continue_run(run_response)8687 pprint.pprint_run_response(run_response)Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/03_teams/human_in_the_loop45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python confirmation_required.py