Skip to main content

workflows/quickstart.tsx

Ghost doc — This is a real script found at workflows/quickstart.tsx in the Smithers repository. It demonstrates a multi-agent sequential workflow with structured output and cross-task data flow.

Source

// workflows/quickstart.tsx
import { createSmithers, Sequence, Task, Workflow } from "smithers-orchestrator";
import { ToolLoopAgent as Agent, Output } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";

const { smithers, outputs } = createSmithers({
  plan: z.object({
    summary: z.string(),
    steps: z.array(z.string()),
  }),
  brief: z.object({
    brief: z.string(),
    stepCount: z.number(),
  }),
});

const planAgent = new Agent({
  model: anthropic("claude-sonnet-4-5-20250929"),
  output: Output.object({
    schema: z.object({
      summary: z.string(),
      steps: z.array(z.string()).min(3).max(8),
    }),
  }),
  instructions:
    "You are a planning assistant. Return a concise summary and 3-8 actionable steps.",
});

const briefAgent = new Agent({
  model: anthropic("claude-sonnet-4-5-20250929"),
  output: Output.object({
    schema: z.object({
      brief: z.string(),
      stepCount: z.number().int().min(1),
    }),
  }),
  instructions:
    "You are a concise technical writer. Produce a 5-8 sentence brief.",
});

export default smithers((ctx) => {
  const planOutput = ctx.outputMaybe("plan", { nodeId: "plan" });

  return (
    <Workflow name="quickstart">
      <Sequence>
        <Task id="plan" output={outputs.plan} agent={planAgent}>
          {`Create a short plan for this goal:\n${ctx.input.goal}`}
        </Task>
        <Task id="brief" output={outputs.brief} agent={briefAgent}>
          {`Goal: ${ctx.input.goal}
Plan summary: ${planOutput?.summary ?? "pending"}
Steps: ${JSON.stringify(planOutput?.steps ?? [])}

Write a brief based on the plan. The "stepCount" must equal the number of steps.`}
        </Task>
      </Sequence>
    </Workflow>
  );
});

Running

smithers run workflows/quickstart.tsx --input '{"goal": "Build a CLI tool for managing dotfiles"}'
Output:
[quickstart] Starting run def456
[plan] Done -> { summary: "Build a dotfile manager CLI", steps: ["Parse config", "Symlink files", "Add backup"] }
[brief] Done -> { brief: "This plan covers 3 steps...", stepCount: 3 }
[quickstart] Completed

What This Demonstrates

  • Multi-agent pipeline — Two agents (planner and briefer) execute sequentially, with the second consuming the first’s output.
  • ctx.outputMaybe() cross-task data flow — The brief task reads the plan task’s persisted output via ctx.outputMaybe("plan", { nodeId: "plan" }). The first argument is the schema key (from createSmithers), not a table name.
  • Zod schemas — Both agents use Output.object({ schema }) for type-safe structured output with validation constraints (min(3).max(8)).
  • Vercel AI SDK agents — Uses ToolLoopAgent from the ai package with Anthropic provider.
  • outputs.plan / outputs.brief — The Zod schemas returned by createSmithers, passed to Task via the output prop to tell Smithers where to persist results.