Compose typed workflows
Connect task results and choose the task type that fits each step.
Connect the steps
Section titled “Connect the steps”Use a workflow when your work has several steps with explicit dependencies. Each task returns a value, and tasks that depend on it can read that value with its TypeScript type preserved.
- Tasks and dependenciesDeclare each step, connect the outputs, run the graph.
- Verification loopsLet the agent try again with the check’s feedback until it passes.
- Typed responsesAsk the agent for a tagged JSON answer and validate it before using it.
- Concurrency, retries and timeoutsParallel branches, retries on failure and bounded durations.
- Result cacheReturn a task’s recorded value instead of running it again.
- ArtifactsHand files, not just values, from one task to the next.
Check a task’s result
Section titled “Check a task’s result”defineTask() prepares the input, defineLoopTask() repeats an attempt until its check accepts, and defineWorkflow() runs them in order.
Nothing runs until start(). The first round is rejected, the second receives the feedback and is accepted, and result.value(fix) keeps the type returned by attempt.
Pick a task type
Section titled “Pick a task type”| Task | Runs | Returns |
|---|---|---|
defineTask() | Your own function | Whatever it returns |
defineAgentTask() | An agent on the shared workspace | Its text, commits and typed value |
defineIsolatedTask() | An agent in its own sandbox and worktree | The same, per repository |
defineLoopTask() | Attempt and check, until accepted | The accepted candidate |
defineApprovalTask() | A gate waiting on a person | The recorded decision |
For a checkpointed workflow, return values that can be stored and restored as JSON without loss. A later process can then resume from the saved task results.
Limits
Section titled “Limits”context.value()throws for a task that is missing fromafter, even when it already ran.- A task starts only once every task in its
afterlist is done;defineWorkflow()rejects cycles and unknown dependencies before execution. - A rejection in the last round fails the loop task with
LoopTaskExhausted. - To save task results in a checkpoint, use values that can be restored from JSON without loss. Class instances, streams and handles do not meet this requirement.
- A workflow does not push, merge or deploy anything by itself. Those steps stay in your tasks.
API: defineTask · defineWorkflow · defineLoopTask · TaskContext · WorkflowResult · WorkflowFailure · defineJsonResponse.