Author workflows with an agent
1. Inspect authority and interfaces
Section titled “1. Inspect authority and interfaces”Ask the agent to read organisation context, networks, controlled accounts, and saved ABI contracts. Give it:
- the operational goal and required human review points;
- exact networks and controlled accounts;
- permitted transaction targets and HTTP hosts;
- input/output requirements;
- notification channels and audiences.
The v2 authoring catalog reads saved contracts but does not silently discover, fetch, or replace an ABI while compiling source. Register or verify contract interfaces separately before referencing them.
2. Generate one program
Section titled “2. Generate one program”The source must default-export one defineWorkflow() call. It may use ordinary
TypeScript variables, closures, loops, branches, arrays, native bigint,
sequential await, Promise.all, and Promise.allSettled.
Every external read or action uses an SDK effect. Each call needs a deterministic
stable key and positive maxResultBytes. The declared capability envelope
must cover all reachable effect kinds and resources.
Ask the agent to avoid "*" capabilities unless you explicitly need them.
For dynamic transaction targets or controlled accounts, use schema inputs with a
finite capability allow list compatible with the credential’s grant.
3. Validate
Section titled “3. Validate”Call validate_workflow_source first. Review:
- compiler diagnostics with source locations;
- normalized input and output schemas;
- capability and call-site summaries;
- forbidden imports or promise patterns;
- source/bundle and universal-limit errors.
Validation is read-only. It does not save source or prepare a backend artifact.
4. Create, save, or fork
Section titled “4. Create, save, or fork”create_workflowvalidates source and creates an owned workflow at Version 1.save_workflowappends and activates the next version using exact workflow CAS.fork_workflowcopies a selected revision into a new owned workflow at Version 1.restore_workflow_revisionappends a selected historical source as the next version.
Only the seated owner or its authorized agent can save or restore. Other members, including organisation admins, inspect and fork.
5. Review the result
Section titled “5. Review the result”Every changed save compiles again, checks account-grant authority, prepares the immutable Cloudflare artifact, and appends one current revision. Invalid or canonically unchanged source creates no revision.
Review the complete source, capability envelope, and proposed diff before
saving. After saving, inspect the new revision and artifact identity. A 409
keeps the proposed source. Read the current workflow and resolve the conflict
before retrying with a new CAS.
Use list_workflow_revisions, get_workflow_revision, and
get_workflow_revision_diff to inspect history. Undo is a restore of the
previous version, so both operations append a compensating revision.