Your First Workflow

Build a multi-step AI workflow in under 5 minutes. No cloud account required.

Quick Start

RelayPlane is a local-first workflow engine for building multi-step AI workflows with explicit provider:model selection. Let's create your first workflow using the step → with → depends → run pattern.

1npm install @relayplane/workflows

Minimal Example

Here's a complete local-first workflow that processes invoices using vision and language models:

1import { relay } from "@relayplane/workflows";
2
3const result = await relay
4 .workflow("invoice-processor")
5 .step("extract").with("openai:gpt-4o-vision")
6 .step("summarize").with("anthropic:claude-3.5-sonnet").depends("extract")
7 .run({ fileUrl: "https://example.com/invoice.pdf" });
8
9console.log(result.steps.summarize);

Local-first by default. This workflow runs entirely on your machine using your own API keys. No RelayPlane cloud account required.

How It Works

RelayPlane workflows follow a simple pattern:

  1. Define steps - Each .step() represents a discrete AI operation
  2. Assign models - Use .with() to specify provider:model
  3. Set dependencies - Chain steps with .depends()
  4. Execute - Run the workflow with .run(input)

The RelayPlane workflow engine handles orchestration, dependency resolution, and result aggregation automatically.

Full Example with Schema

For production workflows, add structured output validation using Zod schemas:

1import { relay } from "@relayplane/workflows";
2import { z } from "zod";
3
4// Define structured output schema
5const InvoiceSchema = z.object({
6 invoiceNumber: z.string(),
7 vendor: z.string(),
8 totalAmount: z.number(),
9 items: z.array(z.object({
10 description: z.string(),
11 quantity: z.number(),
12 unitPrice: z.number(),
13 })),
14});
15
16// Build multi-step workflow
17const result = await relay
18 .workflow("invoice-processor")
19
20 // Step 1: Extract structured data from image
21 .step("extract", {
22 schema: InvoiceSchema,
23 systemPrompt: "Extract all invoice fields as structured JSON.",
24 })
25 .with("openai:gpt-4o-vision")
26
27 // Step 2: Validate and summarize
28 .step("summarize", {
29 systemPrompt: "Create a brief summary for finance approval.",
30 })
31 .with("anthropic:claude-3.5-sonnet")
32 .depends("extract")
33
34 .run({
35 fileUrl: "https://example.com/invoice.pdf"
36 });
37
38// Access step outputs
39console.log("Extracted data:", result.steps.extract);
40console.log("Summary:", result.steps.summarize);

Setting Up API Keys

RelayPlane needs API keys for the AI providers you want to use. Set them as environment variables:

1# .env.local
2OPENAI_API_KEY=sk-...
3ANTHROPIC_API_KEY=sk-ant-...
4GOOGLE_API_KEY=...
5GROQ_API_KEY=...

Or configure them programmatically:

1import { relay } from "@relayplane/workflows";
2
3relay.configure({
4 providers: {
5 openai: { apiKey: process.env.OPENAI_API_KEY },
6 anthropic: { apiKey: process.env.ANTHROPIC_API_KEY },
7 },
8});

Running Your Workflow

Save your workflow to a file (e.g., workflow.ts) and run it:

1npx tsx workflow.ts

That's it! Your first multi-step AI workflow is running locally.

Best Practices

  • Use explicit provider:model format - "openai:gpt-4o" not just "gpt-4"
  • Add schemas for structured output - Zod schemas provide type safety and validation
  • Chain steps with .depends() - Clear dependency graphs make workflows easier to debug
  • Keep steps focused - Each step should do one thing well
  • Use system prompts - Guide model behavior with clear instructions

Common Mistakes

  • Missing provider prefix - Always use provider:model format, not just model name
  • Circular dependencies - Avoid creating dependency cycles between steps
  • Missing API keys - Set environment variables before running workflows
  • Not handling errors - Wrap workflows in try/catch for production use

Next Steps

See Also