Human-in-the-loop (HITL) gives people a defined role in an agent’s work. A person might judge an output, provide feedback, handle a case the agent cannot resolve, or approve a consequential action before it happens. These are related but distinct controls: reviewing an answer improves evaluation; approving an action limits what the agent may do. section 7.1 section 8.4.6 section 11.2
Choose evaluation by the kind of judgment needed. Deterministic tests check outputs with known answers or schemas. LLM and agent evaluators score less exact qualities. People handle edge cases, policy concerns, tone, and real-world context that those checks may miss. For open-ended responses, define a rubric with clear criteria, then validate that its scores agree with human judgment. section 7.1 section 7.3.4
For approval checkpoints, make four decisions before deployment:
- Trigger review according to stakes—such as irreversibility, financial impact, or external visibility—not for every minor step. section 8.4.6
- Show the reviewer what the agent intends to do, why, which data it will touch, and what the user requested. section 8.4.6
- Preserve state while approval is pending; define how the work resumes, times out, or escalates. section 8.4.6
- Plan for missed or bypassed checkpoints with rate limits, caps, sandboxing, and post-hoc audit. section 8.4.6
Customer support escalation
A support agent can answer bounded questions, but route an angry customer, an unclear policy, or a large refund to a person. An `escalate_to_human` tool takes a ticket ID and reason, giving the handoff a concrete record. Customers can also provide feedback on whether their problem was addressed; that feedback supports later evaluation rather than approving an action in advance. section 11.2 section 11.1.5
Listing 11.5 06_support_agent_tips.py
from agents import Agent, function_tool, ModelSettings
@function_tool #1
def escalate_to_human(ticket_id: str, reason: str) -> str:
"""Escalate this conversation to a human. Use for angry users, large refunds, or unclear policy."""
return f"Escalated ticket {ticket_id}: {reason}" #2
retrieval_agent = Agent(... ) #3
support = Agent(
name="Triage Support Agent",
instructions=(
"Verify identity before account actions. Cite policies. "
"If unsure or user is upset, call escalate_to_human."
"Pass on complex queries to retrieval_agent." #4
),
tools=[escalate_to_human, retrieval_agent.as_tool()],
model_settings=ModelSettings(tool_choice="auto")
)
The support-agent listing shows how to expose an escalation tool and instruct the agent when to use it. section 11.2
Autonomy does not mean removing people from the workflow. An assistant may seek approval for each task; an agent may proceed toward a goal while pausing for high-stakes actions. Record human feedback alongside tests and automated evaluations so failures can be examined and changes checked. Keep other safeguards in place: a human checkpoint is one defense, not a substitute for controlled tools or validation. section 1.1.1 section 7.1 section 3.2.4
















