Skip to main content

Recursive Proxy

wrap() intercepts every method call no matter how deeply nested, preserving your original TypeScript types completely.

Approval Gates

Pass requiresApproval to wrap() to pause execution until a human reviewer approves from the dashboard.

Automatic Rollback

If a reviewer rejects or any action fails, AgentRein reverses every previous action in LIFO order automatically.

The Recursive Proxy

The core of AgentRein SDK’s power comes from the wrap() method. Rather than forcing you to learn a new syntax, wrap() uses a Recursive JavaScript Proxy to intercept your existing client’s actions. When you call agentrein.wrap(client, session, { connector }), it intercepts every method call, no matter how deeply nested (e.g., octokit.rest.issues.create). It tracks the action, logs it to the backend, executes the original function, and registers it for potential rollback — while completely preserving your original TypeScript types.

Approval Gates

For high-risk methods that need human sign-off, pass requiresApproval directly to wrap():
Methods not listed in requiresApproval execute immediately without interruption. Only listed paths trigger the approval gate.
const agentStripe = agentrein.wrap(stripe, session, {
    connector: 'stripe',
    requiresApproval: ['subscriptions.cancel', 'invoices.del'],
});

// Normal methods execute immediately
await agentStripe.invoices.create({ customer: 'cus_123' });

// Methods in requiresApproval pause until a reviewer approves
await agentStripe.subscriptions.cancel({ id: 'sub_123' });
If a reviewer rejects the action, ApprovalRejectedError is thrown and the session is automatically rolled back.