Skip to main content
A workflow is the main orchestrator in Output Framework. It defines the sequence of steps to execute and must contain only deterministic code.

Basic Workflow

workflow.ts
import { workflow, z } from '@output.ai/core';
import { fetchData, processData } from './steps.js';

export default workflow({
  name: 'processItems',
  description: 'Fetch and process data items',
  inputSchema: z.object({
    itemIds: z.array(z.string())
  }),
  outputSchema: z.object({
    results: z.array(z.string())
  }),
  fn: async (input) => {
    const data = await fetchData(input.itemIds);
    const results = await processData(data);
    return { results };
  }
});

Workflow Options

OptionTypeDescription
namestringUnique identifier for the workflow
descriptionstringHuman-readable description
inputSchemaZodSchemaZod schema for input validation
outputSchemaZodSchemaZod schema for output validation
fnfunctionThe workflow implementation
optionsobjectAdvanced Temporal activity options

Workflow Rules

Workflows must be deterministic. This means:

Do

  • Call steps and evaluators
  • Use conditionals and loops
  • Import from whitelisted files

Don't

  • Make API calls directly
  • Use Date.now() or Math.random()
  • Import arbitrary modules

Allowed Imports

Workflows can only import from: Components:
  • steps.js — Step definitions
  • evaluators.js — Evaluator definitions
  • shared_steps.js — Shared steps across workflows
Whitelisted files:
  • types.js, consts.js, constants.js
  • vars.js, variables.js
  • utils.js, tools.js, functions.js, shared.js

Activity Options

Override Temporal’s default activity options:
export default workflow({
  name: 'myWorkflow',
  inputSchema: z.object({ id: z.string() }),
  outputSchema: z.object({ result: z.string() }),
  fn: async (input) => {
    // workflow logic
  },
  options: {
    retry: {
      maximumAttempts: 5
    },
    startToCloseTimeout: '10m'
  }
});
Options set on a workflow apply to all steps. Steps can override these with their own options.

File Structure

Each workflow lives in its own directory:
src/
└── my-workflow/
    ├── workflow.ts      # Workflow definition (required)
    ├── steps.ts         # Step implementations (required)
    ├── evaluators.ts    # Evaluators (optional)
    └── prompt@v1.prompt # LLM prompts (optional)