Custom Workflows
Go beyond prebuilt templates. Custom workflows let you compose AI steps, conditional logic, loops, and external calls into exactly the automation your product needs.
Anatomy of a workflow
A custom workflow is a directed sequence of steps. Each step takes an input, does something — call an AI model, transform data, hit an API — and passes its output to the next step via context.
- Trigger: Defines when the workflow runs — on API call, webhook event, schedule, or user action.
- Steps: The logic of your workflow. Chain AI steps, conditions (if / else), loops, and integrations in any order.
- Output: What the workflow returns — a structured response, a side effect (email sent, record updated), or both.
Building your first custom workflow
Every step name you define becomes available asctx.{step_name}downstream. Keep names short and descriptive — you'll reference them often.
Error handling & retries
Set a retry policy per step
Any step can fail — network timeouts, model errors, schema mismatches. Define a retry policy at the step level to handle transient failures without rewriting your entire workflow.
Fallback steps
Use.onError()to define what happens when a step fails after all retries — log the failure, return a default value, or trigger a different path.