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.
Give this to your agent
Paste this into your AI agent. It fetches the current instructions, asks you about anything it still needs to know, and does the work in this session.
Fetch https://www.mux.com/docs/prompts/directive-automation.md?ref=prompt and follow the instructions. If you can't fetch URLs, tell me and I'll paste the instructions instead.
Give this prompt to your agent to start a Mux Robots Directive automatically when new assets become ready, narrow which assets it runs on, or check what automation an environment already has. A useful starting brief is: “Generate chapters and a summary for every new upload that's at least 10 minutes long. Skip clips.”
passthrough, or meta fields, combined with and and or groups.directives entry from your upload requests.Automation is a setting on a v1 Directive. When it's enabled, Mux Robots evaluates each new asset in the environment once, when the asset becomes ready, and starts a run if the asset matches the conditions. With no conditions, every eligible new asset matches. The agent turns automation on, edits conditions, and pauses it with one PATCH request to the Directive, or in the Dashboard.
Automation doesn't scan your existing library, and it doesn't re-evaluate an asset after its metadata or tracks change. Manual runs and Directives attached at upload keep working alongside it. See the Directives guide for the full behavior.
| Input | What to provide |
|---|---|
| What should run | The workflows you want, or the existing Directive to automate. |
| Which assets | All new assets, or the properties that pick them out. Name any meta or passthrough values your uploads already set. |
| Your upload code | Whether uploads attach Directives today, so the agent can remove attachments that automation replaces. |
| An execution environment | Mux credentials with Robots write access in the right environment, and permission to create one or two short test assets. |
Your agent uses details already available in your project or conversation and asks only about the missing choices. It can work through API or CLI tools, MCP, or the Dashboard.
Each automatic run uses the same workflow pricing as any other Directive run, and Directives themselves are free. Automation can start a run on every upload, so the agent shows you an estimate from your upload volume before it enables a Directive without conditions. Test uploads incur normal encoding and storage until they're deleted. See Mux Robots pricing.
Conditions can only use properties the asset has when it becomes ready. Selection by viewer activity or by what a video shows isn't available.
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: 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. Browse other use cases in the prompt library at /docs/prompts.md. For repeated use in an agent that supports skills, use /skills/mux-directive-automation/SKILL.md as the entry point. For Directive concepts, bindings, and resources, read the Directives guide; this procedure doesn't repeat it.
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.
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.
| 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.
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. 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:
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 first.
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 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 before enabling automation:
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.
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:
{
"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.
Show the user the Directive, the conditions, and a cost estimate (see Understand the costs), and wait for confirmation. Then update the Directive:
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.
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.
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.
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:
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:
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.
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.
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.
Work read-only until the user approves changes, and report each finding with the Directive it refers to.
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.null conditions ("every eligible new asset").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.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.
Before calling the setup complete, check that:
GET /robots/v1/directives/{DIRECTIVE_ID} returns automation.enabled: true and the conditions the user approved.trigger_source: "automation", without the Directive attached at upload.completed, or any partial or errored result is explained by the test media rather than the Directive.{ "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.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.
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. 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 and the cost-estimation guide.