Skip to main content

Overview

Human-in-the-loop (HITL) means requiring human approval before agents perform certain actions. This is critical for:
  • High-stakes operations: Deleting data, making purchases, sending communications
  • Compliance requirements: Regulated industries requiring human oversight
  • Safety guardrails: Preventing unintended consequences in production
  • Gradual trust building: Starting with oversight, removing it as confidence grows
The key insight with the Agentica SDK is that you don’t need special framework features for HITL. It’s just wrapping the functions you pass to agents with approval logic. The Agentica SDK makes this trivial because agents just use regular functions — wrap those functions, and you have human oversight.
What’s in this guide:

The Core Pattern

Instead of passing a function directly to an agent, wrap it with approval logic:
No middleware, no special API, no framework hooks. Just wrap the function you’re passing.
The agent sees the approval prompt as part of the function’s behavior. If you deny the action, the agent receives an exception and can adapt accordingly.

Decision Types

When reviewing an action, you have three typical options:
Modify the agent’s proposed arguments before executing. This is useful when the action is almost right but needs adjustment:
Deny the action but provide feedback that helps the agent understand why and try a different approach:
When you raise an exception with a descriptive message, the agent sees that message and can adjust its strategy. For example, if you reject a query because “must use READ ONLY transaction,” the agent might then add that to its next attempt.

Approval Mechanisms

How you ask for approval depends on your application context. Here are practical patterns:
Perfect for development, scripts, and command-line tools:
For web applications running in the browser:
For production systems with approval workflows, you may want approvals to go through a proper web interface where managers can review requests, see context, and make informed decisions. This is especially useful when:
  • The person approving isn’t at their terminal
  • You need a record of who approved what and when
  • Multiple people might need to approve the same action
  • You want to batch approval requests for review
The pattern: create an approval request via HTTP, poll until approved/denied, then proceed or raise an error.
See the Customer Support example below for a complete production implementation using this pattern.
Request approval via chat platforms where your team already is:
Only require approval for high-risk operations:

Practical Examples

An agent that can deploy code, but requires approval for production:
Agent handles support tickets but requires approval for refunds:
Agent can query data freely, but needs approval for modifications:

Advanced Patterns

When an agent wants to perform multiple actions at once, you can collect them all, review them together, then decide on each one.How it works:
  1. When the agent calls a wrapped function, instead of executing immediately, the call is queued and a placeholder like "PENDING_APPROVAL_1" is returned to the agent
  2. The agent continues executing and may queue multiple actions
  3. After the agent finishes, you call review_and_execute() to see all pending actions at once
  4. You can approve all, deny all, or handle each individually
  5. The actual functions execute based on your decisions
This pattern is useful when you want to see the full scope of what the agent plans to do before committing to any individual action.
Key insight: By providing wait_for_approvals() to the agent, the agent can:
  1. Queue up actions (getting placeholders back like "PENDING_APPROVAL_1")
  2. Call wait_for_approvals() to block until human review
  3. Receive a dict mapping action IDs to actual results: {1: "Deleted user 123", 2: "REJECTED: ..."}
  4. Adapt based on what was approved vs rejected
The agent can check results like: if "REJECTED" in results[1] to handle denied actions differently.Alternative: If you don’t give the agent wait_for_approvals(), it will receive placeholders and complete without knowing the real outcomes. Useful when the agent doesn’t need to adapt based on approval decisions.You can customize this pattern however you want: web UI for review, role-based approvals, risk-level grouping, timeouts — just code it.
Example: Agent adapts based on approval results
Allow a certain number of operations without approval, then require oversight:
Require approval during business hours, allow automation off-hours:
Log all approval decisions for compliance:

Why This Approach Works

Key insight: Agentica SDK agents call real functions, not schema definitions. This means HITL is just wrapping functions — no special framework features needed.
Traditional agent frameworks require special middleware or plugins for human-in-the-loop because they treat tools as schema definitions, not actual code. You configure tools through JSON or decorators, and the framework manages execution. The Agentica SDK is different: agents call real functions. When you pass delete_file to an agent, the agent literally calls your delete_file function through RPC via Warp. There’s no schema layer, no tool registry, no execution middleware. This means:
  • You control execution — wrap functions however you want
  • Use any approval mechanism — terminal, web, Slack, custom systems
  • Standard programming patterns — decorators, higher-order functions, classes
  • No framework lock-in — approval logic is in your code, not the framework
You don’t need the Agentica SDK to provide HITL because you already have everything you need: functions and control flow.

Best Practices

When denying an action, raise an exception with a clear message. The agent sees this and can adapt:
The agent might then try an alternative approach based on the error message.
Not everything needs the same oversight:
  • Low risk: Auto-approve, just log
  • Medium risk: CLI approval for development
  • High risk: Dashboard with multiple approvers
  • Critical: Require manager approval + audit trail
Use environment variables to control approval requirements:
Don’t wait forever for approval:

Next Steps

Best Practices

Production-ready patterns and security

Multi-Agent Systems

Apply HITL in multi-agent workflows

Error Handling

Handle approval denials and failures

Examples

Explore examples & get inspired