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
wrap() detects the method path is in `requiresApproval`
Logs the action as `PENDING_APPROVAL` to the backend (awaited)
SDK polls `GET /approvals/:id` at `pollIntervalMs`
A reviewer approves or rejects from the dashboard
Approved → method executes → action updated to `SUCCESS`
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 called | Path to match |
|---|
agentStripe.subscriptions.cancel(...) | 'subscriptions.cancel' |
agentStripe.invoices.del(...) | 'invoices.del' |
agentStripe.customers.del(...) | 'customers.del' |