# Connections and consent

> How an agent or workflow gets access to a vault — the agreement the owner signs, what the platform checks at connect time, and how access ends.

Source: https://developers.manykind.ai/vaults/connections-and-consent/

An agent or workflow runs on a vault's data only after the vault owner
**connects** it. Connecting does two things: the owner's wallet signs an
**agreement**, and the vault creates a **connection** that records what was
granted. Consent is what the owner gives; the agreement is the signed record
that proves it.

## What the owner signs

The agreement is held in the agreement registry, not in the vault. It binds:

| Bound | Form |
|---|---|
| The owner's wallet | the public key that signs |
| Your Agent Service | `agentServicePubkey`, the prefix of the agent id |
| The vault | the vault id |
| The scopes | the set of scopes the connection may use |

One agreement covers the whole scope set for one (Agent Service, owner) pair.
Because the agreement is the authority, you cannot widen your own access; you
can only ask the owner to sign again.

## Where connecting happens

- **In ROC.** Running a workflow from the Workflow Builder connects its agents to
  the vault first. The first run asks for a passkey to sign the agreement.
- **From your own app.** `vault.agents.connect({ agentId, scope })` in the Vault
  SDK builds the agreement, signs it with the configured signer, submits it, and
  creates the connection in one call.

The full walkthrough is [Connect to a vault](https://developers.manykind.ai/agents/ship/connect-to-a-vault/).

<!-- shot: run-consent-passkey | /agent-services/:serviceId/workflows/:workflowId | the passkey prompt on a workflow's first Run -->

## What the vault checks

A valid signature is necessary but not sufficient. At connect time the vault:

1. Fetches your agent's manifest from your Agent Service's registry by agent id.
   The manifest, not any listing, is the authority on what the agent declares.
2. Checks that the agent id's prefix matches the manifest's Agent Service.
3. Checks every requested scope is one the manifest asks for (`default` when it
   declares none).
4. Validates the owner's `settings` values against the manifest's settings
   schema.
5. Verifies the agreement is present and not revoked or expired.
6. Provisions the cubbies the manifest declares, running their migrations.

Only then does the connection become `active`.

## What a connection records

| Field | Meaning |
|---|---|
| `agentId` | `<agentServicePubkey>:<alias>` |
| `scope` / `scopes` | The scopes it may use. |
| `status` | `provisioning` → `active` → `revoking` → `revoked`. |
| `settings` | The owner's values for the manifest's settings schema. |
| `ceiling` | Optional spend ceiling: `gpuUnits` (platform-metered) and `a2aTokens` (self-reported by an LLM agent). The platform refuses new work once a ceiling is reached. |

A connection runs the agent's current deployment: deploying a new version
reaches every connected vault without a reconnect.

### Workflows and connectors

A workflow's access to the vault's [connectors](https://developers.manykind.ai/vaults/connectors/) is part of
its consent. When you deploy a workflow, ROC grants it exactly the connector
actions and events its graph uses, per connection, and removes access the graph
no longer uses.

## How a request proves authority

Every call into a vault traces back to a signature:

| Proof | Used by | How |
|---|---|---|
| **Signed request** | Apps acting with the owner's or a member's key | The body is canonicalized and signed; sent as `X-Public-Key` / `X-Signature`. |
| **Delegation token** | Clients acting on someone's behalf without the key | `Authorization: Bearer <token>`, scoped and revocable. |
| **Execution token** | A running agent or workflow | Minted per task, short-lived, carrying the connection's authority for that vault, scope, and run. Your code never sees a credential; `ctx` uses it. |

## Ending access

| Action | Effect |
|---|---|
| **Disconnect** (`connection.disconnect()`) | Deletes the connection. Cubby data is kept, so a later reconnect resumes. |
| **Revoke the agreement** | Removes the root of authority. The vault checks the registry for every active connection and tears down any whose agreement is revoked or expired. |

Agreement reads are cached briefly, so revocation takes effect within that cache
window rather than instantly. What the agent wrote stays in the vault.

## Errors

Match on the error `code`, not the HTTP status.

| Code | Meaning |
|---|---|
| `AUTH_MISSING` | No usable signature or token on the request. |
| `AUTH_AMBIGUOUS` | Conflicting auth schemes on one request. |
| `AGENT_ALREADY_CONNECTED` | A live connection already exists for this agent. |
| `MANIFEST_NOT_FOUND` | No manifest for this agent id in the registry. |
| `MANIFEST_INVALID` | A requested scope is not in the manifest, or the agent id does not match it. |
| `SETTINGS_SCHEMA_MISMATCH` | `settings` do not match the manifest's schema. |
| `GAR_MISSING`, `GAR_EXPIRED` | No agreement, or one revoked or expired. |
| `CUBBY_PROVISION_FAILED` | A declared cubby's migration failed. |

## Related

- [Next: Memory Bank](https://developers.manykind.ai/vaults/memory-bank/)
- [Connect to a vault](https://developers.manykind.ai/agents/ship/connect-to-a-vault/)
- [Sovereign data](https://developers.manykind.ai/vaults/sovereign-data/)
- [Vaults](https://developers.manykind.ai/vaults/overview/)
- [Members](https://developers.manykind.ai/vaults/members/)
