# Run Robots workflows on new uploads automatically

Set up Mux Robots Directive automation with AI agents. Run a Directive on every eligible new asset, or only on assets that match conditions like duration, aspect ratio, ingest type, or metadata, with no Directive ID attached at upload.

Source: https://www.mux.com/docs/prompts/directive-automation.md · Last updated: 2026-12-04

## Agent instructions

Use this procedure to run a Mux Robots Directive automatically on new assets: set up automation on a new or existing Directive, change or pause automation that's already running, or audit what an environment's automation selects. When automation is enabled on a v1 Directive, Mux Robots evaluates each new asset in that environment once, when the asset becomes ready, and starts a run if the asset matches the Directive's conditions. With no conditions, every eligible new asset matches. Upload requests don't need to attach the Directive.

Follow the user's requirements and existing project instructions. Reuse the tools, credentials, and upload code already available. If a Mux MCP server is already connected, use it for Mux operations. If the environment has no Mux credentials yet and you can run shell commands, sign in with the [Mux CLI](https://www.mux.com/docs/integrations/mux-cli.md): run `npx @mux/cli login`, or `mux login` if it is installed. It opens a browser where the user approves access and chooses the Mux environment, so nobody creates or pastes an access token. Agent shells and `!` commands are not interactive terminals, where a plain `login` exits with an error. Run `npx @mux/cli login --json` in the background instead: it writes the authorization URL as a JSON line on stderr and waits up to five minutes for the user to approve. Give the user that URL and wait for the command to finish. If the user may not be there to approve it, for example because they said they are unavailable, add `--timeout 60` so the command gives up after one minute. If the command times out or nobody can approve the sign-in, stop waiting and continue with the work that does not need Mux access. Sign-in cannot finish in an unattended session, or on a remote machine that the user's browser cannot reach. In your report, list the Mux operations that still need credentials. Without a shell, fetch https://www.mux.com/prompts/onboarding.md and complete it first; it connects the Mux MCP server. The examples and defaults below are starting choices; adapt them to the request.

