Integrating Human Input Back to Agents
Introduction: Completing the Human-in-the-Loop Workflow
In the previous lesson, you completed Factor 6 by implementing pause and resume endpoints that give clients lifecycle control over agent workflows. Now, you'll implement Factor 7 — Contact humans with tool calls. As you learned when studying the 12-Factor Agents methodology, this factor treats human escalation as a first-class tool: when the agent lacks information, it doesn't guess or fail — it calls a structured ask_human tool, pauses itself, and waits for a response. The human's input is recorded in the context just like any other tool output, making the interaction auditable and reproducible. By the end of this lesson, you'll have a complete human-in-the-loop system where agents and users collaborate seamlessly to solve problems together.
Defining the ask_human Tool Schema
To allow the agent to request information from users, you need to create a new tool schema. The ask_human tool requires only one parameter: the question or prompt that the agent wants to present to the user. Create a new file at src/core/tools/schemas/ask_human.json with the following content:
This schema follows the same structure as your other tools, like sum_numbers or final_answer. The name field identifies the function as ask_human, while the description tells the language model when it should use this tool. The parameters section defines a single required field called question that holds the text the agent wants to show to the user. By keeping the schema simple with just one string parameter, you make it easy for the language model to formulate clear questions without worrying about complex argument structures.
Loading the ask_human Schema in the Agent
Now you need to load this schema and register it alongside your existing tools in the agent initialization. Open src/core/agent.py and modify the __init__ method to include the new schema:
The code opens the new schema file and loads it as JSON, just like it does for the math and final_answer schemas. Then, it includes ask_human_schema in the self.tool_schemas list, making the tool available to the language model during each agent step.
