Skip to main content

Overview

Approval gates are configured directly on wrap() via the requiresApproval option — no separate method needed.
The session is automatically rolled back when a reviewer rejects an action — no manual cleanup required.
import { AgentRein, ApprovalRejectedError } from 'agentrein';

const agentrein = new AgentRein({ apiKey: process.env.AGENTREIN_API_KEY });
const session = await agentrein.newSession({ agentId: 'billing-agent' });

const agentStripe = agentrein.wrap(stripe, session, {
    connector: 'stripe',
    requiresApproval: ['subscriptions.cancel'],
    pollIntervalMs: 2000,
    timeoutMs: 300000,
});

try {
    // This call pauses until approved from the dashboard
    await agentStripe.subscriptions.cancel({ id: 'sub_123' });
} catch (err) {
    if (err instanceof ApprovalRejectedError) {
        console.log('Rejected:', err.reason);
        // all previous session actions were already rolled back automatically
    }
}

Flow

1

wrap() detects the method path is in `requiresApproval`

2

Logs the action as `PENDING_APPROVAL` to the backend (awaited)

3

SDK polls `GET /approvals/:id` at `pollIntervalMs`

4

A reviewer approves or rejects from the dashboard

5

Approved → method executes → action updated to `SUCCESS`

6

Rejected → `ApprovalRejectedError` thrown → session auto-rolled back

requiresApproval path matching

The strings in requiresApproval match the method path after the connector prefix. For agentrein.wrap(stripe, session, { connector: 'stripe' }):
Method calledPath to match
agentStripe.subscriptions.cancel(...)'subscriptions.cancel'
agentStripe.invoices.del(...)'invoices.del'
agentStripe.customers.del(...)'customers.del'