Async Streaming: Confirm Member Agent Tool
Same as confirmation_required_stream.py but uses async run/continue_run.
1"""Team HITL Async Streaming: Member agent tool requiring confirmation.23Same as confirmation_required_stream.py but uses async run/continue_run.45Note: When streaming with member agents, use isinstance() with TeamRunPausedEvent6to distinguish the team's pause from member agent pauses.7"""89import asyncio1011from 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_confirmation=True)29def deploy_to_production(app_name: str, version: str) -> str:30 """Deploy an application to production.3132 Args:33 app_name (str): Name of the application34 version (str): Version to deploy35 """36 return f"Successfully deployed {app_name} v{version} to production"373839# ---------------------------------------------------------------------------40# Create Members41# ---------------------------------------------------------------------------42deploy_agent = Agent(43 name="Deploy Agent",44 role="Handles deployments to production",45 model=OpenAIResponses(id="gpt-5.2-mini"),46 tools=[deploy_to_production],47 db=db,48)495051# ---------------------------------------------------------------------------52# Create Team53# ---------------------------------------------------------------------------54team = Team(55 name="DevOps Team",56 members=[deploy_agent],57 model=OpenAIResponses(id="gpt-5.2-mini"),58 db=db,59)606162async def main():63 async for run_event in team.arun(64 "Deploy the payments app version 2.1 to production", stream=True65 ):66 # Use isinstance to check for team's pause event (not the member agent's)67 if isinstance(run_event, TeamRunPausedEvent):68 print("Team paused - requires confirmation")69 for req in run_event.active_requirements:70 if req.needs_confirmation:71 print(f" Tool: {req.tool_execution.tool_name}")72 print(f" Args: {req.tool_execution.tool_args}")73 req.confirm()7475 # Use apprint_run_response for async streaming76 response = team.acontinue_run(77 run_id=run_event.run_id,78 session_id=run_event.session_id,79 requirements=run_event.requirements,80 stream=True,81 )82 await pprint.apprint_run_response(response)838485# ---------------------------------------------------------------------------86# Run Team87# ---------------------------------------------------------------------------88if __name__ == "__main__":89 asyncio.run(main())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_async_stream.py