Team Tool with User Input

Demonstrates collecting required user input during paused team tool execution.

1"""
2User Input Required
3=============================
4
5Demonstrates collecting required user input during paused team tool execution.
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_user_input_sessions", db_file="tmp/team_hitl.db")
23
24
25@tool(requires_user_input=True, user_input_fields=["destination", "budget"])
26def plan_trip(destination: str = "", budget: str = "") -> str:
27 """Plan a trip based on user preferences."""
28 return (
29 f"Trip planned to {destination} with a budget of {budget}. "
30 "Includes flights, hotel, and activities."
31 )
32
33
34# ---------------------------------------------------------------------------
35# Create Members
36# ---------------------------------------------------------------------------
37travel_agent = Agent(
38 name="TravelAgent",
39 model=OpenAIResponses(id="gpt-5.2-mini"),
40 tools=[plan_trip],
41 db=db,
42 telemetry=False,
43)
44
45# ---------------------------------------------------------------------------
46# Create Team
47# ---------------------------------------------------------------------------
48team = Team(
49 name="TravelTeam",
50 model=OpenAIResponses(id="gpt-5.2-mini"),
51 members=[travel_agent],
52 db=db,
53 telemetry=False,
54 add_history_to_context=True,
55)
56
57# ---------------------------------------------------------------------------
58# Run Team
59# ---------------------------------------------------------------------------
60if __name__ == "__main__":
61 session_id = "team_travel_session"
62 run_response = team.run("Help me plan a vacation", session_id=session_id)
63
64 if run_response.is_paused:
65 console.print("[bold yellow]Team is paused - user input needed[/]")
66
67 for requirement in run_response.active_requirements:
68 if requirement.needs_user_input:
69 console.print(
70 f"Member [bold cyan]{requirement.member_agent_name}[/] needs input for "
71 f"[bold blue]{requirement.tool_execution.tool_name}[/]"
72 )
73
74 values = {}
75 for field in requirement.user_input_schema or []:
76 values[field.name] = Prompt.ask(
77 f" {field.name}", default=field.value or ""
78 )
79 requirement.provide_user_input(values)
80
81 run_response = team.continue_run(run_response)
82
83 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 user_input_required.py