# upgrade

URL: /business/nouns/agent/upgrade · Id: `verb:Agent.upgrade` · Call: `await $.Agent.upgrade({ … })` (SDK) or the `do` tool at `https://api.sb/mcp`. Inputs says what to pass, Outputs what returns, When it waits who approves.

> Upgrade moves a Customer’s minted Agent to a new Version once every case in its Tenant passes on that Version.

Upgrade moves a [Customer](/business/nouns/customer)’s minted [Agent](/business/nouns/agent) to a new [Version](/business/nouns/version) once every case in its [Tenant](/business/nouns/tenant) passes on that Version.

## Inputs
| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `agent` | [Agent](/business/nouns/agent) | Yes | The minted Agent. |
| `version` | [Version](/business/nouns/version) | Yes | The target Version. |

## Outputs
| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `agent` | [Agent](/business/nouns/agent) | Yes | The Agent, on the target Version. |

## Effects
| Fact | Value |
| --- | --- |
| Action class | None: no approval rule names it, so it runs within its seat's Permissions and Limits |
| Stakes | Who may act |
| Door | Two-way: it runs at once |
| Modes | `try` previews it and stores nothing; `send` returns a pending Action; `do` (default) waits for the result |
| Idempotent | Only with a key: a repeat with the same `Idempotency-Key` and input returns the first Action, the same key with other input is refused with `409`, and a repeat without a key runs again |
| Undo | [Action.undo](/business/nouns/action/undo) reverses it |
| Emits | [`Agent.upgraded`](/business/events/Agent.upgraded) |
| Performed by | The [Engineering Lead](/agents/engineering/engineering-lead) |

- Replays every case recorded in the Customer’s Tenant on the target Version first; a failing case leaves the Agent where it was and names the case.

## Refuses when
| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| `agent` is missing, or is not a agent | [`invalid-input`](/code/api/errors/invalid-input) | Send `agent` as a agent, then call it again. | None. |
| `version` is missing, or is not a version | [`invalid-input`](/code/api/errors/invalid-input) | Send `version` as a version, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

## When it waits
| Gate | Default |
| --- | --- |
| Decision class | Low: two-way, no delay window |
| [Delay window](/systems/trust-and-governance/controls/one-way-windows) | None: it runs once review passes. |
| Limit | The call [Limit](/business/nouns/limit) of the [Permission](/business/nouns/permission) it runs under. |
| Over the Limit | It waits `pending` for an [Approval](/business/nouns/approval), which a Human answers: the owner of record, or a Human they named to approve for the [Founder](/agents/founding/founder) seat. Approved, it runs; refused, it ends `refused` with [`limit-exceeded`](/code/api/errors/limit-exceeded); unanswered by its deadline, it ends `canceled`. |

## Example

**Ask**

```text
Upgrade the latest agent with a version.
```

**API**

```bash
curl -X POST https://api.sb/leaseline.app/agents/agent_tCzKDMorKn/upgrade \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: leaseline-agent-upgrade-1" \
  -H "Content-Type: application/json" \
  -d '{"version":"version_4HTEMs14G4"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "agent": {
    "$id": "https://api.sb/leaseline.app/agents/agent_tCzKDMorKn",
    "$type": "Agent",
    "instructions": "Write as the property manager’s assistant. Never promise a rent the manager has not set.",
    "model": "claude-opus-5-5",
    "status": "seated"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Agent.upgrade",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

**CLI**

```bash
npx startup-builder do Agent.upgrade --data '{"agent":"agent_tCzKDMorKn","version":"version_4HTEMs14G4"}' \
  --idempotency-key leaseline-agent-upgrade-1
```

**MCP**

```json
{
  "name": "do",
  "arguments": {
    "code": "return await $.Agent.upgrade({ agent: 'agent_tCzKDMorKn', version: 'version_4HTEMs14G4' })",
    "idempotencyKey": "leaseline-agent-upgrade-1"
  }
}
```

**SDK**

```ts
import { $ } from 'startup-builder'

const agent = await $.Agent.upgrade({ agent: 'agent_tCzKDMorKn', version: 'version_4HTEMs14G4' }, { idempotencyKey: 'leaseline-agent-upgrade-1' })
```

To retry, send the same `Idempotency-Key`: the retry returns the first Action and runs nothing twice. A new key runs the call again.