Transparent Proxy
Intercepts SDK method calls at any depth while fully preserving original TypeScript types and Python client interfaces.
LIFO Rollback Engine
Reverses multi-step production side-effects in strict Last-In-First-Out order when errors or rejections occur.
Human-in-the-Loop
Pauses or reviews sensitive actions to wait for human reviewer sign-off via dashboard or API.
1. The Transparent Recursive Proxy (wrap())
At the core of AgentRein is the wrap() method. Instead of forcing developers to adopt custom client wrappers or new syntax, wrap() uses a JavaScript/Python proxy to intercept calls on existing SDK objects.
When you call agentrein.wrap(client, session, { connector }):
- Deep Nesting Support: Intercepts method calls regardless of property depth (e.g.,
octokit.rest.issues.createorstripe.subscriptions.cancel). - Operation Classification: Automatically maps target method names (
create,update,delete,del,post) into standardized backend operations (CREATE,UPDATE,DELETE). - Payload & Response Capture: Logs input arguments and execution responses to the backend action registry.
- Type Safety: Preserves 100% of native TypeScript type signatures and IDE autocompletion.
2. Session Lifecycle & State Machine
Every agent execution run is encapsulated within a Session. A Session groups related tool actions, tracks overall intent, and maintains execution state.Action vs. Session Status: Individual actions carry an
ActionStatus such as PENDING_APPROVAL or CLEARED while waiting for human review or execution confirmation, during which the parent Session remains ACTIVE. If a before-execution approval is rejected or expires, the action becomes FAILED and a session rollback is triggered. If an after-execution approval is rejected by a reviewer, the action stays SUCCESS and only that single action is rolled back; the session is not rolled back as a whole (if it expires, nothing is rolled back). If a rollback approval is rejected or expires, the action stays SUCCESS with its undo marked DECLINED; no rollback.Stored vs Derived Session States
The database stores raw session status (ACTIVE, COMPLETED, FAILED, ROLLED_BACK, ABANDONED). When querying sessions via API, the backend computes a dynamic displayStatus:
3. Automatic LIFO Rollback Engine
When an agent executes multi-step workflows across external services, an unexpected failure midway can leave production systems in an inconsistent state. AgentRein solves this by recording every state-modifying action in the backend Rollback Registry.How LIFO Rollback Works
- Side-Effect Tracking: Each successful action captures inverse metadata (or an
undoConfigstrategy such ashttp-deleteor connector-specific inverse calls). - Reverse Execution Order: When a session rollback runs (see triggers below), AgentRein executes inverse compensation actions in strict Last-In-First-Out (LIFO) order (e.g., Step 3 Step 2 Step 1).
- Automatic Triggering: Rollback triggers automatically when:
- An unhandled exception occurs in wrapped SDK calls or action logging fails.
- A before-execution approval request is rejected or expires.
- An approval gate is unavailable on your plan.
- An action is reported as failed.
- You call
agentrein.rollbackSession(session).
Actions marked with an
undoConfig type of none (such as immutable notifications) are logged for auditing but skipped during rollback execution.4. Human-in-the-Loop (HITL) & Approval Gates
For sensitive operations—such as canceling subscriptions, deleting databases, or deploying code—you can require explicit human approval.Pre-Execution vs Post-Execution Approvals
- Before-Execution Approval: Explicitly requested in the SDK via
wrap({ requiresApproval: ['subscriptions.cancel'] }). The SDK pauses local execution, logs the action asPENDING_APPROVAL, and pollsGET /approvals/:id. When approved, action becomesCLEARED, the SDK executes the call locally, and confirms success viaPATCH. - After-Execution Approval: Created when a standard logged action matches an organization policy with
REQUIRE_APPROVAL. The action executed locally, but the backend flags it for after-execution reviewer review. If rejected by a reviewer, single-action rollback is triggered.
5. Organization Policy Engine
Centralize governance rules across all agent teams using AgentRein’s Policy Engine. Managed via the Dashboard REST API, policies enforce runtime rules across logged actions.Policy Actions
Policy Conflict Resolution
When multiple enabled policies match an action, AgentRein evaluates them in order of strictness:6. Intent Verification & Drift Detection
AgentRein continuously evaluates whether agent actions align with their declared session goals.Outcome Statuses
When a session specifies anintent, AgentRein’s LLM engine evaluates actual execution results against that intent:
VERIFIED: The action outcome directly aligns with the stated intent.DRIFT_DETECTED: Outcome shows significant divergence from the intent.UNVERIFIED: Verification infrastructure issue prevented evaluation.
7. Resilience, Retry & Sandbox Engine
Failure Modes (open vs closed)
AgentRein allows you to configure client behavior if the AgentRein backend service becomes unreachable:
failureMode: 'open'(Default): Logs warning messages to standard output and permits tool execution to proceed without safety guarantees.failureMode: 'closed': Strictly throwsAgentReinUnavailableErrorand halts agent execution to prevent non-monitored actions.
Automated Transient Retry
Specify transiently retryable method paths using theretryable parameter: