Skip to main content

Bring Your Own Client

AgentRein’s SDK contains zero connector logic. There are no Stripe, GitHub, or Slack classes to import from agentrein. Instead, you install and initialize your own standard SDK clients as you normally would, then pass them to wrap().
import { AgentRein } from 'agentrein';
import { Octokit } from '@octokit/rest';
import { WebClient } from '@slack/web-api';
import Stripe from 'stripe';

const agentrein = new AgentRein({ apiKey: process.env.AGENTREIN_API_KEY });

// Your own clients — initialized with your own credentials
const octokit  = new Octokit({ auth: process.env.GITHUB_TOKEN });
const slack    = new WebClient(process.env.SLACK_TOKEN);
const stripe   = new Stripe(process.env.STRIPE_KEY);

const session = await agentrein.newSession({ agentId: 'my-agent', intent: '...' });

// Wrap once — use exactly as before
const agentOctokit = agentrein.wrap(octokit, session, { connector: 'github' });
const agentSlack   = agentrein.wrap(slack,   session, { connector: 'slack' });
const agentStripe  = agentrein.wrap(stripe,  session, { connector: 'stripe' });

await agentOctokit.issues.create({ owner: 'my-org', repo: 'my-repo', title: 'Task' });
await agentSlack.chat.postMessage({ channel: '#ops', text: 'Issue created' });
await agentStripe.invoices.create({ customer: 'cus_123' });

How the Proxy Works

wrap() returns a Proxy that is transparent to your code — TypeScript types, autocompletion, and runtime behavior are all preserved. When you call any method on the wrapped client:
  1. The Proxy captures the method path and arguments
  2. Your original SDK method executes normally
  3. AgentRein logs the action to the backend asynchronously (fire-and-forget)
  4. If the call throws, AgentRein triggers a LIFO rollback of all previous actions in the session

Connector Prefix

The connector string you pass to wrap() must match the prefix used in the AgentRein backend rollback registry. The supported prefixes are:
PrefixExternal SDK
github@octokit/rest
slack@slack/web-api
stripestripe
hubspotaxios (REST)
salesforceaxios (REST)
notionaxios (REST)
gmailgoogleapis
gdrivegoogleapis
gsheetsgoogleapis
For any service not in this list, use call() with a custom rollback function instead. See Execution Methods for details.