Reject Member Tool Call

Handle rejection of a tool call by a team member agent.

This example demonstrates how the team handles rejection of a tool call. After rejection, the team continues and the model responds acknowledging the rejection.

1"""Team HITL: Rejecting a member agent tool call.
2
3This example demonstrates how the team handles rejection of a tool
4call. After rejection, the team continues and the model responds
5acknowledging the rejection.
6"""
7
8from kern.agent import Agent
9from kern.models.openai import OpenAIResponses
10from kern.team.team import Team
11from kern.tools import tool
12
13
14# ---------------------------------------------------------------------------
15# Tools
16# ---------------------------------------------------------------------------
17@tool(requires_confirmation=True)
18def delete_user_account(username: str) -> str:
19 """Permanently delete a user account and all associated data.
20
21 Args:
22 username (str): Username of the account to delete
23 """
24 return f"Account {username} has been permanently deleted"
25
26
27# ---------------------------------------------------------------------------
28# Create Members
29# ---------------------------------------------------------------------------
30admin_agent = Agent(
31 name="Admin Agent",
32 role="Handles account administration tasks",
33 model=OpenAIResponses(id="gpt-5.2-mini"),
34 tools=[delete_user_account],
35)
36
37# ---------------------------------------------------------------------------
38# Create Team
39# ---------------------------------------------------------------------------
40team = Team(
41 name="Admin Team",
42 members=[admin_agent],
43 model=OpenAIResponses(id="gpt-5.2-mini"),
44)
45
46# ---------------------------------------------------------------------------
47# Run Team
48# ---------------------------------------------------------------------------
49if __name__ == "__main__":
50 response = team.run("Delete the account for user 'jsmith'")
51
52 if response.is_paused:
53 print("Team paused - requires confirmation")
54 for req in response.requirements:
55 if req.needs_confirmation:
56 print(f" Tool: {req.tool_execution.tool_name}")
57 print(f" Args: {req.tool_execution.tool_args}")
58
59 # Reject the dangerous operation
60 req.reject(note="Account deletion requires manager approval first")
61
62 response = team.continue_run(response)
63 print(f"Result: {response.content}")
64 else:
65 print(f"Result: {response.content}")

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_rejected.py