Skip to content
Français

Connect tasks and dependencies

Define tasks, declare what they depend on and read their typed results.

The first example runs entirely in Node.js: install Outpost in an ESM project, save it as dependencies.ts and run node dependencies.ts. No agent, account or sandbox is needed to learn the graph.

Declare each step with a task constructor, then give the tasks to defineWorkflow(). Dependencies determine execution order and which earlier results a task may read.

Declare named inputs when the task consumes dependency results. Outpost adds those tasks to after and supplies their typed values to perform. Keep after for ordering-only dependencies; duplicate tasks are added once. The dependency mapping is copied when the task is defined.

import { defineTask, defineWorkflow } from "@elie-laloum/outpost/workflows";

const files = defineTask({ key: "files", perform: () => ["src/parser.ts"] });
const report = defineTask({
  key: "report",
  inputs: { files },
  perform: ({ inputs }) => ({ reviewed: inputs.files.length }),
});
const result = await defineWorkflow("review", [files, report]).start();
result.unwrap();
console.log(result.value(report));
// Example output: { reviewed: 1 }

It prints { reviewed: 1 }. defineTask() and defineWorkflow() only declare the graph: nothing runs until start().

List a task in after, then read its output with context.value(task). The value keeps the type returned by that task’s perform.

context.value() throws for a task missing from after, even if it already ran. A task starts only once every task in its after list is done.

defineWorkflow() checks the graph before anything runs and throws on the first error.

MistakeError
Two tasks share a keyDuplicate task: test
A task in after is not in the workflow’s listpublish: missing dependency lint
Tasks depend on each other in a loopDependency cycle at report
A key does not match [A-Za-z0-9][A-Za-z0-9._-]*Invalid task key: …, from defineTask()

start() resolves with a WorkflowResult once no task can run any more, even when tasks failed. It rejects when an option is invalid or a checkpoint cannot be saved.

import { defineTask, defineWorkflow } from "@elie-laloum/outpost/workflows";

const lint = defineTask({
  key: "lint",
  perform: () => {
    throw new Error("2 lint errors");
  },
});
const test = defineTask({ key: "test", perform: () => "ok" });
const result = await defineWorkflow("checks", [lint, test]).start();
console.log(result.status);
// Example output: failed
for (const task of result.tasks)
  console.log(task.key, task.status, task.error ?? "");
// Example output: lint failed 2 lint errors

It prints failed, then lint failed 2 lint errors and test cancelled: by default, the first failure cancels the tasks that have not finished.

API reference: WorkflowResult and TaskRecord.

Independent tasks can run together when you increase concurrency. Start with the parallelism and retries guide for a working example. Tasks that share a sandbox must remain sequential; connect them with after.

Use condition when a task only makes sense for some inputs. A false condition skips the task and its dependents, and produces no value. See the conditional task example before reading such a result.

diagram() returns the graph as a Mermaid flowchart, for a README or a pull request.

import { defineTask, defineWorkflow } from "@elie-laloum/outpost/workflows";

const lint = defineTask({ key: "lint", perform: () => 0 });
const report = defineTask({ key: "report", after: [lint], perform: () => 0 });
console.log(defineWorkflow("checks", [lint, report]).diagram());
// Example output: flowchart LR
flowchart LR
  n0["lint"]
  n1["report"]
  n0 --> n1

To run tasks against the same files, follow Share a sandbox.

Start with the declaration that matches who owns the work.

Your step needsUse
Your own functiondefineTask
An agent with its own sandboxdefineIsolatedTask
An agent or command in an open sandboxdefineAgentTask or defineCommandTask
Another attempt after a failed checkA verification loop

Add approvals, human questions, queued work or artifacts when those steps become necessary.

  • Outputs live in memory for one start(). A restarted run reruns every task unless you pass a checkpoint.
  • Approval and pause tasks, interactive tasks, quota pauses, answers and decisions require a checkpoint: start() throws without one.
  • A workflow does not commit, merge or push across tasks as one transaction. To change several repositories, see Multiple repositories.

API: defineTask · defineWorkflow · TaskContext · WorkflowResult · TaskRecord · WorkflowFailure