# Push and deploy

> Ship an agent or workflow: build it, push a version to your Agent Service's bucket, and deploy it with deployment records that choose which version runs for which audience, from the CLI or ROC.

Source: https://developers.manykind.ai/agents/ship/push-and-deploy/

This group covers getting any agent to run on a customer's data: push and deploy a version, then have the vault owner connect it.

Shipping has three steps, and they are the same for code agents and workflows:

| Step | What it does | CLI | ROC |
|---|---|---|---|
| **Build** | Bundles the code and writes `manifest.json`. | `mk build` | The Workflow Builder builds from the canvas. |
| **Push** | Uploads a version to the Agent Service's storage bucket, the registry. Versions are immutable. | `mk push` | Part of **Deploy** in the Workflow Builder. |
| **Deploy** | Applies deployment records: which version runs, for which vaults and events. | `mk deploy` | Agent page → **Overview** → deployments; **Deploy** in the Workflow Builder. |

Then a vault owner must **connect** the agent before it runs on their data. See [Connect to a vault](https://developers.manykind.ai/agents/ship/connect-to-a-vault/).

## Before you start

From ROC, open your Agent Service → **⋯** → **Settings** → **General** and copy:

- **Agent-service public key**: pass it as `--as-pubkey`.
- **Registry bucket ID**: pass it as `--bucket`.

On the **Access** tab, generate two tokens:

| Token | Used by | Environment variable |
|---|---|---|
| **Storage access token** | `mk push`, `mk widget push`, `mk cubby push` | `MANYKIND_DDC_ACCESS_TOKEN` |
| **CLI access token** | `mk deploy`, `mk publish` | `MANYKIND_ACCESS_TOKEN` |

Tokens are shown once. Members of an Agent Service get their storage token through an invite; see [Team](https://developers.manykind.ai/get-started/team/).

<!-- shot: service-settings-access | /agent-services/:serviceId (Settings drawer, Access tab) | the DDC access token and CLI access token panels -->

## Environments

Every command takes `--env dev|stage|prod` (or `$MANYKIND_ENV`). The default is `dev`. One flag selects the whole environment: the storage network for push (`dev` = devnet, `stage` = testnet, `prod` = mainnet), the platform API for deploy, and the endpoints baked into widgets. Push and deploy to the same environment.

## Build

```bash
mk build
```

Writes `dist/<alias>/bundle.js`, `manifest.json`, and `widgets/<id>/` for every agent in `manykind.config.ts`. A workflow written with `defineWorkflow` builds the same way; its graph and the workflow runner become the bundle. `mk build` first runs the checks of `mk validate`, which lists every problem at once; run it on its own while you edit. Build errors are listed in [Write an agent](https://developers.manykind.ai/agents/code-agents/overview/#what-mk-build-rejects).

## Push

```bash
export MANYKIND_DDC_ACCESS_TOKEN=…
mk push --env dev --bucket <bucketId> --as-pubkey <agentServicePubkey>
```

`mk push`:

- uploads `bundle.js` and each widget directory, content-addressed;
- writes `manifest.json` under `agents/<alias>/<version>/` in the bucket and moves `latest` to it;
- stamps the agent id `<agentServicePubkey>:<alias>` and the environment's endpoints into the manifest and widgets;
- declares any cubby the manifest names that the bucket does not have yet.

To publish into an organization vault instead of a bucket you control, pass `--vault <vaultId> --vault-scope <scope>` instead of `--bucket`: the vault API checks you may write that scope and writes the vault's registry bucket itself. Its request body is capped at 64 MiB; ship large assets as vault objects, not in the bundle.

Before uploading anything, `mk push` checks the access token against the bucket's on-chain owner. A token that the owner did not issue is refused with the owner's address and the fix. See [Team](https://developers.manykind.ai/get-started/team/#publishing-as-a-member).

Preview a push with `mk push --dry-run`: it lists what would be uploaded and where, from local files only, without credentials.

Bump `version` in `manykind.config.ts` for each push you want to keep. An A2A agent you run elsewhere is registered with `--kind external`; see [Bring your own (A2A)](https://developers.manykind.ai/agents/llm-agents/bring-your-own/).

## Deploy

```bash
export MANYKIND_ACCESS_TOKEN=…
mk deploy --env dev --as-pubkey <agentServicePubkey>
```

`mk deploy` reads every record in `deployments/` and applies them as one set, replacing what is live. The folder is the desired state: delete a file and the next deploy removes that record. Each apply creates a revision you can roll back to in ROC.

### Deployment records

One record per file; the filename is the record name (`^[a-z0-9][a-z0-9_-]{0,62}$`). `.json` and `.jsonc` are read, comments allowed.

```jsonc
// deployments/default.jsonc
{
  "priority": 99,
  "targeting": "",       // empty: the default record, matches everything
  "version": "latest",
  "weight": 1
}
```

```jsonc
// deployments/sandbox-canary.jsonc
{
  "priority": 10,
  "targeting": "vault.scope == 'sandbox'",
  "version": "0.2.0",
  "weight": 1,
  "params": { "temperature": 0.1 }
}
```

| Field | Required | Rule |
|---|---|---|
| `priority` | yes | Among matching records, the lowest priority wins. |
| `targeting` | yes | A CEL expression over `vault` (`id`, `scope`), `event` (`type`), and `connection.settings`. `""` marks the default record. |
| `version` | yes | A pushed semver, or `"latest"`. |
| `weight` | no | A positive integer, default `1`. Records in the same priority tier split traffic by weight: `90` and `10` is a 90/10 split. |
| `enabled` | no | `false` excludes the record. |
| `params` | no | Overrides the manifest's param defaults. |
| `engagements` | no | Per-engagement overrides: `{ "<id>": { priority, weight, limit: { n, per }, enabled, params } }`. |
| `expiresAt` | no | RFC 3339. Once past, the record is ignored. |

The set must contain **exactly one** default record (empty `targeting`). A Job resolves its version when it is created and keeps it until it ends, so `"latest"` affects new Jobs only.

| Flag | Default | Meaning |
|---|---|---|
| `--version <v>` | — | Override `version` in every record without editing files. |
| `--deployments <path>` | `deployments` | A folder, or one file holding `{ "deployments": [...] }` or a single record. |
| `--dry-run` | — | Compare the set with what is live and print what would change; apply nothing. |
| `--note`, `--author` | git `user.email` | Recorded on the revision. |

Preview a deploy before you apply it:

```
$ mk deploy --dry-run
Dry run of mk deploy: <agentServicePubkey>:ticket-triage (dev), live revision 3; 1 change, nothing sent
  = unchanged default: latest (priority 99, weight 1)
  + add sandbox-canary: 0.2.0 (priority 10, weight 1, when vault.scope == 'sandbox')
```

### Rollout patterns

| Goal | Records |
|---|---|
| Ship to everyone | One default record, `version` pinned or `"latest"`. |
| Canary to an audience | Add a record with targeting and a lower priority than the default. |
| Percentage rollout | Two records in one priority tier with weights such as `90` / `10`. |
| Temporary experiment | Add `expiresAt`. |

### In ROC

Open **Agents**, pick the agent, and use the deployments manager on **Overview**: **New deployment**, **Edit deployment**, **Delete deployment**, and **History** with **Roll back**. The form has **Route** (Name, Audience — targeting (CEL), Version, Priority, Weight), **Parameters**, **Engagements**, and **Execution rules**. **Save revision** creates a new revision; limits in **Execution rules** are saved separately with **Save limits**.
<!-- shot: deployment-form | /agent-services/:serviceId/registry/:agentName | the New deployment dialog with Route and Execution rules -->

## Scripts, CI, and coding agents

In your terminal, `mk push` and `mk deploy` run as soon as you start them and print text. In a script, in CI, or under a coding agent, the CLI changes two things:

- **It never prompts.** When nobody can answer (a coding agent, `CI` set, stdin not a terminal, or `MK_NON_INTERACTIVE=1`), `mk push` and `mk deploy` need `--yes`. Without it they change nothing, exit `2`, and print the command to re-run.
- **It prints JSON.** When stdout is not a terminal, or a coding agent runs it, the result is JSON on stdout and progress goes to stderr. A failure is one JSON object with a stable `reason`. Force a format with `--format text|json` or `--json`.

```bash
# CI
mk validate
mk build
mk push --bucket "$BUCKET" --as-pubkey "$AS_PUBKEY" --yes
mk deploy --dry-run > plan.json      # what would change, for the log
mk deploy --yes
```

Exit codes: `0` success, `1` failed, `2` usage or confirmation needed, `4` authentication. See [Output, prompts, and errors](https://developers.manykind.ai/reference/cli/#output-prompts-and-errors).

## Workflows

A workflow is an agent, so the same steps apply.

- **Release, then deploy.** **Release** in the Workflow Builder, or `mk release`, checks the workflow and publishes a numbered version without making it live; **Deploy**, or `mk deploy <version>`, makes a release live. See [Release and deploy](https://developers.manykind.ai/agents/workflows/release/).
- **`latest` is what is live.** A workflow's triggers (events, schedules, webhooks) are read from its `latest` version. `mk release` leaves `latest` alone and `mk deploy <version>` moves it; `mk push` moves it at once.
- **Push and deploy still work.** `mk build`, `mk push`, `mk deploy` ship a `defineWorkflow` workflow as any agent, without checks. See [Workflows in code](https://developers.manykind.ai/agents/workflows/author-in-code/).

## Listing

`mk publish` sends the agent's card to the marketplace listing, and the agent page's **Pricing** tab publishes its pricing. Neither is needed to deploy, connect, or run the agent.

## Related

- [Next: Connect to a vault](https://developers.manykind.ai/agents/ship/connect-to-a-vault/)
- [Write an agent](https://developers.manykind.ai/agents/code-agents/overview/)
- [Team](https://developers.manykind.ai/get-started/team/)
- [CLI reference](https://developers.manykind.ai/reference/cli/)
