NylorunDocsBeta
Get startedBuildRunDeployReferenceMore

Workflows

Compose agents, tools, and deterministic functions into durable runnable graphs.

A workflow is a registered runnable with kind: "workflow". It uses the same Tenant session API as an agent, but its manifest describes a graph of agent, tool, function, and verification nodes.

agents/report/agent.ts
import { Agent, Chain, tool } from "@nylorun/agents/define";
import { z } from "zod";

const researcher = Agent({
  id: "researcher",
  name: "Researcher",
  description: "Gathers concise findings.",
  instructions: "Research the topic and return { findings }.",
  outputSchema: z.object({ findings: z.string() }),
}).build();

const publish = tool({
  name: "publish",
  description: "Records finished findings.",
  input: z.object({ findings: z.string() }),
  output: z.object({ published: z.boolean() }),
  async run() {
    return { published: true };
  },
});

export const report = Chain({
  id: "report",
  steps: [
    researcher,
    {
      run: publish,
      input: ({ value }) => value,
    },
  ],
});

Export the workflow from the registry exactly as you export an agent:

agents/index.ts
import { report } from "./report/agent.js";

export const agents = [report];

Primitives

PrimitiveBehavior
ChainRuns steps in order; each result becomes the next step's value.
SwitchComputes a key and runs the matching case or default branch.
ParallelRuns a fixed object of named branches concurrently.
MapRuns one node per item concurrently and returns ordered results.
LoopRuns a node, verifies its output, and either returns or supplies the next input.

Primitives nest, so a Chain can contain a Map whose each node is a Loop. Runtime persists each node boundary and resumes from completed effects instead of repeating them.

Slots and data

A direct node receives the current value. Wrap it in a slot to give the node a stable id or reshape its input:

{
  id: "summarize",
  run: summarizer,
  input: ({ value, results, input }) => ({
    current: value,
    earlier: results.researcher,
    original: input,
  }),
}

value is the preceding node output, results contains completed keyed nodes, and input is the workflow's original turn input. Functions used for slot inputs, switch keys, map expansion, and loop decisions run as durable fn or verify executor actions.

Sessions and manifests

Use saveAgent, createSession, input, observe, pending, approve, and cancel exactly as for agents. Text agents accept content; workflows can also accept structured data. Saving a workflow first saves the agents it references.

Agent sessions can carry a turn-only message.manifest; see Sessions. Workflow sessions retain their workflow pin. Studio renders the workflow manifest tree, live node states, iterations, and links to child agent sessions.

All nodes in one workflow share the session sandbox. Cancelling the parent cancels active child work.

Examples

See the shipped chain, switch, parallel, map, loop, and ship-feature examples.

Next step

Start with Chain, or open Sessions to run a workflow and Studio to inspect its manifest and node progress.

On this page