Workflow definitions
Declare a workflow and its steps, choose where each call runs, and give the workflow a name operators can recognize across deployments.
Declare a workflow and its steps, choose where each call runs, and give the workflow a name operators can recognize across deployments.
Authoring at a glance
- A workflow body is a set of named calls: a call starts when the values it uses are ready, and line order means nothing. Inside
with sequential:, each statement starts after the previous statement’s work has finished. - Declare workflows, steps, tools and agents at module scope.
- Write ordinary Python inside steps;
.fnpreserves the function’s signature. - A decorated step call in workflow orchestration schedules durable work.
- Use
.fn(...)inside a step, helper or test; await async functions and supply their context. - Calls inside a step share its attempt and connection permissions.
- In workflow bodies, omit
awaitand the injectedStepContextargument. - Use
branch,mapandloopfor workflow control flow; call another workflow by name to run it as a child run. - Bind step results to names; use them as inputs, projections or return values.
- Title what an operator reads or picks in the console: a workflow and its reviews.
- Use
mapfor fan-out over a step; start a batch of independent records as one run per record. - Validate before deploying; see the grammar below and step semantics for restrictions and typing limits.
Module scope is load-bearing
@workflow, @step, @tool, and Agent(...) declarations must be
module-level. Agents must be direct assignments (extractor = Agent(...))
so deploy-time discovery can stamp stable identities.
Steps and workflows
A call’s target is a step or a workflow. A direct call, a branch arm, a
loop body and until, and a sleep’s then take either; map takes a
step. Where each runs differs:
| Step | Workflow | |
|---|---|---|
| Runs in | This run’s sandbox | Its own run, on any worker |
| Cost to start | Negligible | A queue wait and a sandbox |
timeout bounds |
One attempt | Active time of its own run |
| Can wait on a person | No | Yes |
| Counts against | The run’s sandbox | The organization’s run limit |
| Input | 16 MiB for the combined step input | One parameter, a run’s input, 1 MiB |
A child run takes its parent’s deployment. Only JSON values and file
references cross a call, never a live handle such as a portal sign-in or a
connection. A child is bounded by its own workflow’s usage_limits, which a
caller’s limits do not cover, and its case key comes from the field its own
input marks with CaseKey(), as any run’s does.
Build a list from other lists inside a step, such as one that returns
[*state.history, item]. An expression containing no workflow value or call,
such as 1 + 2, is a deployment-time constant.
Use and, or, not (or &, |, ~) for conditions. Boolean
producers declare bool, its type aliases, boolean literals, or these types
with None; unannotated and Any results remain unchecked. A constant
alone is not a condition. Compute defaulting expressions such as
value or "unknown" inside a step. Calls inside either operand of
and/or/&/| are rejected: bind the result first for unconditional work,
or use branch for conditional work. Comparisons and combinations can be
passed to steps and returned.
A local body is a synchronous def directly inside the workflow, with zero
parameters for a branch arm or one required positional parameter for a loop.
It ends with return value or return. Use assignments and calls inside
it; decorators, defaults, variadic parameters, nested definitions and
recursion are unsupported. It can capture outer values and be reused; each
use creates its own work. Every declared body must be used.
None is a value. An explicit return None or bare return yields None,
including after work in a local body. A workflow body that ends without a
return yields None, as a Python function does, whatever its last call
returns. Validation rejects a body that ends without a return when its
return annotation declares a value. Omit false= for an absent branch arm.
A chosen local body runs all of its work even when its result is None.
Record constructors accept positional and named arguments in every data
position. Constant-only trees execute at deploy; trees containing workflow
values execute when their consuming work runs, including nested constructors.
A runtime constructor inside a branch arm runs only when that arm is chosen.
A bound value expression describes data; reusing it does not create a
checkpoint or promise that construction runs only once. The class owns
parsing, aliases, validation, defaults and initialization. Deployment reports
invalid call shapes and provably missing required or factory fields. Supply
factory fields explicitly, such as tags=[]; generate fresh values in a
step. Hooks and validators must be deterministic and free of side effects
because replay and typed boundaries can reconstruct records.
Pass a constructed value intact to its consumer. To read fields or indexes
from a constructor expression, construct and project it inside a step.
A completed branch or loop result supports ordinary workflow projections.
Values cross step and durable state boundaries as canonical JSON. Tuples become JSON arrays and records become JSON objects; a receiving step’s annotation controls reconstruction. A constructor can receive live nested records and authored tuples while it builds its result; this does not carry Python object identity through later steps or loop iterations.
Workflow return types must load by their declared names. Declare return classes
at module scope under their own names. Builtins, Any, primitive Literal
values, and supported list, dictionary, tuple and union annotations work.
A function-local return class or a Literal containing enum members fails
deployment; use a module-level class or primitive literal values instead.
Declare runtime record types at module scope under their own names. Annotate
producing steps with complete source types, such as list[Item], when a
constructor needs restored Python values; Any and unannotated sources
stay JSON. Ordinary step arguments use the receiving parameter’s annotation.
Validation stops at the first workflow source error in each workflow to avoid cascading diagnostics. Calls whose targets cannot be identified from workspace source are checked at deployment; an imported helper can pass validation and then be rejected during deployment, before execution. Deployment also resolves module values and types and reports all graph validation errors together. Locations use workspace-relative paths and one-based Unicode character columns.
Declared producer and consumer types must be assignable, including record
classes, optional results, mapped element types and declared loop state.
A branch with an absent or null arm can produce None, including when its
other arm is a literal or composed dictionary. Its receiver must accept None.
Normalize incompatible declared values inside a step. A constant must be a
value a type checker would assign to the declared type: 7 fills a float
and a matching string fills a Literal, but "7" does not fill an int,
"open" an enum, or "2026-01-01" a date. Pass an enum member such as
Status.OPEN, or a module-level constant such as CUTOFF = date(2026, 1, 1).
A bool constant fills neither an int nor a float parameter.
A record constructor is the one way to build a record in a workflow body:
deployment rejects a dictionary, constant or composed, where a record is
declared, at any depth, including list items and constructor fields. A dict
or TypedDict parameter takes a dictionary; deployment checks a TypedDict’s
required keys and each value against its field type. Inferred dictionary value
types do not constrain later loop keys.
Validation checks syntax and facts available from source. Deployment also
checks argument and return types by the same rule, record fields,
mapped argument shapes and unequal known list lengths. A constant that a type
checker would accept is also validated as execution validates it, which
applies field constraints and a record’s validators. Values that arrive at
run time are validated into the declared type where they arrive: a run’s input
from the API, and a step result declared loosely, such as Any. Custom
validators remain authoritative for runtime data.
Display names
title= names something for the operators who run workflows in the console,
which shows it in place of the code name. Title what an operator reads or
picks: a workflow and its reviews. A workflow’s title is its readable name,
even when it mirrors the key. Title a step only when its function name would
not read to someone who has not seen the code; a step title that only
respaces the function name adds nothing, so leave it off.
title= is optional on @workflow, @step, wait_for_review and
wait_for_event; without one the console shows the key, the function name or
the label. A title is printable text on one line, at most 80 characters,
and on a wait it is a deployment-time constant. Changing a title changes no
identity, so rename freely; keys and labels are the identities.
@workflow(key="stock_report", title="Stock report")
def stock_report(input: ReportInput) -> None:
figures = parse_filing(input.filing)
review = wait_for_review(
FiguresCheck, subject=figures, timeout="72h", title="Check the figures"
)
Stable identity
Definitions default to module:function for steps, module:variable for
agents, and the function name for workflows. Pin identity across refactors with
@step(key="..."), Agent(key="..."), or @workflow(key="...").
Explicit keys match [a-z_][a-z0-9_]* and are unique within each definition
kind in a deployment.
Workflow node keys normally come from assignment names. Each parameter and local
name may be bound only once in its workflow or local body; separate local bodies
may reuse names. A local assignment shadows the outer name throughout its
body, so read it only after assignment. Use a different local name when its
value depends on the outer binding. Use distinct names such as loaded and
refined for successive results. Bind calls (recommendation = recommend(claim))
or pass key= to primitives that expose it when a structural key would be ambiguous. An unbound
call uses the short callee identity, such as result.true/refine, without its
module path. Branch arms and loop bodies are scoped under their container.
Different callees with the same short identity also require distinct bindings.
Repeated unbound calls to the same target in one scope are rejected because
occurrence suffixes can shift when a sibling call is inserted or reordered.
Validation reports repetitions when source identifies the target; deployment
checks all resolved targets. For example, replace
(summarize(input), summarize(input)) with separate assignments to first
and second, then (first, second).