Workflows
A workflow is a plain async function marked
'use workflow'that orchestrates'use step'units. Each step runs once, persists its result, and retries on failure. The whole run survives crashes and redeploys, so it can pause for minutes, days, or months and resume exactly where it stopped.
Where an agent holds an open-ended conversation, a workflow runs a fixed, auditable pipeline: validate, call a model, write a side effect. The durability comes from the upstream Workflow SDK (the same engine behind Vercel Workflows); Stackbone runs it on a per-install Redis-backed runtime.
The model in one minute
- Two directives.
'use workflow'on the function makes it durable and replayable.'use step'on a sub-function makes that unit run once, persist its result, and retry on failure. Every side effect belongs in a step. - Deterministic body, side effects in steps. The body is replayed on every crash-resume, so keep it free of clocks, randomness, and direct I/O. Steps hold the real work, and the runtime replays their recorded results instead of re-running them.
- A typed contract. Sibling
inputSchemaandoutputSchemaZod exports describe the workflow. The input is validated before a run starts. - Discovered by convention. Any
workflows/<name>.workflow.tsis picked up automatically; the exported function is the camelCase name plusWorkflow.
import { z } from '@stackbone/sdk';
export const inputSchema = z.object({ email: z.email(), company: z.string() });
export const outputSchema = z.object({ score: z.number(), qualified: z.boolean() });
export async function qualifyLeadWorkflow(input: z.infer<typeof inputSchema>) {
'use workflow';
const score = await scoreLead(input.company); // a durable step
return { score, qualified: score >= 60 };
}
async function scoreLead(company: string) {
'use step';
return company.length * 5;
}Kill the runtime mid-run and it resumes from the last completed step instead of replaying everything.
Where to go next
- Getting started: scaffold, trigger, and observe your first workflow, including long waits and approvals.
- Examples: an onboarding pipeline, a refund with a human approval, and a scheduled digest.
- Workflow agents: let a step delegate to an agent.
- Human-in-the-loop: pause a run for a person to approve.