Streaming: Confirm Member Agent Tool
This example demonstrates how a team pauses when a member agent's tool requires human confirmation in streaming mode.
This example demonstrates how a team pauses when a member agent's tool requires human confirmation in streaming mode. After confirmation the team resumes with continue_run().
1"""Team HITL Streaming: Member agent tool requiring confirmation.23This example demonstrates how a team pauses when a member agent's tool4requires human confirmation in streaming mode. After confirmation the team5resumes with continue_run().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# Database is required for continue_run to work - it stores the paused run2021# ---------------------------------------------------------------------------22# Setup23# ---------------------------------------------------------------------------24db = SqliteDb(db_file="tmp/team_hitl_stream.db")252627# ---------------------------------------------------------------------------28# Tools29# ---------------------------------------------------------------------------30@tool(requires_confirmation=True)31def deploy_to_production(app_name: str, version: str) -> str:32 """Deploy an application to production.3334 Args:35 app_name (str): Name of the application36 version (str): Version to deploy37 """38 return f"Successfully deployed {app_name} v{version} to production"394041# ---------------------------------------------------------------------------42# Create Members43# ---------------------------------------------------------------------------44deploy_agent = Agent(45 name="Deploy Agent",46 role="Handles deployments to production",47 model=OpenAIResponses(id="gpt-5.2-mini"),48 tools=[deploy_to_production],49 db=db,50)515253# ---------------------------------------------------------------------------54# Create Team55# ---------------------------------------------------------------------------56team = Team(57 name="DevOps Team",58 members=[deploy_agent],59 model=OpenAIResponses(id="gpt-5.2-mini"),60 db=db,61)626364# ---------------------------------------------------------------------------65# Run Team66# ---------------------------------------------------------------------------67if __name__ == "__main__":68 for run_event in team.run(69 "Deploy the payments app version 2.1 to production", stream=True70 ):71 # Use isinstance to check for team's pause event (not the member agent's)72 if isinstance(run_event, TeamRunPausedEvent):73 print("Team paused - requires confirmation")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 confirmation_required_stream.py