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
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):
| Characteristic | EXECUTE_PRE (Before-Execution) | EXECUTE_POST (Post-Execution) | ROLLBACK (Compensation Gate) |
|---|---|---|---|
| Trigger Source | Declared in SDK: wrap({ requiresApproval: [...] }) | Organization Policies or Outcome Verifier drift | Inverse compensation for high-risk operations |
| Execution Timing | Pauses BEFORE external API call executes | Executes locally; flagged for reviewer verification | Pauses during LIFO unwinding before inverse call |
| Reviewer: Approved | Action becomes CLEARED; SDK executes call locally | Action verified and marked approved in audit trail | Undo marked IN_PROGRESS and executed |
| Reviewer: Rejected | Session initiates full LIFO rollback | Triggers targeted single-action rollback (rollbackAction) | Undo marked DECLINED; original mutation kept by intent |
| Sweeper Timeout | ApprovalTimeoutError thrown; full rollback | Marked REJECTED with resolutionReason TIMEOUT | Marked DECLINED with resolutionReason TIMEOUT |
Configuring Approvals in the SDK
Configuring before-execution approvals in TypeScript with explicit error handling:
1 import { AgentRein, ApprovalRejectedError, ApprovalTimeoutError } from 'agentrein' 2 import Stripe from 'stripe' 3
4 const agentrein = new AgentRein({ apiKey: process.env.AGENTREIN_API_KEY! }) 5 const session = await agentrein.newSession({ agentId: 'procurement-agent' }) 6
7 const 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
14 try { 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.
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.