Streaming: Confirm Team Tool
This example demonstrates HITL for tools provided directly to the Team (not to member agents) in streaming mode.
This example demonstrates HITL for tools provided directly to the Team (not to member agents) in streaming mode. When the team leader decides to use a tool that requires confirmation, the entire team run pauses until the human confirms.
1"""Team HITL Streaming: Tool on the team itself requiring confirmation.23This example demonstrates HITL for tools provided directly to the Team4(not to member agents) in streaming mode. When the team leader decides5to use a tool that requires confirmation, the entire team run pauses6until the human confirms.78Note: For team-level tools (not member agent tools), you can use either9isinstance(event, TeamRunPausedEvent) or event.is_paused since there's10no member agent pause to confuse it with.11"""1213from kern.agent import Agent14from kern.db.sqlite import SqliteDb15from kern.models.openai import OpenAIResponses16from kern.run.team import RunPausedEvent as TeamRunPausedEvent17from kern.team.team import Team18from kern.tools import tool19from kern.utils import pprint2021# ---------------------------------------------------------------------------22# Setup23# ---------------------------------------------------------------------------24db = SqliteDb(db_file="tmp/team_hitl_stream.db")252627# ---------------------------------------------------------------------------28# Tools29# ---------------------------------------------------------------------------30@tool(requires_confirmation=True)31def approve_deployment(environment: str, service: str) -> str:32 """Approve and execute a deployment to an environment.3334 Args:35 environment (str): Target environment (staging, production)36 service (str): Service to deploy37 """38 return f"Deployment of {service} to {environment} approved and executed"394041# ---------------------------------------------------------------------------42# Create Members43# ---------------------------------------------------------------------------44research_agent = Agent(45 name="Research Agent",46 role="Researches deployment readiness",47 model=OpenAIResponses(id="gpt-5.2-mini"),48 db=db,49)505152# ---------------------------------------------------------------------------53# Create Team54# ---------------------------------------------------------------------------55team = Team(56 name="Release Team",57 members=[research_agent],58 model=OpenAIResponses(id="gpt-5.2-mini"),59 tools=[approve_deployment],60 db=db,61)626364# ---------------------------------------------------------------------------65# Run Team66# ---------------------------------------------------------------------------67if __name__ == "__main__":68 for run_event in team.run(69 "Check if the auth service is ready and deploy it to staging", stream=True70 ):71 # Use isinstance to check for team's pause event72 if isinstance(run_event, TeamRunPausedEvent):73 print("Team paused - requires confirmation for team-level tool")74 for req in run_event.active_requirements:75 if req.needs_confirmation:76 print(f" Tool: {req.tool_execution.tool_name}")77 print(f" Args: {req.tool_execution.tool_args}")78 req.confirm()7980 response = team.continue_run(81 run_id=run_event.run_id,82 session_id=run_event.session_id,83 requirements=run_event.requirements,84 stream=True,85 )86 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 team_tool_confirmation_stream.py