# Connect to a vault

> Connect an agent or workflow to a vault so it can run on that vault's data: from ROC or with the vault SDK, ship new versions to connected vaults, and set spend limits.

Source: https://developers.manykind.ai/agents/ship/connect-to-a-vault/

Deploying makes a version available. Nothing runs on a vault's data until the vault owner **connects** the agent. A connection is a signed, scoped, revocable agreement between the vault and the agent: the owner signs it with their wallet, and the vault records it with the scopes and settings they chose.

## What a connection holds

| Part | Meaning |
|---|---|
| Scopes | The vault scopes the agent may read and publish in. Each must be in the manifest's `requiredScopes` (default `default`). |
| Settings | Values for the agent's declared `settings`, validated against its schema. |
| Ceiling | Optional spend limits. See [Spend limits](#spend-limits). |

The connection also provisions the agent's cubbies in the vault.

## Connect from ROC

| Where | How |
|---|---|
| **Workflow Builder** | **Deploy** connects the workflow, and any agent it calls, to your vault. Your wallet may ask for your passkey. |
| **Sandbox** | Pick the agent and a vault; the pill reads **agent not connected** with a **Connect** button. When connected, it reads **agent connected**, with a control to disconnect. |
| A widget | `WidgetRuntime.connectAgent()` connects the widget's agent for the signed-in reader. |

<!-- shot: sandbox-connect | /agent-services/:serviceId/sandbox | the connection pill showing agent not connected and Connect -->

## New versions reach connected vaults

A connection follows the agent's current deployment. Each run resolves the deployed version, so pushing and deploying a new version reaches every connected vault without a reconnect.

## Connect with the vault SDK

```ts

const sdk = new VaultSDK({
  endpoint: vaultApiUrl,
  garEndpoint: garUrl,                                  // required for agents.connect
  signer: await CereWallet.fromMnemonic(mnemonic),      // or KeypairWallet.fromSeed(seed)
});

const vault = await sdk.vault.ensure();
const connection = await vault.agents.connect({
  agentId: "<agentServicePubkey>:<alias>",
  scope: "default",                                     // or scopes: ["default", "research"]
  settings: { apiKey: "…" },
  ceiling: { gpuUnits: 500, a2aTokens: 200000 },
});
```

| Input | Required | Meaning |
|---|---|---|
| `agentId` | yes | `<agentServicePubkey>:<alias>`. The pubkey is taken from the prefix unless you pass `agentServicePubkey`. |
| `scope` or `scopes` | one of them | The scopes to connect into. |
| `settings` | no | Values for the agent's settings schema. |
| `ceiling` | no | Spend limits, written together with the connection. |

`connect` signs one consent agreement covering every requested scope, submits it to the agreement registry, and creates the connection. The vault reads the manifest from the registry itself; you never send it.

### Manage a connection

```ts
const all = await vault.agents.list();
const one = await vault.agents.get(agentId);   // status, scopes, settings, ceiling
await one.update({ apiKey: "…" });             // new settings
await one.setCeiling({ gpuUnits: 1000 });      // new limits
await one.disconnect();
```

Disconnecting keeps the cubby data.

## Spend limits

A connection can carry two limits. Blank or `0` means no limit.

| ROC label | SDK field | Counts |
|---|---|---|
| **Compute limit — metered GPU units** | `gpuUnits` | GPU units the platform measured. Decimals allowed. |
| **Token limit — agent-reported** | `a2aTokens` | Tokens the agent reports about itself. Whole numbers. A stop signal, not a measured cost. |

Once the connection's total reaches a limit, new tasks for that agent in that vault are refused. Spend is counted when a task finishes, so a limit stops the next run after it is crossed, not a run in progress.

In ROC, set limits in the deployment dialog's **Execution rules** section: pick the vault, enter the limits, and click **Save limits**. Limits belong to the connection, not to the deployment revision, so the agent must already be connected to that vault.
<!-- shot: execution-rules | /agent-services/:serviceId/registry/:agentName | the Execution rules section with Token limit and Compute limit -->

## Errors

| Code | Cause | Fix |
|---|---|---|
| `MANIFEST_INVALID` | A requested scope is not in `requiredScopes`, or the agent id does not match the manifest. | Connect into a declared scope, or push a version that declares it. |
| `MANIFEST_NOT_FOUND` | No manifest for that agent id in the registry. | Check the id and that the agent was pushed. |
| `SETTINGS_SCHEMA_MISMATCH` | Settings do not satisfy the schema. | Fix the values. |
| `AGENT_ALREADY_CONNECTED` | A connection already exists. | Use the existing connection. |
| `GAR_MISSING`, `GAR_EXPIRED` | No valid consent agreement. | Connect again to sign a new one. |
| `CUBBY_PROVISION_FAILED` | A cubby migration failed. | Fix the migration in a new version. |

All codes: [Errors](https://developers.manykind.ai/reference/errors/).

## Related

- [Next: Vaults](https://developers.manykind.ai/vaults/overview/)
- [Connections and consent](https://developers.manykind.ai/vaults/connections-and-consent/)
- [Push and deploy](https://developers.manykind.ai/agents/ship/push-and-deploy/)
- [Vault SDK reference](https://developers.manykind.ai/reference/vault-sdk/)
- [Work with the vault SDK](https://developers.manykind.ai/vaults/build-on-a-vault/work-with-the-vault-sdk/)
