Skip to main content

What This Example Shows

  • A SequentialWorkflow chaining four clinical-research specialist agents: Literature Reviewer, Clinical Trial Analyst, Evidence Synthesizer, and Recommendations Editor
  • How to reuse a rigorous clinical-research system prompt (MED_SYS_PROMPT) as the basis for every agent’s voice
  • A concrete worked example on a stage III pancreatic adenocarcinoma evidence question
  • How to fan the same pipeline across an overnight queue of research questions via /v1/swarm/batch/completions for the 50% night-mode discount
  • A regulated-industry-friendly artifact: per-agent audit trail in the swarm log, plus an explicit reviewer checklist for the licensed clinician
This pipeline is for research and development only. It is not for direct clinical decision-making without licensed-physician review. Output must be reviewed and signed off by a qualified clinician before it informs any patient care, formulary decision, or published material.

Why This Matters

A pharma medical-affairs analyst, a payer policy researcher, or a hospital evidence-review team is paid $200-$400 per hour to produce exactly this artifact: a structured memo that answers “what does the evidence say, and what should we do?” for a single clinical question. The job typically runs 4-8 billable hours per memo — $800 to $3,200 of loaded labor — plus a one-to-two week turnaround that bottlenecks downstream decisions like formulary inclusion, payer policy updates, and KOL outreach. This pipeline produces the same shape of first draft in roughly a minute for about a dollar. The licensed reviewer keeps the role they actually add value in: signing off.

Step 1: Get Your API Key

  1. Visit https://swarms.world/platform/api-keys
  2. Sign in or create an account
  3. Generate a new API key
  4. Set it as an environment variable:

Step 2: Install Dependencies

Step 3: Configure the Client

Step 4: Anchor the Pipeline on a Rigorous System Prompt

Every agent in this pipeline is a variation on one rigorous clinical-research persona. Define it once and reuse it across the chain so the voice, evidence standards, and citation discipline stay consistent end to end.

Step 5: Define the Clinical Research Question

A concrete, defensible question is the most important input. Vague prompts get vague memos. The example below targets stage III pancreatic cancer — an active area of evidence and a real question medical-affairs and payer teams ask every week.

Step 6: Define the Four-Agent Pipeline

Each agent owns one phase of the memo and inherits the shared MED_SYS_PROMPT plus a lane-specific addendum. The SequentialWorkflow passes the previous agent’s output as upstream context, so the Trial Evaluator critiques what the Research Specialist surfaced, the Treatment Recommender builds on that critique, and the Risk/Compliance Reviewer audits the whole chain.
The Clinical Research Specialist and Evidence Synthesizer run on gpt-4.1 at low temperature (0.3) for repeatable structured output. The Clinical Trial Analyst and Recommendations Editor run on anthropic/claude-opus-4-8 — Opus reasoning is well-suited to critical appraisal and final editorial review. The temperature field is intentionally omitted for the Opus 4.8 agents (the API drops it before forwarding to Anthropic; see the Claude Opus 4.8 example).

Step 7: Run the Pipeline

Step 8: Verify the Editor Verdict and Persist the Audit Trail

The Recommendations Editor is the last agent in the chain, so its output is the last entry in result["output"]. Gate downstream delivery on its verdict, then write the full per-agent log to disk for the audit record.
Persist the full per-agent log so the credentialed reviewer has a defensible audit record before they sign off:
That JSON is your evidence that the memo was produced from a specific question, in a specific agent order, at a specific moment. Pair it with the reviewer’s sign-off and you have a defensible record.

Step 9: Overnight Queue with /v1/swarm/batch/completions

Medical-affairs and policy teams rarely have just one open question. The same pipeline can be fanned across a queue of questions in a single API call using /v1/swarm/batch/completions. Scheduled overnight (8 PM to 6 AM Pacific) the platform also applies a 50% night-time discount on token costs (see calculate_swarm_cost in api/swarm_completions.py).
The batch endpoint accepts a JSON array where every item is a full SwarmSpec — identical to the body you pass to /v1/swarm/completions. Items run in parallel server-side, so a 4-question queue does not take 4x the wall-clock time. Pair this with a scheduled job that fires after 8 PM Pacific and the entire queue runs on the night-time discount.

Per-Query Cost vs. Consultant Time

A medical-research analyst inside pharma medical affairs, a payer policy team, or a hospital evidence-review office bills $200-$400 per hour and typically spends 4-8 hours per memo of this shape. The same first draft from this pipeline lands in roughly a minute for about a dollar, even before the night-mode discount. The pipeline does not replace the clinician — it relocates them from drafting to reviewing, which is both faster and higher-leverage.

Adapting the Pipeline

Replace the question and tighten the prompts to retarget: The pipeline shape, billing, and response schema stay identical.

Common Pitfalls

Tighten the Evidence Synthesizer’s prompt to explicitly cite the evidence-strength rating from the Clinical Trial Analyst and to avoid universal claims (“all patients with stage III pancreatic cancer should…”) in favor of population-scoped claims (“guideline-eligible patients with ECOG 0-1 and adequate organ function…”). The editor is doing its job — your upstream prompt is over-claiming.
Increase max_tokens on the Clinical Research Specialist and Evidence Synthesizer to 8192, and add domain anchors to the question (“for a 68-year-old with borderline-resectable stage III pancreatic adenocarcinoma, ECOG 1, CA 19-9 320…”). Sequential pipelines amplify upstream specificity — vague input compounds into vague output.
Pair this pipeline with the Swarm Logs endpoint to maintain a full audit trail of every prompt, every agent output, and every reviewer verdict tied to your API key. Most regulated medical-affairs programs require that trail; the API gives it to you for free.

Next Steps