Reference for writing a Workflow tool script (script API and gotchas, resume, quality patterns, worked examples). Load before authoring a script for a workflow the user already opted into; it does not itself authorize running one.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Workflow Authoring?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tomorrow-dev-workflow-authoring)
---
name: workflow-authoring
description: "Reference for writing a Workflow tool script (script API and gotchas, resume, quality patterns, worked examples). Load before authoring a script for a workflow the user already opted into; it does not itself authorize running one."
---
# Writing a workflow script
A workflow script is JavaScript run by the Workflow tool in a sandbox with no file system, no network and no imports. It orchestrates agents; the agents do the work.
## Shape
```js
export const meta = {
name: 'my-workflow',
description: 'One sentence on what it does',
phases: ['Plan', 'Work', 'Check'],
}
const plan = await phase('Plan', () => agent({ prompt: `Plan: ${args.task}`, label: 'planner' }))
```
- `meta` comes first and is a pure object literal: no variables, no calls, no template substitutions.
- The rest is the body of an async function: top-level `await` works, and the last returned value is the result.
- `args` holds the arguments the caller passed. Everything else the script needs comes from `args` or from an `agent()`.
## API
- `agent({ prompt, label?, schema? })` runs one agent with a fresh context and resolves to its final answer. With a JSON `schema` the answer is the parsed object. The agent sees only its `prompt`: put everything it needs there.
- `parallel([() => agent(...), ...])` runs the thunks at once and resolves to their results in order.
- `pipeline(initial, step1, step2, ...)` feeds each step the previous result.
- `phase(title, body)` marks a phase of `meta.phases` as started, then runs `body`.
## Determinism
A run resumes (`resumeFromRunId`) by replaying the script: each `agent()` call is matched by its position to the journaled answer, and only the calls after the first change run again. So the script must be deterministic:
- `Date`, `Date.now()` and `Math.random()` throw. Pass a value in through `args`, or ask an agent.
- Do not branch on anything that varies between runs. Branch on agent answers and `args` only.
- Keep the order and number of `agent()` calls stable for the same inputs; editing a prompt re-runs that call and those after it.
## Quality patterns
- Split by independence: fan out with `parallel`, join with one synthesis agent.
- Give each agent one job and one output shape; use `schema` for anything the script reads.
- Separate the doer from the checker: a second agent that did not write the work verifies it, and the script loops on its verdict, with a bound on the rounds.
- Prompts are self-contained: goal, constraints, where to look, the form of the answer.
- Cap fan-out (for example 5 to 8 agents per phase) and say so in the prompt of the synthesis step so it knows what was left out.
- Return a compact result: the answer, then the evidence, not the transcripts.
## Examples
Fan out then synthesize:
```js
export const meta = { name: 'survey', description: 'Survey several angles then merge', phases: ['Survey', 'Merge'] }
const angles = await phase('Survey', () =>
parallel(args.angles.map((angle) => () => agent({ prompt: `Investigate ${angle} for: ${args.question}. Reply with findings and sources.`, label: angle }))))
return phase('Merge', () => agent({ prompt: `Merge these findings into one answer to "${args.question}":\n\n${angles.join('\n\n---\n\n')}` }))
```
Do, check, retry:
```js
export const meta = { name: 'checked', description: 'Do a task and have it verified', phases: ['Do', 'Check'] }
let work = await phase('Do', () => agent({ prompt: args.task }))
for (let round = 0; round < 3; round++) {
const verdict = await phase('Check', () => agent({
prompt: `Verify this against the task "${args.task}". Be strict.\n\n${work}`,
schema: { type: 'object', properties: { ok: { type: 'boolean' }, problems: { type: 'string' } }, required: ['ok'] },
}))
if (verdict.ok) break
work = await agent({ prompt: `Fix these problems in the work.\n\nTask: ${args.task}\n\nWork:\n${work}\n\nProblems:\n${verdict.problems}` })
}
return work
```