---
title: "Give an agent a budget and approvals"
description: "Name an agent, give it a budget and an approval rule, and switch it off without a deploy."
section: "guides"
status: "Building for 0.3"
spec: "agent-governance"
canonical: "https://mainsdk.dev/docs/guides/govern-an-app-agent"
updated: "2026-10-28"
---

# 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.

Status: Building for 0.3 · Canonical: https://mainsdk.dev/docs/guides/govern-an-app-agent · Updated: 2026-10-28

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](https://mainsdk.dev/docs/agents/governance).

## You need

- An action or model call the agent will make.

## 1. Declare the agent

```yaml title="main.yaml"
agents:
  support-bot:
    budget: { spend: $5/day, calls: 500/day }
    approve: { risk: destructive, spend-over: $1 }
    enabled: true
```

## 2. Run a step through it

```ts title="lib/refund-step.ts"
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

```ts title="app/api/approve/route.ts"
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

- [App agents](https://mainsdk.dev/docs/interfaces/agents)
