- Updated
- Reading
- 10 min
- By
- Anlyon Team
How to let an AI agent issue Stripe refunds, update GitHub files and send email within fixed limits
Configure the Stripe refund, GitHub file update and Resend email adapters so an agent names an action, Anlyon holds the key and makes the call, every agent shares one limit, and each result comes back as a graded receipt.
- Stripe
- GitHub
- Resend
- refunds
- provider workflows
- impact limits
To let an AI agent issue Stripe refunds, update a GitHub file or send email through Resend within fixed limits, keep the provider key out of the agent and route each write through an Anlyon action with an adapter: stripe.refund, github.file_update or resend.email_send. The agent names the action and passes input. Anlyon holds the credential, reserves the action's impact against a limit every agent shares, binds any approval to the exact request, makes the call and returns a receipt with a grade.
TL;DR
- Each adapter fixes its target in config: a Stripe account, mode and currency; a GitHub owner, repo, branch and path prefix; a Resend sending domain and from-addresses. The agent cannot pick a different one.
- A limit counts what the adapter changes: money in minor units for refunds, resource mutations for file updates, emails per recipient for sends. Every agent, session and key in the environment draws from it, reserved before dispatch.
- Preview, then invoke with
previewIdand a stableoperationKey, so the reviewed request is the one that runs and a retry is not a second refund. confirmedmeans something different per adapter. A Resend receipt is Resend's record, not inbox delivery.- A lost response is recorded
unknownand is never sent again automatically. Stripe and Resend support a same-key replay inside 24 hours. GitHub does not.
How do the three adapters compare?
stripe.refund | github.file_update | resend.email_send | |
|---|---|---|---|
| Operation | Refund of an explicit amount on a payment intent | Update of one existing UTF-8 text file, up to 64 KB | One email from a designated sending domain |
| Counted as | money in the action's currency, plus one resource_mutations | One resource_mutations | emails, one per recipient across to, cc and bcc |
confirmed means | Stripe's own record of the refund was read | GitHub's own record of the commit carrying Anlyon-Effect: was read | A read-back of the email id shows this effect's tag |
| Stale-state protection | Not atomic. Refundable amount is as of review, re-checked before dispatch | Atomic. The write carries the reviewed blob SHA | None. Resend has no conditional send |
| Same-key replay after a lost response | Yes, within 24 hours | No | Yes, within 24 hours |
| Undo | No. A refund cannot be reversed through the Stripe API | A new, separately reviewed file update | No. A sent email cannot be recalled |
Setup runs from an operator key in a deploy script, never from the agent.
How do I set up a Stripe refund action for an agent?
Store the key in the vault, bound to Stripe's API host, then define the action with the adapter. There is no URL template, and no default account that could change after review.
// setup.ts, run with an operator key
import { Client } from '@anlyonhq/sdk';
const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });
await ops.secrets.put('STRIPE_KEY', {
value: process.env.STRIPE_KEY!,
allowedHosts: ['api.stripe.com'],
});
await ops.actions.create({
name: 'refund',
description: 'Refund a payment intent. Amount is integer minor units in USD.',
requiresApproval: true,
adapter: {
type: 'stripe.refund',
config: { account: 'acct_1Nxyz', mode: 'live', currency: 'usd' },
credentialSecret: 'STRIPE_KEY',
},
});
// One allowance for every refund agent, session and key in this environment.
await ops.impactLimits.create({
name: 'Daily refunds',
dimension: 'money',
currency: 'usd',
actionName: 'refund',
period: 'day',
amount: 50_000, // $500.00
});
The adapter runs against your own Stripe account with a live or a test key. mode: 'live' takes an sk_live_ or rk_live_ key, and mode: 'test' takes sk_test_ or rk_test_. Build against a test-mode action, then add a live one.
Three details carry the boundary:
- One currency per action, integer minor units. For USD,
1250is $12.50 and50_000is $500.00. A request in another currency is refused before anything is sent. - An explicit amount on every refund. The adapter does not issue full refunds by default, so the quantity counted against the limit is always the quantity sent.
- The limit counts money and a resource mutation. A money limit and a mutation limit can both apply. Either one can refuse the operation, and the refusal says which.
The agent side is short. It previews the refund, then invokes exactly that preview under an operation key derived from your own persisted refund request.
// refund-tool.ts, in the agent's process
import { Client } from '@anlyonhq/sdk';
const agent = new Client({ apiKey: process.env.ANLYON_AGENT_KEY! });
export async function refund(refundRequestId: string, paymentIntent: string, amount: number) {
const { data: preview } = await agent.actions.preview('refund', {
paymentIntent,
amount,
currency: 'usd',
reason: 'requested_by_customer',
});
const { data } = await agent.actions.invoke('refund', preview!.request, {
previewId: preview!.id,
operationKey: `refund:${refundRequestId}`,
});
if (data!.pendingApproval) {
return { state: 'pending_approval', approvalId: data!.approvalId };
}
return { state: data!.status, grade: data!.grade, effectId: data!.effectId };
}
The preview reads Stripe and writes nothing. It shows the account and mode, the payment intent, the amount, the refundable amount observed at review and when, and an expiry. The approval is bound to a digest of that request, and Anlyon recomputes it before dispatch. A changed request sent with the reviewed previewId is refused with PREVIEW_MISMATCH. Reusing the operation key with a different request is refused with OPERATION_KEY_REUSE, and repeating it with the same request returns the existing operation without sending anything.
Is the refundable amount in the preview guaranteed?
No. Stripe has no compare-and-set on a payment intent, so the refundable amount is as of review and the preview labels it freshness. The adapter re-checks the account immediately before dispatch and relies on Stripe to refuse a refund above what remains refundable. Approval binding protects the reviewed request. It does not promise that the provider's state stayed still.
How do I give an agent one bounded GitHub file-update path?
An agent that updates a status file does not need arbitrary repository write access. Name the repository, branch and path prefix in the config. The adapter refuses the repository's default branch unless the config says allowDefaultBranch: true, refuses files it cannot read as UTF-8 text or that exceed 64 KB, and changes one existing file per effect.
await ops.secrets.put('GITHUB_TOKEN', {
value: process.env.GITHUB_TOKEN!,
allowedHosts: ['api.github.com'],
});
await ops.actions.create({
name: 'update-status-page',
requiresApproval: true,
adapter: {
type: 'github.file_update',
config: { owner: 'acme', repo: 'status', branch: 'agent-updates', pathPrefix: 'incidents/' },
credentialSecret: 'GITHUB_TOKEN',
},
});
// Bound how many file changes this repository and branch take per day.
await ops.impactLimits.create({
name: 'Status page edits',
dimension: 'resource_mutations',
resourcePrefix: 'github:acme/status@agent-updates:',
period: 'day',
amount: 20,
});
// The agent's call: one existing file, its full new content, a commit message.
const { data } = await agent.actions.invoke(
'update-status-page',
{ path: 'incidents/current.md', content: '# All systems normal\n', message: 'Close incident 812' },
{ operationKey: 'incident-812-close' },
);
The preview for a file update includes a before-and-after text diff, which is what a reviewer should read. The write carries the blob SHA the reviewer saw as its precondition. If someone changes the file at GitHub after review, GitHub refuses the stale write on that SHA, nothing is overwritten, and the receipt grades failed. Do not swap in the latest SHA and resend the old content: that erases the intervening change while presenting it as the reviewed edit. Read the new file, build a new preview and get a new decision. The approval expiry and drift guide covers that recovery.
A confirmed file update means Anlyon read GitHub's record of a commit on that branch whose message carries Anlyon-Effect: <effect id>. It does not mean tests passed or a deploy finished. The token's own permissions still matter: the action boundary does not restrict uses of that token outside Anlyon, so scope it to the repository.
How do I bound an agent's customer email sends through Resend?
Approving an email means approving its recipients and its content, not the agent's summary of it. The Resend adapter fixes the sending domain, can narrow the allowed from-addresses, and counts one email per recipient across to, cc and bcc.
await ops.secrets.put('RESEND_API_KEY', {
value: process.env.RESEND_API_KEY!, // a full access key: the read-back needs it
allowedHosts: ['api.resend.com'],
});
await ops.actions.create({
name: 'send-receipt',
adapter: {
type: 'resend.email_send',
config: { domain: 'mail.example.com', fromAddresses: ['billing@mail.example.com'] },
credentialSecret: 'RESEND_API_KEY',
},
});
await ops.impactLimits.create({
name: 'Daily customer email',
dimension: 'emails',
actionName: 'send-receipt',
period: 'day',
amount: 500,
});
const { data } = await agent.actions.invoke(
'send-receipt',
{
from: 'billing@mail.example.com',
to: ['customer@example.com'],
subject: 'Your refund has been issued',
text: 'We refunded $12.50 to your card.',
},
{ operationKey: 'refund-4411-notice' },
);
to takes 1 to 50 addresses, cc and bcc up to 50 each, and the input needs html, text or both. The credential must be a Resend API key (re_...) with full access, because a sending-only key cannot read the email back. A limit admits or refuses an operation whole: a send to four recipients is not trimmed to two when two emails remain. Revise the request explicitly if a smaller send is right.
A Resend receipt is confirmed when Resend's own record returns the email on read-back. It does not establish inbox delivery or that anyone read it. Bounces, complaints and later delivery events happen after acceptance, and the adapter does not track them.
What happens when the provider's response is lost?
A timeout, a reset connection, a 5xx or a worker that dies after sending all end the same way: the outcome is unknown, the allowance stays held, and Anlyon does not send the request again. A 409 from Stripe or Resend on an idempotent write is also recorded unknown. Reconciliation then reads the provider, never writes, and backs off from 30 seconds to one hour for up to 12 attempts.
- Stripe: looks up the refund by id, or by the
anlyon_effectmetadata on the payment intent. A refund Stripe accepts as pending is read back up to 12 times. - GitHub: looks for a commit on the branch carrying the effect trailer. Matching file content alone is never taken as proof.
- Resend: reads by email id, or scans recent sent emails, bounded, for the effect's tag.
Not finding the operation proves nothing, so the effect stays unknown with its allowance held. For Stripe and Resend, an operator holding actions:resolve can replay under the same provider idempotency key within 24 hours. GitHub has no replay, because the reviewed blob SHA cannot tell a restored file from one never written. After that, an operator resolves the effect with evidence, and the receipt is labelled manual.
// Operator runbook: the requesting agent key cannot resolve or replay its own effect.
const { data: open } = await ops.actions.effects({ unresolved: true });
for (const effect of open ?? []) {
const { data: detail } = await ops.actions.reconcileEffect(effect.id); // read-only
console.log(detail!.id, detail!.outcome, detail!.grade);
}
Tell the agent the operation is unresolved and must not be recreated under a new key. The unknown-outcome runbook walks through evidence and settlement, and structured tool results keep that state visible to the model.
What should I check before using live credentials?
- Each config names the account, repository or sending domain you intend, and each key matches it.
- Each action has a limit in the same environment and unit. Only an operator holds
impact-limits:write. - The agent's key has
actions:invokeand nothing that changes actions, secrets or limits. - No other copy of the provider key sits in the agent's process. A call made outside Anlyon is not bounded by the limit.
The OpenAI Agents SDK refund example and the Vercel AI SDK email example show the agent side in a framework. For every adapter field, read governed effects and bound approvals, and choose the scope of a shared limit before you set the amounts.
Free during Early Beta Access, no credit card. Start building
Frequently asked questions
- How do I let an AI agent issue Stripe refunds without giving it the Stripe key?
- Store the Stripe key in the Anlyon vault bound to api.stripe.com and define an action with the stripe.refund adapter, naming the account, the mode and the currency. The agent holds an Anlyon key with actions:invoke and asks for the action by name with a payment intent and an integer amount in minor units. Anlyon resolves the key at dispatch, makes the refund and returns a receipt with a grade.
- Does the Stripe refund adapter work with a live key?
- Yes. The action config names mode live or mode test, and the Stripe key must match it: sk_live_ or rk_live_ for live, sk_test_ or rk_test_ for test. Refunds run against your own Stripe account. An impact limit is shared within one environment, not across environments.
- What does a confirmed receipt mean for a Resend email?
- Confirmed means Anlyon read the email back from Resend by id and found this effect's tag. It is Resend's record of the send. It does not mean the email reached an inbox, and a sent email cannot be recalled.
- What happens if a GitHub file changes after the agent's update was reviewed?
- The github.file_update adapter sends the blob SHA the reviewer saw as a precondition. If the file changed at GitHub after review, GitHub refuses the write on that SHA, nothing is overwritten, and the receipt grades failed. Refresh the diff and get a new decision.
