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.
2
3This example demonstrates how a team pauses when a member agent's tool
4requires human confirmation in streaming mode. After confirmation the team
5resumes with continue_run().
6
7Note: When streaming with member agents, use isinstance() with TeamRunPausedEvent
8to distinguish the team's pause from member agent pauses.
9"""
10
11from kern.agent import Agent
12from kern.db.sqlite import SqliteDb
13from kern.models.openai import OpenAIResponses
14from kern.run.team import RunPausedEvent as TeamRunPausedEvent
15from kern.team.team import Team
16from kern.tools import tool
17from kern.utils import pprint
18
19# Database is required for continue_run to work - it stores the paused run
20
21# ---------------------------------------------------------------------------
22# Setup
23# ---------------------------------------------------------------------------
24db = SqliteDb(db_file="tmp/team_hitl_stream.db")
25
26
27# ---------------------------------------------------------------------------
28# Tools
29# ---------------------------------------------------------------------------
30@tool(requires_confirmation=True)
31def deploy_to_production(app_name: str, version: str) -> str:
32 """Deploy an application to production.
33
34 Args:
35 app_name (str): Name of the application
36 version (str): Version to deploy
37 """
38 return f"Successfully deployed {app_name} v{version} to production"
39
40
41# ---------------------------------------------------------------------------
42# Create Members
43# ---------------------------------------------------------------------------
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)
51
52
53# ---------------------------------------------------------------------------
54# Create Team
55# ---------------------------------------------------------------------------
56team = Team(
57 name="DevOps Team",
58 members=[deploy_agent],
59 model=OpenAIResponses(id="gpt-5.2-mini"),
60 db=db,
61)
62
63
64# ---------------------------------------------------------------------------
65# Run Team
66# ---------------------------------------------------------------------------
67if __name__ == "__main__":
68 for run_event in team.run(
69 "Deploy the payments app version 2.1 to production", stream=True
70 ):
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()
79
80 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 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 confirmation_required_stream.py