Canonical instructions: [/docs/prompts/directive-automation.md](https://www.mux.com/docs/prompts/directive-automation.md). Browse other use cases in the prompt library at [/docs/prompts.md](https://www.mux.com/docs/prompts.md). For repeated use in an agent that supports skills, use [/skills/mux-directive-automation/SKILL.md](https://www.mux.com/skills/mux-directive-automation/SKILL.md) as the entry point. For Directive concepts, bindings, and resources, read the [Directives guide](https://www.mux.com/docs/guides/robots-directives.md); this procedure doesn't repeat it.

## Track your progress with this checklist

Copy this checklist into your task list or plan before starting, and keep it updated as you work. Mark each item done, skipped with the reason, or blocked with what is needed. Include the final state of the checklist in your report to the user.

1. Identify the mode: set up automation, change or pause automation, or audit automation.
2. Check the environment for Mux credentials and tools. If there are none, sign in with the Mux CLI as described above. If you cannot check, say so and offer the CLI sign-in rather than asking the user for an access token.
3. Resolve every question in the table under **Start with the request**: answered by the user, answered from the project, or not applicable with the reason.
4. Confirm which Mux environment you're working in. Automation applies to every new asset in that environment.
5. **Get approval before enabling automation.** Show the Directive, its conditions, and a cost estimate, and wait for the user to confirm. From then on, every matching upload starts a billable run.
6. Complete each numbered step that applies, or record why it was skipped. Save Directive, asset, and run IDs as you go.
7. Run every check under **Verify the result** that applies, against real test uploads where credentials allow.
8. Report which checks ran against real Mux, and which still need credentials, test media, or a decision from the user.

## Start with the request

First determine whether the user wants to **set up automation** on a Directive, **change or pause automation** that already exists, or **audit automation** to see what an environment runs on new uploads. The first two change Mux configuration and may touch upload code. The audit starts read-only.

Inspect the available project, its upload code, its Mux configuration, and configured tools before asking questions. Use what the user has already told you, and ask only for missing choices that change the work:

| Question | Why it matters |
| :-- | :-- |
| Which workflows should run, and is there already a Directive for them? | Decides whether to create a Directive or enable automation on an existing one. Bindings and resources can't be edited after creation. |
| Should every new asset run it, or only some? What sets those assets apart? | Defines the conditions, or `null` for all eligible new assets. The answer has to map to a field listed in step 3. |
| Do uploads set `passthrough` or `meta` values the conditions could use? | Text conditions match exact, case-sensitive strings, so they must use values the upload code really sends. |
| Does the upload code attach this Directive today? | Automation can replace that attachment, which simplifies the upload request. |
| Should existing assets be processed too? | Automation never backfills. Existing assets need manual runs, with their own cost approval. |
| Which environment, and is there a non-production one to test in? | Enabling automation affects every new upload in the environment, including other people's. |

Treat upload volume estimates, which assets count as "the right ones", and whether existing assets get processed as the user's decisions. Mux selects assets and starts runs.

### Choose an execution method

| Available capability | How to use it |
| :-- | :-- |
| Repository and coding tools | Find Directive attachments and `meta` or `passthrough` values in the upload code, update it, and script the API calls below. |
| Mux MCP, CLI, or API access | Create and update Directives, upload test assets, and list runs. Check which operations the installed tool version supports. With the MCP server's `execute` tool, check asset and run status in separate short calls instead of a wait loop inside one call: agents may move a long-running tool call to the background and leave it there until it finishes. |
| Browser or computer use | In the Dashboard, open the Directive and click **Add Automation**, choose **All new assets** or **Only assets that match conditions**, acknowledge the workflow charges, and click **Enable automation**. New Directives offer the same choice under **Automation rule**. Record IDs and check the saved settings after each change. |
| Advice-only chat | Produce the requests and conditions to run, and identify the credentials and environment needed to apply them. |

If a needed operation is unavailable, explain the handoff rather than inventing a tool. Never place an access token secret in client code, a repository, or a chat transcript.

## 1. Check credentials and the Directive version

The access token needs **Mux Robots** Read (`robots:read`) and Write (`robots:write`) in the environment where uploads land, plus **Mux Video** Write to create test assets. See [Robots permissions](https://www.mux.com/docs/core/make-api-requests.md#mux-robots-permissions). Existing tokens cannot gain permissions; create a replacement if needed. A `403` with `insufficient_scope` on an update means the token lacks `robots:write`.

List the Directives in the environment:

```bash
curl "https://api.mux.com/robots/v1/directives?limit=100&page=1" \
  --user "$MUX_TOKEN_ID:$MUX_TOKEN_SECRET"
```

Each summary includes `automation`: an object for a v1 Directive, and `null` for a v0 Directive. Automation is available only on v1 Directives. To automate a v0 Directive, [create a v1 copy](https://www.mux.com/docs/guides/robots-migrate-directives-to-v1.md) first.

## 2. Create or choose the Directive

To reuse a Directive, retrieve it with `GET /robots/v1/directives/{DIRECTIVE_ID}` and check that its bindings and resources do what the user wants. Only `name` and `automation` can change after creation, so a Directive that runs the wrong workflows needs a replacement.

To create one, follow [create a Directive](https://www.mux.com/docs/guides/robots-directives.md#create-a-directive) for bindings and resources. Leave automation off until the Directive is tested. `automation` is optional on `POST /robots/v1/directives` and defaults to disabled with `conditions: null`.

Test the Directive on one existing asset that meets the [Robots workflow prerequisites](https://www.mux.com/docs/guides/robots.md#workflow-prerequisites) before enabling automation:

```bash
curl https://api.mux.com/robots/v1/directives/YOUR_DIRECTIVE_ID/runs \
  --user "$MUX_TOKEN_ID:$MUX_TOKEN_SECRET" \
  --header "Content-Type: application/json" \
  --data '{ "asset_id": "YOUR_ASSET_ID" }'
```

A `409` means a run for that Directive and asset is already in progress. Check the run with `GET /robots/v1/directives/{DIRECTIVE_ID}/runs/{RUN_ID}` until it reaches `completed`, `partial`, or `errored`, and fix the Directive before going on if it didn't complete.

## 3. Write the conditions

Skip this step when every eligible new asset should run the Directive; use `"conditions": null`.

A condition is one predicate, `{ "field", "operator", "value" }`, or a group. `{ "and": [...] }` matches when every child matches, and `{ "or": [...] }` when at least one does. Groups can nest.

| Field | Value | Operators |
| :-- | :-- | :-- |
| `duration` | Nonnegative seconds; fractions allowed. | `equals`, `not_equals`, `greater_than`, `greater_than_or_equal`, `less_than`, `less_than_or_equal`, `in`, `not_in` |
| `max_stored_frame_rate` | Nonnegative frames per second. | Same as `duration` |
| `meta.title`, `meta.creator_id`, `meta.external_id` | Text from the asset's `meta`. | `equals`, `not_equals`, `contains`, `in`, `not_in` |
| `passthrough` | The asset's passthrough string. | Same as `meta` fields |
| `ingest_type` | `on_demand_url`, `on_demand_direct_upload`, or `on_demand_clip`. | `equals`, `not_equals`, `in`, `not_in` |
| `resolution_tier` | `720p`, `1080p`, `1440p`, `2160p`, or `audio-only`. | `equals`, `not_equals`, `in`, `not_in` |
| `aspect_ratio` | `width:height` with positive integers, such as `16:9`. Equivalent ratios match, so `32:18` equals `16:9`. | `equals`, `not_equals`, `in`, `not_in` |

`in` and `not_in` take an array of 1 to 50 values. A condition can hold up to 25 predicates across three levels of groups. Text values can't be empty, can contain up to 1,024 characters, and match case-sensitively with whitespace preserved.

**A missing field fails every comparison, including `not_equals` and `not_in`.** An asset with no `meta.creator_id` doesn't match `{ "field": "meta.creator_id", "operator": "not_equals", "value": "creator_123" }`, and an unknown frame rate matches nothing. There's no operator that tests whether a field is present. If the user wants assets without a value included, the conditions can't express it; say so and suggest setting the value at upload.

This example selects assets at least 10 minutes long that weren't created as clips:

```json
{
  "and": [
    { "field": "duration", "operator": "greater_than_or_equal", "value": 600 },
    { "field": "ingest_type", "operator": "not_equals", "value": "on_demand_clip" }
  ]
}
```

Before saving conditions on `meta` or `passthrough`, read the upload code or a few recent assets to confirm the exact strings uploads send.

## 4. Enable automation

Show the user the Directive, the conditions, and a cost estimate (see **Understand the costs**), and wait for confirmation. Then update the Directive:

```bash
curl https://api.mux.com/robots/v1/directives/YOUR_DIRECTIVE_ID \
  --request PATCH \
  --user "$MUX_TOKEN_ID:$MUX_TOKEN_SECRET" \
  --header "Content-Type: application/json" \
  --data '{
    "automation": {
      "enabled": true,
      "conditions": {
        "and": [
          { "field": "duration", "operator": "greater_than_or_equal", "value": 600 },
          { "field": "ingest_type", "operator": "not_equals", "value": "on_demand_clip" }
        ]
      }
    }
  }'
```

The response is the complete Directive. Check that `data.automation` matches what you sent. A `422` means the update is invalid, for example an operator the field doesn't support, more than 25 predicates, or an empty string. Read the error messages, fix the conditions, and send the request again.

Allow up to one minute for the change to take effect. Assets that become ready before then may not be evaluated with the new settings.

## 5. Update the upload code

Search the upload code for the Directive's ID in `directives`, both on `POST /video/v1/assets` and in `new_asset_settings` for direct uploads.

* If automation selects every asset the attachment covered, remove the attachment. When both select an asset, the attachment takes precedence and only one run starts, so leaving it doesn't double the cost, but it keeps two sources of truth.
* If the attachment covers assets that the conditions skip, keep it. An attachment always runs, whatever the conditions say.
* Other Directives attached at upload are unaffected.

Two different Directives that both run on an asset each start a run and each bill, even if they include the same workflow. If another automated Directive overlaps with this one, point it out to the user.

## 6. Test with new uploads

Automation only evaluates new assets, so test with uploads made after the change took effect. Use a non-production environment if the user has one with the same Directive.

Upload one asset that should match and, when there are conditions, one that shouldn't. Conditions on `meta` or `passthrough` make this easy to control. For example:

```bash
curl https://api.mux.com/video/v1/assets \
  --user "$MUX_TOKEN_ID:$MUX_TOKEN_SECRET" \
  --header "Content-Type: application/json" \
  --data '{
    "inputs": [{ "url": "https://example.com/test-video.mp4" }],
    "playback_policies": ["public"],
    "passthrough": "automation-test-match"
  }'
```

Use a test file that meets the conditions and the workflows' needs. A workflow that reads captions needs speech, and a duration condition needs a long enough file. Don't attach the Directive to test uploads, or you'll be testing the attachment instead.

When each asset is ready, list the Directive's runs:

```bash
curl "https://api.mux.com/robots/v1/directives/YOUR_DIRECTIVE_ID/runs?limit=25&page=1" \
  --user "$MUX_TOKEN_ID:$MUX_TOKEN_SECRET"
```

The matching asset should have a run whose `subject_id` is its asset ID and whose `trigger_source` is `automation`. The other asset should have none. If webhooks are configured, `robots.v1.directive_run.created` arrives for the automated run. If no run appears after a minute or two, check that automation was enabled before the asset became ready, that the asset meets the workflow prerequisites, and that every field in the conditions has a value on the asset.

Delete the test assets afterwards if the user agrees.

## 7. Process existing assets, if asked

Automation won't select assets that were ready before it was enabled. When the user wants them processed, list the candidates with `GET /video/v1/assets`, estimate the cost, and get approval. Then start a manual run for each one, as in step 2, in bounded batches. Save each run ID so the work can resume, and skip assets that already have a run for this Directive.

## Change or pause automation

Every change is a `PATCH` to the Directive. Omitted fields keep their saved values.

| Goal | Request body | Effect |
| :-- | :-- | :-- |
| Pause | `{ "automation": { "enabled": false } }` | Stops new automatic runs and keeps the saved conditions. |
| Resume | `{ "automation": { "enabled": true } }` | Restarts automatic runs with the saved conditions. |
| Replace the conditions | `{ "automation": { "conditions": { ... } } }` | Replaces the entire condition tree. Send the full tree, not only the part that changed. |
| Run on all eligible new assets | `{ "automation": { "conditions": null } }` | Clears the conditions. This doesn't disable automation. |
| Rename | `{ "name": "New name" }` | Leaves automation as it is. |

In the Dashboard, turn off **Enabled** on the Directive's automation card to pause, and use the card's three-dot menu and **Edit** to change conditions.

Runs that already started finish as configured after a pause, a change, or a deletion, and they're billed. Manual runs and attachments keep working while automation is paused. Changes take up to one minute to apply. Deleting a Directive stops its automatic runs for good; confirm with the user first, since it can't be undone.

To change which workflows run, create a new Directive, test it, enable automation on it, and then pause or delete the old one. Pause the old one first if both would otherwise run on the same assets.

## Audit automation

Work read-only until the user approves changes, and report each finding with the Directive it refers to.

1. **List automated Directives.** From `GET /robots/v1/directives`, collect every Directive whose `automation.enabled` is `true`, with its name, ID, and conditions. Directives with `"enabled": false` and saved conditions are paused; list them separately.
2. **Explain what each one selects** in plain language, including `null` conditions ("every eligible new asset").
3. **Flag risky conditions**: `not_equals` or `not_in` on a field that uploads don't always set (those assets never match), text conditions whose values don't appear in the upload code, and Directives without conditions in an environment with high upload volume.
4. **Find overlap.** Two automated Directives that can both select the same asset each run, and each bill. Upload code that attaches an automated Directive is harmless but redundant.
5. **Check recent runs.** `GET /robots/v1/directives/{DIRECTIVE_ID}/runs` shows `trigger_source` for each run: `manual`, `attachment`, `automation`, or `null` for older runs. A run history with no `automation` entries on an enabled Directive is worth investigating.

Then propose changes, and apply them only after the user confirms.

## Verify the result

Before calling the setup complete, check that:

* `GET /robots/v1/directives/{DIRECTIVE_ID}` returns `automation.enabled: true` and the conditions the user approved.
* A new upload that matches the conditions gets a run with `trigger_source: "automation"`, without the Directive attached at upload.
* A new upload that doesn't match gets no run from this Directive.
* The automated run reached `completed`, or any `partial` or `errored` result is explained by the test media rather than the Directive.
* Upload code no longer attaches the Directive where automation replaces it, and still attaches it where the conditions would skip assets that need it.
* Pausing with `{ "automation": { "enabled": false } }` keeps the conditions, and a new matching upload made after a minute starts no run. Resume afterwards if the user wants automation running.
* No other automated Directive overlaps with this one unless the user chose that.

For an agent-built setup, report which of these were tested against real uploads and runs, and which still need credentials, test media, or the user's approval.

## Understand the costs

Directives and automation are free. Each run is billed at the normal rate for the workflows it runs, in Mux Robots units, whether it started automatically, from an attachment, or by hand. To estimate, multiply the expected number of matching uploads per month by the cost of one run of the Directive's workflows, using [Mux Robots pricing](https://www.mux.com/docs/pricing/overview.md#mux-robots-pricing). Resources the Directive generates follow their own pricing; auto-generated captions have no additional charge. Test uploads add encoding and storage until they're deleted; see the [pricing overview](https://www.mux.com/docs/pricing/overview.md) and the [cost-estimation guide](https://www.mux.com/docs/pricing/estimating-video-costs.md).
