Streaming: Member Tool with User Input
This example demonstrates how a team pauses when a member agent's tool.
This example demonstrates how a team pauses when a member agent's tool needs additional information from the user before it can be executed in streaming mode.
1"""Team HITL Streaming: Member agent tool requiring user input.23This example demonstrates how a team pauses when a member agent's tool4needs additional information from the user before it can be executed5in streaming mode.67Note: When streaming with member agents, use isinstance() with TeamRunPausedEvent8to distinguish the team's pause from member agent pauses.9"""1011from kern.agent import Agent12from kern.db.sqlite import SqliteDb13from kern.models.openai import OpenAIResponses14from kern.run.team import RunPausedEvent as TeamRunPausedEvent15from kern.team.team import Team16from kern.tools import tool17from kern.utils import pprint1819# ---------------------------------------------------------------------------20# Setup21# ---------------------------------------------------------------------------22db = SqliteDb(db_file="tmp/team_hitl_stream.db")232425# ---------------------------------------------------------------------------26# Tools27# ---------------------------------------------------------------------------28@tool(requires_user_input=True, user_input_fields=["passenger_name"])29def book_flight(destination: str, date: str, passenger_name: str) -> str:30 """Book a flight to a destination.3132 Args:33 destination (str): The destination city34 date (str): Travel date35 passenger_name (str): Full name of the passenger36 """37 return f"Booked flight to {destination} on {date} for {passenger_name}"383940# ---------------------------------------------------------------------------41# Create Members42# ---------------------------------------------------------------------------43booking_agent = Agent(44 name="Booking Agent",45 role="Books travel arrangements",46 model=OpenAIResponses(id="gpt-5.2-mini"),47 tools=[book_flight],48 db=db,49)505152# ---------------------------------------------------------------------------53# Create Team54# ---------------------------------------------------------------------------55team = Team(56 name="Travel Team",57 members=[booking_agent],58 model=OpenAIResponses(id="gpt-5.2-mini"),59 db=db,60)616263# ---------------------------------------------------------------------------64# Run Team65# ---------------------------------------------------------------------------66if __name__ == "__main__":67 for run_event in team.run("Book a flight to Tokyo for next Friday", stream=True):68 # Use isinstance to check for team's pause event (not the member agent's)69 if isinstance(run_event, TeamRunPausedEvent):70 print("Team paused - requires user input")71 for req in run_event.active_requirements:72 if req.needs_user_input:73 print(f" Tool: {req.tool_execution.tool_name}")74 for field in req.user_input_schema or []:75 print(f" Field needed: {field.name} - {field.description}")7677 req.provide_user_input({"passenger_name": "John Smith"})7879 response = team.continue_run(80 run_id=run_event.run_id,81 session_id=run_event.session_id,82 requirements=run_event.requirements,83 stream=True,84 )85 pprint.pprint_run_response(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 user_input_required_stream.py