workflow.ts file. This is where you define what happens and in what order — fetch company data, then enrich it with an LLM, then push it to your CRM. The workflow orchestrates; the steps do the actual work.
Basic Workflow
Here’s a workflow that enriches a sales lead by looking up the company and generating a summary:workflow.ts
fn function is your workflow logic. It calls steps in sequence, and each step’s result is automatically cached — if a step fails and the workflow retries, previously completed steps won’t re-execute.
Workflow Function
| Option | Type | Description |
|---|---|---|
name | string | Unique identifier for the workflow |
description | string | Human-readable description |
inputSchema | ZodSchema | Zod schema for input validation |
outputSchema | ZodSchema | Zod schema for output validation |
fn | function | The workflow implementation |
options | object | Optional workflow options (see Options) |
Workflow Rules
Workflows must be deterministic — given the same input, they must always follow the same path. This is because Output (via Temporal) replays your workflow code to recover state after failures. If the code produces different results on replay, recovery breaks. In practice this means:Do
- Call steps and evaluators
- Use conditionals and loops
- Import from allowed files
Don't
- Make API calls directly
- Use
Date.now()orMath.random() - Import component files from wrong locations
Allowed Imports
Workflows can import from: Components (detected by convention):steps.ts— A single file namedsteps.tsin the workflow directorysteps/*.ts— Any file inside asteps/directory in the workflow directoryevaluators.ts— A single file namedevaluators.tsin the workflow directoryevaluators/*.ts— Any file inside anevaluators/directory in the workflow directoryshared/steps/*.ts— Shared steps available to all workflowsshared/evaluators/*.ts— Shared evaluators available to all workflows
- Type definitions, constants, helpers, utilities
- API clients from
src/clients/
Project Structure
Each workflow is a self-contained directory with a standard set of files. API clients live insrc/clients/ at the top level — they’re standalone modules any step can import:
The workflow file must be named
workflow.ts. Steps are detected from steps.ts or any file inside a steps/ directory. Evaluators follow the same pattern with evaluators.ts or evaluators/. Shared components must be under shared/steps/ or shared/evaluators/. Everything else (types, utils, clients) can be organized however you prefer.Options
Activity options
You can configure how steps behave — timeouts, retry counts, backoff — using theoptions.activityOptions property. These apply to all steps in the workflow:
workflow.ts
options.activityOptions — see step options.
The fields under activityOptions are supported by Output and relayed directly to Temporal, our runtime. The full list of Activity options:
activityIdallowEagerDispatchcancellationTypeheartbeatTimeoutpriorityretryscheduleToCloseTimeoutscheduleToStartTimeoutstartToCloseTimeoutsummary
ValidationError or FatalError are never retried — these signal problems that won’t fix themselves on retry (bad input, missing credentials).
Native options
Output supports one native workflow option besides activity options:| Option | Type | Description |
|---|---|---|
disableTrace | boolean | When true, disables trace file generation for this workflow. Only has effect when tracing is enabled globally. |
workflow.ts
Workflow Context
Thefn function receives a context object as its second argument, giving you access to workflow execution info:
workflow.ts
context.control.continueAsNew()— Continue the workflow as a new execution with fresh historycontext.control.isContinueAsNewSuggested()— Check if continue-as-new is recommendedcontext.info.workflowId— The workflow execution ID
File Structure
Workflows support two organization patterns: Flat files:What’s Next
Once you have a workflow, you’ll want to explore these related concepts:- Steps — Where I/O happens: API calls, LLM requests, database queries
- Child Workflows — Compose workflows by calling other workflows
- Parallel Execution — Run multiple steps concurrently with
executeInParallel - External Integration — Send data out, receive input, and query status
- Connecting to External APIs — Build typed, traced API clients