Confirmation Required

Demonstrates team-level pause/continue flow for confirmation-required member tools.

1"""
2Confirmation Required
3=============================
4
5Demonstrates team-level pause/continue flow for confirmation-required member tools.
6"""
7
8from kern.agent import Agent
9from kern.db.sqlite import SqliteDb
10from kern.models.openai import OpenAIResponses
11from kern.team import Team
12from kern.tools import tool
13from kern.utils import pprint
14from rich.console import Console
15from rich.prompt import Prompt
16
17# ---------------------------------------------------------------------------
18# Setup
19# ---------------------------------------------------------------------------
20console = Console()
21
22db = SqliteDb(session_table="team_hitl_sessions", db_file="tmp/team_hitl.db")
23
24
25@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}"
29
30
31# ---------------------------------------------------------------------------
32# Create Members
33# ---------------------------------------------------------------------------
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)
41
42# ---------------------------------------------------------------------------
43# Create Team
44# ---------------------------------------------------------------------------
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)
53
54# ---------------------------------------------------------------------------
55# Run Team
56# ---------------------------------------------------------------------------
57if __name__ == "__main__":
58 session_id = "team_weather_session"
59 run_response = team.run("What is the weather in Tokyo?", session_id=session_id)
60
61 if run_response.is_paused:
62 console.print("[bold yellow]Team is paused - member needs confirmation[/]")
63
64 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 )
71
72 message = (
73 Prompt.ask(
74 "Do you want to approve?", choices=["y", "n"], default="y"
75 )
76 .strip()
77 .lower()
78 )
79
80 if message == "n":
81 requirement.reject(note="User declined")
82 else:
83 requirement.confirm()
84
85 run_response = team.continue_run(run_response)
86
87 pprint.pprint_run_response(run_response)

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/03_teams/human_in_the_loop
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python confirmation_required.py