Skip to main content
Autonomous agents can take irreversible real-world actions: send emails, delete database records, make payments, execute code, post to social media, grant permissions. Unlike a model that produces text, an agent that calls a tool has side effects in the world. A poorly-aligned response can be corrected in the next turn. A sent wire transfer cannot. A human-in-the-loop (HITL) gate is the last line of defence between an AI agent and an irreversible action. This reference architecture describes how to build one using Cognisafe’s webhook system and your existing approval tooling.

Two variants

This pattern has two variants with different trade-offs: For truly irreversible actions, use Variant 1. For actions that can be unwound or that are lower stakes, Variant 2 is sufficient and imposes no user-visible latency.

Variant 1: Pre-execution gate

How it works

Framework requirements

Variant 1 requires the agent framework to support intercepting tool calls before execution. This works with:
  • LangGraph — add a conditional edge before the tool node that routes to an approval subgraph
  • Semantic Kernel — implement a FunctionInvocationFilter middleware
  • Custom MCP server — wrap dangerous tool handlers in the approval gate
  • LangChain custom tools — override _run / _arun with the gate wrapper
It does not work with frameworks where tool execution is entirely managed by the LLM provider (e.g., OpenAI Assistants with hosted tools). In those cases, use Variant 2 for monitoring and redesign the agent to use a self-hosted tool server.

Approval-gating wrapper

Never auto-approve on timeout. The fail-safe must be rejection. An agent that can time out into execution has no gate — it just has a delay. If the approval SLA cannot be met, consider whether the action is suitable for automation at all.

LangGraph integration


Slack approval bot

The simplest approval service for many teams is a Slack bot with Approve/Reject buttons. This avoids deploying a separate service and integrates with where engineers already work.

Variant 2: Post-detection review

When pre-execution gating is not feasible, configure Cognisafe to detect and alert on high-risk tool calls after they complete. This creates an audit trail and informs future policy even if it does not block the action.

Configure the custom scorer

Webhook receiver: post-detection review ticket


High-risk tool classification

Not all tools need HITL. Apply the gate selectively to preserve agent velocity for low-risk operations. Classify tools by the reversibility of their side effects and the blast radius of a mistake.
Start with a conservative list and expand it. It is better to gate too many tools initially and relax the list based on analyst feedback than to discover after an incident that a tool was unguarded. Review the high-risk tool list quarterly with the AI system owners and the security team.

Custom scorer for dangerous tool detection


Compliance value

OWASP LLM06 — Excessive Agency

HITL is the primary control for LLM06. The OWASP guidance states: “Limit the permissions of LLM-integrated systems and implement human-in-the-loop controls for actions that are irreversible or have significant impact.” Document the approval gate as the LLM06 control in your security posture assessment.

EU AI Act Article 14 — Human Oversight

For AI systems classified as “high-risk” under the EU AI Act (Annex III), Article 14 requires that natural persons are able to “oversee the functioning” of the AI system and “intervene or interrupt” it. A pre-execution HITL gate satisfies this requirement for the specific actions it covers. Document each tool category in your AI Act technical documentation.

SOC 2 CC6.1 — Logical Access Controls

The approval service functions as a logical access control: the AI agent cannot execute a privileged action without an authorised human granting access for that specific invocation. Include the HITL gate in your CC6.1 control evidence:
“High-risk tool calls made by AI agents require approval from an authorised human operator before execution. Approvals are logged in the Cognisafe audit trail with the approver identity, timestamp, and decision. The approval gate is implemented as a synchronous block in the agent tool wrapper and defaults to rejection on timeout.”

Operational considerations

Latency

HITL adds human response time. An approval workflow that requires a human to click Approve adds seconds to minutes to hours of latency to the agent task. Design agent tasks accordingly:
  • Set agent timeout longer than your approval SLA: if your Slack approval SLA is 5 minutes, set the agent task timeout to 10 minutes
  • Inform end users that high-risk actions are queued for human review: “I need to transfer funds — this action is pending approval and will complete within 5 minutes”
  • Define a business-hours policy: if approvals are only reviewed during working hours, agents should not initiate high-risk actions outside those hours unless there is an on-call roster

Approval fatigue

If the approval queue receives too many requests, approvers start rubber-stamping without reviewing. Counter this by:
  1. Calibrating the high-risk tool list — do not gate low-stakes operations
  2. Providing maximum context in the approval message so the review takes 30 seconds, not 5 minutes
  3. Setting a volume alert: if more than 10 approvals are pending simultaneously, something is wrong with the agent

Failure mode: approval service unavailable

If the approval service is unavailable, the gate wrapper will raise an exception when it cannot submit the request. The agent will receive a tool error and should surface this to the user. This is the correct behaviour — unavailability of the approval service must not result in ungated execution. Design the gate wrapper to fail closed.