Getting Started

Human hand-off

Humans sometimes need to talk to an other human instead of an AI, yeah I know sounds weird right? But turns out this could be quite beneficial for customer satisfaction. Superagent enables this by offering a specific tool we call Human hand-off.

Step-by-step guide

Prerequisites: This tutorial expects you to have configured an LLM and created an Agent

  1. Create a HAND_OFF tool. This tool will make sure to trigger and ask the user if they want to speak to a human.
1tool = client.tool.create(
2 name="Human hand-off",
3 description="Useful when the user wants to speak to a human operator",
4 type="HAND_OFF"
5)
6
7# Add the tool to your agent
8client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id)
  1. Invoke the Agent to test the hand-off
1# Write a helper function that checks for human hand-off
2def check_for_human_handoff(data: list) -> bool:
3 for item, _ in data:
4 if item['tool'] == 'human-hand-off':
5 return True
6 return False
7
8prediction = client.agent.invoke(
9 agent_id=agent.data.id,
10 enable_streaming=False,
11 input="I want to speak to a human",
12 session_id="my_session_id"
13)
14
15output = prediction.data.get("output")
16steps = prediction.data.get("intermediate_steps")
17
18if check_for_human_handoff(steps):
19 # Run any local code here
20 print("HUMAN HANDOFF DETECTED")

That’s it, you can now run arbitrary code whenever the human hand-off is triggered.

Full code

1tool = client.tool.create(
2 name="Human hand-off",
3 description="Useful when the user wants to speak to a human operator",
4 type="HAND_OFF"
5)
6
7# Add the tool to your agent
8client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id)
9
10# Write a helper function that checks for human hand-off
11def check_for_human_handoff(data: list) -> bool:
12 for item, _ in data:
13 if item['tool'] == 'human-hand-off':
14 return True
15 return False
16
17prediction = client.agent.invoke(
18 agent_id=agent.data.id,
19 enable_streaming=False,
20 input="I want to speak to a human",
21 session_id="my_session_id"
22)
23
24output = prediction.data.get("output")
25steps = prediction.data.get("intermediate_steps")
26
27if check_for_human_handoff(steps):
28 # Run any local code here
29 print("HUMAN HANDOFF DETECTED")