Skip to main content
Enterprise Governance•6 min read

Human-in-the-Loop Architecture: Pre-Execution vs. Post-Execution Approval Gates

The operational balance between automation and oversight: how to implement before-execution approval polling and after-execution policy reviews for sensitive agent tool calls.

AgentRein Policy & Security

AgentRein Policy & Security

Published: October 2026•Updated: October 2026

Enterprise organizations seeking to automate operations with AI agents face a governance dilemma: requiring manual approval for every single action destroys agent speed, while granting unrestricted execution access creates unacceptable operational risk. AgentRein provides a structured Human-in-the-Loop architecture separating pre-execution approvals from post-execution policy reviews.

The Balance Between Autonomy and Governance

Routine operations—such as querying customer records, reading analytics reports, or drafting notifications—should execute with zero human friction. However, high-impact operations—such as canceling subscriptions, processing financial refunds, or modifying database schemas—require explicit reviewer sign-off.

AgentRein implements two distinct approval mechanisms: Before-Execution Approval (requested directly in the SDK) and After-Execution Approval (triggered by organization policies).

Pre-Execution vs. Post-Execution Approvals

AgentRein models human governance across three distinct approval purposes (ApprovalPurpose enum in backend schema):

CharacteristicEXECUTE_PRE (Before-Execution)EXECUTE_POST (Post-Execution)ROLLBACK (Compensation Gate)
Trigger SourceDeclared in SDK: wrap({ requiresApproval: [...] })Organization Policies or Outcome Verifier driftInverse compensation for high-risk operations
Execution TimingPauses BEFORE external API call executesExecutes locally; flagged for reviewer verificationPauses during LIFO unwinding before inverse call
Reviewer: ApprovedAction becomes CLEARED; SDK executes call locallyAction verified and marked approved in audit trailUndo marked IN_PROGRESS and executed
Reviewer: RejectedSession initiates full LIFO rollbackTriggers targeted single-action rollback (rollbackAction)Undo marked DECLINED; original mutation kept by intent
Sweeper TimeoutApprovalTimeoutError thrown; full rollbackMarked REJECTED with resolutionReason TIMEOUTMarked DECLINED with resolutionReason TIMEOUT

Configuring Approvals in the SDK

Configuring before-execution approvals in TypeScript with explicit error handling:

services/billing-agent.tstypescript
1import { AgentRein, ApprovalRejectedError, ApprovalTimeoutError } from 'agentrein'
2import Stripe from 'stripe'
3
4const agentrein = new AgentRein({ apiKey: process.env.AGENTREIN_API_KEY! })
5const session = await agentrein.newSession({ agentId: 'procurement-agent' })
6
7const agentStripe = agentrein.wrap(new Stripe(process.env.STRIPE_KEY!), session, {
8 connector: 'stripe',
9 requiresApproval: ['subscriptions.cancel', 'customers.del'],
10 pollIntervalMs: 2000, // Poll every 2 seconds
11 timeoutMs: 300000, // Wait up to 5 minutes for reviewer
12})
13
14try {
15 // SDK pauses local execution and polls until approved or rejected
16 await agentStripe.subscriptions.cancel({ id: 'sub_999' })
17 console.log('Action approved and executed.')
18} catch (err) {
19 if (err instanceof ApprovalRejectedError) {
20 console.error(`Approval rejected by reviewer: ${err.reason}`)
21 // Session actions have already been automatically rolled back
22 } else if (err instanceof ApprovalTimeoutError) {
23 console.error('Approval timed out without reviewer response')
24 }
25}

Organization Policy Conflict Resolution

When multiple organization policies match a given tool call, AgentRein resolves conflicts in strict order of security precedence:

BLOCK > REQUIRE_APPROVAL > ALLOW

If any enabled policy specifies BLOCK, the action is immediately blocked with HTTP 403. Otherwise, if any policy requires approval, it is flagged for review. ALLOW applies only when no blocking or approval policies match.

Summary & Key Invariants

  • ›Before-execution approvals pause execution locally, preventing sensitive API calls until a human reviewer approves.
  • ›If a before-execution approval is rejected or expires, AgentRein automatically rolls back the entire session in LIFO order.
  • ›Organization policies enforce governance centrally across all team agents with strict precedence rules.
Tags:#Governance#Human-in-the-Loop#Policies#Approvals#Compliance
AgentRein Policy & Security

AgentRein Policy & Security

Governance & Runtime Safety

Published by the AgentRein engineering team. AgentRein provides transparent proxy instrumentation, deterministic LIFO rollbacks, runtime intent verification, and human-in-the-loop governance for AI agent fleets.