Give an agent a budget and approvals
Name an agent, give it a budget and an approval rule, and switch it off without a deploy.
Building for 0.3
Status Status is where the work is: Planned (in a milestone, not started), Building (tickets in progress), Preview (usable, may change), then the stability it ships at.
Stability The promise an interface ships with.
- Stable Follows semantic versioning; breaking changes need a new major, 12 months of overlap and a codemod.
- Beta Usable in production; may change before it becomes stable.
- Experimental May change or go away; needs an explicit opt-in in main.yaml.
You will declare an agent, run a step through it and approve a waiting step. It takes about 10 minutes. The full walk-through is in agents with an identity, a budget and approvals.
You need
- An action or model call the agent will make.
1. Declare the agent
agents:
support-bot:
budget: { spend: $5/day, calls: 500/day }
approve: { risk: destructive, spend-over: $1 }
enabled: true2. Run a step through it
import { agents } from "mainsdk";
declare function refundOrder(input: { orderId: string }): Promise<unknown>; // your own action
const user = { id: "u_1" };
const input = { orderId: "o_1" };
const out = await agents.run(
{ agent: "support-bot", action: "orders.refund", user: user.id, spend: "$5.00", risk: "destructive" },
() => refundOrder(input),
);A step over spend-over, or at the destructive risk, returns pending and waits.
3. Approve it
import { agents } from "mainsdk";
const approvalId = "apr_1"; // from the pending approval
const admin = { id: "u_admin" };
agents.approve(approvalId, { kind: "user", id: admin.id });An agent approving its own step fails with MAIN-AGENT-0003.
Check it worked
Set enabled: false. The next call fails with MAIN-AGENT-0004, with no deploy.
Next
Was this page helpful?