Workflow Control Flow
DurableWorkflow is the single durable workflow primitive. Use it for one saved step or for a pipeline with parallel branches, joins, bounded map work, JSON-based conditions, loops, approval gates, and cleanup after failure. Every SDK sends the same workflow description to the shared runtime. Routing, combining results, scheduling, loop limits, cleanup order, and replay are consistent across languages. Your callbacks perform the named work for each step.
Use this page when routes follow application rules or workflow state. If a step
needs model reasoning, run an Agent inside that step and pass its structured
result into the workflow condition. This keeps routing reproducible and
inspectable while allowing model reasoning where it is useful.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import Condition, Workflow
wf = (Workflow(workflow_id="review-42", entry="start")
.add_step("start", "load")
.add_step("left", "left")
.add_step("right", "right")
.add_join_step("join", "join")
.add_map_step("items", "inspect", "items", "reports", max_concurrency=4)
.add_step("draft", "draft")
.add_step("verify", "verify")
.add_parallel("start", "left", "right")
.add_edge("left", "join").add_edge("right", "join")
.add_edge("join", "items").add_edge("items", "draft")
.add_edge("draft", "verify")
.add_conditional("verify", [{"when": Condition.lt("score", 0.8), "to": "draft"}], "END")
.set_reducer("reports", "append").set_reducer("score", "max")
.max_steps(20))
result = await wf.run(initial_state, handler=run_named_step)
const wf = new DurableWorkflow(client, "review-42", persistence).entry("start")
.addStep("start", "load").addStep("left", "left").addStep("right", "right")
.addJoinStep("join", "join").addMapStep("items", "inspect", "items", "reports", 4)
.addStep("draft", "draft").addStep("verify", "verify")
.addParallel("start", "left", "right")
.addEdge("left", "join").addEdge("right", "join")
.addEdge("join", "items").addEdge("items", "draft").addEdge("draft", "verify")
.addConditional("verify", [{ when: workflowCondition.lt("score", 0.8), to: "draft" }], "END")
.setReducer("reports", "append").setReducer("score", "max").maxSteps(20);
const result = await wf.run(initialState, runNamedStep);
The Rust API uses typed workflow methods. See the workflow API reference for its names and signatures.
wf := NewDurableWorkflowWithStore(client, "review-42", store).Entry("start").
AddStep("start", "load").AddStep("left", "left").AddStep("right", "right").
AddJoinStep("join", "join").AddMapStep("items", "inspect", "items", "reports", 4).
AddStep("draft", "draft").AddStep("verify", "verify").
AddParallel("start", "left", "right").AddEdge("left", "join").AddEdge("right", "join").
AddEdge("join", "items").AddEdge("items", "draft").AddEdge("draft", "verify").
AddConditional("verify", branches, "END").SetReducer("reports", "append").MaxSteps(20)
result, err := wf.Run(initialState, runNamedStep)
using var wf = new DurableWorkflow(client, "review-42", persistence);
wf.Entry("start").AddStep("start", "load").AddStep("left", "left").AddStep("right", "right")
.AddJoinStep("join", "join").AddMapStep("items", "inspect", "items", "reports", 4)
.AddStep("draft", "draft").AddStep("verify", "verify")
.AddParallel("start", "left", "right").AddEdge("left", "join").AddEdge("right", "join")
.AddEdge("join", "items").AddEdge("items", "draft").AddEdge("draft", "verify")
.AddConditional("verify", branches, "END").SetReducer("reports", "append").MaxSteps(20);
var result = wf.Run(initialState, runNamedStep);
try (var wf = new DurableWorkflow(client, "review-42", persistence).entry("start")) {
wf.addStep("start", "load").addStep("left", "left").addStep("right", "right")
.addJoinStep("join", "join").addMapStep("items", "inspect", "items", "reports", 4)
.addStep("draft", "draft").addStep("verify", "verify")
.addParallel("start", "left", "right").addEdge("left", "join").addEdge("right", "join")
.addEdge("join", "items").addEdge("items", "draft").addEdge("draft", "verify")
.addConditional("verify", branches, "END").setReducer("reports", "append").maxSteps(20);
JsonNode result = wf.run(initialState, runNamedStep);
}
An Agent is a separate primitive for autonomous model/tool loops. It does not force agent behavior into a fixed graph. Choose DurableWorkflow when application code must define the control flow.
The snippets show the builder shape. initial_state, branches, and
runNamedStep are application values: define the initial JSON state, condition
branches, and handler registry before calling run. You can also register a
callback on each step when a shared handler registry is not useful.
One workflow, from step replay to control flow
The builders below create the same workflow shape. The parallel branch outputs are merged in declaration order, map output preserves item order, and the condition loops through draft until the score reaches the threshold or max_steps stops execution.
Conditions, joins, bounded execution
Conditions are JSON predicates, not host callbacks. Supported operators are eq, ne, gt, gte, lt, lte, in, not_in, contains, starts_with, exists, is_empty, all, any, and not. A conditional's branches are checked in order, then its default edge is followed. Join reducers include append, sum, and merge_object; Rust merges parallel results in declared edge order. Map steps read an array at items_path, limit active callbacks to max_concurrency, and store results at output_key in input order.
Use max_steps and per-step max_visits to stop loops that run too long. A step can require approval or name a cleanup handler. If the workflow fails, compensate_on_failure runs configured cleanup handlers in reverse completion order, including successful sibling branches. If cleanup also fails, the error reports both the original failure and cleanup failures. Cleanup is best effort; use request IDs or status checks to make retries of external actions safe.
Persistence, connectors, replay
DurableWorkflow accepts a SQLite path, an in-memory store, or an existing PersistenceStore / ConnectorPersistence. When a caller passes a store, closing the workflow does not close that caller-owned store. Reusing the same workflow ID and store reuses completed step results without calling their handlers again. StorageConnector lets an application keep those records in PostgreSQL, SQL Server, Redis, or another database it operates. Its conditional update must be one atomic database operation so two workers cannot claim the same work. See Custom Storage Connectors.
store = ConnectorPersistence(my_connector)
workflow = Workflow(workflow_id="review-42", persistence=store, entry="load")
Keep callbacks limited to a step's work. They do not choose branches, evaluate predicates, reduce state, or decide whether a completed step should replay.