Skip to main content

What This Example Shows

  • A real production DAG: an SDR (sales development) enrichment pipeline with three parallel research branches that converge into synthesis and scoring nodes
  • How to express fan-out → fan-in graphs with edges, entry_points, and end_points
  • Why this beats stacking SequentialWorkflow + ConcurrentWorkflow (single round-trip, server-side concurrency, single billing event)
  • How to read per-node outputs from the response so you can persist branch outputs to your CRM
  • Patterns for retries and conditional paths via downstream gating
The Graph Workflow endpoint (POST /v1/graph-workflow/completions) is a premium-only feature available on Pro, Ultra, and Premium plans. Free tier keys receive a 403. Upgrade your account to run production DAGs on the Swarms API.

Why This Matters

Sales teams burn the first 20 minutes of every cold outreach reading three different tabs — LinkedIn for the buyer, Crunchbase for the company, and a news search for the trigger event. Then somebody distills it into a one-line pitch hook, somebody else scores the lead, and only then does the SDR send. That sequence is a DAG, not a chain: the three lookups are independent of each other, but they all block the synthesis step, which blocks the scoring step. A Graph Workflow lets you describe that DAG once and have the platform run the three lookups in parallel, fan them into the synthesis node, then feed scoring — in a single API call with one billing event. You stop maintaining glue code that orchestrates async tasks, and your SDR pipeline runs 3-5x faster than the sequential version.

Step 1: Setup

Step 2: Sketch the Graph Before You Code It

The graph for an SDR enrichment looks like this:
Three independent researchers (parallel) → synthesizer (waits for all three) → scorer (waits for synthesis). Three edges into the synthesizer, one edge out to the scorer.
Always draw the graph on paper before encoding it. The edges and entry_points/end_points fields are mechanical once the picture is right — and almost always wrong when they aren’t.

Step 3: Define the Agents

Each node is a specialist. Researchers are tuned low-temperature for factual recall; the synthesizer runs slightly warmer to write copy; the scorer is the coldest of all because we want a deterministic verdict.

Step 4: Wire the Edges

Three fan-in edges, one straight edge. The entry_points are the three researchers (no upstream dependencies); the end_point is the scorer (no downstream dependencies).

Step 5: Submit the Workflow

Step 6: Read the Per-Node Output

Every node’s output is keyed by agent_name under outputs. Persist them individually — the buyer profile belongs on the contact record, the company profile on the account record, the pitch in the sequencer, the score in the CRM lead-scoring column.

Why This Beats Sequential + Concurrent Stacking

You could build the same pipeline by calling ConcurrentWorkflow for the three researchers, manually stitching their outputs into a prompt, then calling SequentialWorkflow for synthesis → scoring. That works. It’s also worse:

Adding Conditional Paths and Retries

Two production patterns to layer on top: Conditional gating (early exit on cold leads). Add a Qualifier node before the heavy research and let the synthesizer’s prompt instruct it to output “SKIP” if the lead score’s company profile fails a hard filter (e.g., < 50 employees, US-only). Downstream nodes still run, but their prompts can be written to no-op when they see “SKIP” upstream. Retries on a flaky node. auto_compile: true pre-validates the graph (auto-setting entry/end points, checking structure) and caches the compiled execution plan — it does not retry failed nodes. If a node fails, its output in outputs becomes the string "[ERROR] Agent <name> failed: ...", downstream nodes still run on that text, and the request returns 200. The failed node pays no agent fee and its error text isn’t billed. Only when every node fails does the request return an error (404, 400, 429 or 502, following the provider) with nothing charged. So check outputs for [ERROR] values and retry the request if a node you need failed. What you can do per-node is raise that agent’s own max_loops, which gives it more internal iterations to recover from a bad tool call or malformed output within its own run before handing off to downstream nodes — that’s agent-level resilience, not graph-level, automatic retry-on-failure.

Scaling the Pattern

Drop in any production DAG by swapping the node prompts: Everything else — request shape, response shape, billing, retries — stays identical.

Cost vs. Building It Yourself

Concrete numbers from a real SDR team enriching 1,000 leads per week: Math: 1,000 leads/week at $22 manual vs. $0.03 on the endpoint is $22,000/week saved ($1.1M/year), before counting the engineering team you don’t need to staff for the DIY path. The pipeline goes live in a day instead of a quarter.
Per-lead cost will vary with model choice and token volume — gpt-4.1 on five short nodes is the cheap path; swap to claude-opus-4-8 (premium-only) if your synthesizer needs deeper reasoning.

Next Steps