Workflows

Drafts, node kinds, publishing, runs, approvals.

Raw Markdown for agents: workflows.md. MCP: read_docs("workflows").

A workflow chains several published routines in a Space: items pass from one routine node to the next, an approval node lets a person decide between steps, and a trigger node starts the chain. Build one only for such a chain. One routine with a schedule is configured with routines.automation.set, with webhooks or events through a queue (read_docs("queues")) instead; files that should arrive in a folder are an import source (read_docs("imports")). A workflow has a draft definition and, once published, an immutable active version. workflows.get returns draft, published version, webhooks, trigger status and shares.

Build flow: workflows.create (starts with one manual trigger node) -> workflows.node_kinds with detail=summary (keys, descriptions and ports of every kind) -> workflows.node_kinds with kinds=[...] and detail=full for each kind you add (its JSON config schema, default config and output schema; take config fields and port names only from there, never guess them) -> workflows.draft.save with the full definition and the current expected_revision (409 on stale revision; the response lists non-blocking validation issues) -> workflows.validate to check without saving -> workflows.publish (validates, creates the active version, registers schedule and event triggers, creates webhooks). Node kinds: trigger.manual, trigger.schedule, trigger.event, trigger.webhook, routine, approval. Every node has an id, a kind, config and connections between ports; items flow between nodes as JSON lists. A routine node needs only skill_id (the routine's id): the items of its predecessor reach the routine run as input/items.jsonl in the run's working directory (plus their document references in the scope), and the routine's declared outputs come back as items (an items output as one item per element, a sheet as one item per row, a doc as one item with its text). Chain routines instead of mapping fields; input_mapping and instruction stay available for explicit values. workflows.rename changes the name at once; workflows.draft.discard drops the draft of a published workflow and keeps the active version (an unpublished workflow is archived instead).

Waiting for people: workflows have no wait or loop nodes. Waiting lives inside a routine node: its routine's agent calls wait_for_reply, or its script entry calls ctx.wait_for_reply and is resumed (read_docs("routines"), "Flows that wait for people"); the node shows WAITING until the routine run ends, then its outputs flow on. input_mapping keys are the routine's declared inputs (a text input takes a string or expression, a document input {document_id}); a script entry reads them as ctx.inputs, and the predecessor's items arrive as its items.

Schedules (trigger.schedule config, also routines.automation.set and import sources): prefer kind=rule, a structured rule with unit (minute, hour, day, week, month, year), every, times (HH:MM in the schedule timezone) and for months a list of on selectors. Every 14th: on=[{type: month_day, day: 14}]; last day of the month: day=-1; first Monday: {type: nth_weekday, nth: 1, weekday: 1}; last workday: {type: nth_weekday, nth: -1, weekday: workday}; last day of week 4 of the month: {type: month_week, week: 4, day: last}; ISO week 3 of the year: unit=year with {type: year_week, week: 3, day: first}; every second week needs every=2 plus start_date. kind=cron stays available for five-field expressions (L = last day of month, 1#1 = first Monday, L5 = last Friday; day-of-month and day-of-week together match either one), kind=once runs a single time. Call workflows.schedule.preview with the schedule to validate it and to tell the user the next run times before publishing.

Running: workflows.runs.start runs a published workflow from its manual trigger; workflows.runs.get, workflows.runs.events (cursor; after_event_id is a deprecated alias) and workflows.runs.node_items show progress and data; runs.get and runs.events take wait_seconds (0-25) to wait for a final state or new events instead of polling. An approval node creates an Approval (read_docs("approvals"); the wait carries approval_id): a person decides it in the app, approvals.list shows it, and the run continues on its own once it is decided or expires. workflows.runs.retry continues a failed or cancelled run from the failed step; workflows.runs.replay starts a finished run again from the beginning. workflows.list reports per workflow runs_30d, errors_30d (FAILED), last_status and recent_statuses (last 30 runs, oldest first; test runs excluded).

Lifecycle: workflows.set_enabled pauses or resumes the triggers, workflows.archive removes triggers and keeps history, workflows.delete only works on archived workflows without runs. workflows.restore copies an earlier version into the draft (publish afterwards). workflows.share manages access for other users of the Space. workflows.webhooks.rotate issues a new webhook URL and secret (the old URL stops working).