Streaming: Reject Member Tool Call.
Handle rejection of a tool call by member agent in streaming mode.
This example demonstrates how the team handles rejection of a tool call in streaming mode. After rejection, the team continues and the model responds acknowledging the rejection.
1"""Team HITL Streaming: Rejecting a member agent tool call.23This example demonstrates how the team handles rejection of a tool4call in streaming mode. After rejection, the team continues and the5model responds acknowledging the rejection.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_confirmation=True)29def delete_user_account(username: str) -> str:30 """Permanently delete a user account and all associated data.3132 Args:33 username (str): Username of the account to delete34 """35 return f"Account {username} has been permanently deleted"363738# ---------------------------------------------------------------------------39# Create Members40# ---------------------------------------------------------------------------41admin_agent = Agent(42 name="Admin Agent",43 role="Handles account administration tasks",44 model=OpenAIResponses(id="gpt-5.2-mini"),45 tools=[delete_user_account],46 db=db,47)484950# ---------------------------------------------------------------------------51# Create Team52# ---------------------------------------------------------------------------53team = Team(54 name="Admin Team",55 members=[admin_agent],56 model=OpenAIResponses(id="gpt-5.2-mini"),57 db=db,58)596061# ---------------------------------------------------------------------------62# Run Team63# ---------------------------------------------------------------------------64if __name__ == "__main__":65 for run_event in team.run("Delete the account for user 'jsmith'", stream=True):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}")7374 # Reject the dangerous operation75 req.reject(note="Account deletion requires manager approval first")7677 response = team.continue_run(78 run_id=run_event.run_id,79 session_id=run_event.session_id,80 requirements=run_event.requirements,81 stream=True,82 )83 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_rejected_stream.py