What This Example Shows
- A
SequentialWorkflowchaining 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/completionsfor 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
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
- Visit https://swarms.world/platform/api-keys
- Sign in or create an account
- Generate a new API key
- 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 sharedMED_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 inresult["output"]. Gate downstream delivery on its verdict, then write the full per-agent log to disk for the audit 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/utils.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.| Method | Time per memo | Cost per memo |
|---|---|---|
| Medical research analyst at $200/hr × 4 hrs | 4 hours | $800 |
| Medical research analyst at $400/hr × 8 hrs | 8 hours | $3,200 |
| This pipeline (single query) | ~1 minute | ~$1 |
| This pipeline (4-question overnight batch, night-mode discount) | ~1-2 minutes wall time | a few dollars total |
| This pipeline + 30 min physician sign-off | ~32 minutes | ~$150 |
Adapting the Pipeline
Replace the question and tighten the prompts to retarget:| Domain | Agent 1 | Agent 2 | Agent 3 | Agent 4 |
|---|---|---|---|---|
| Drug-class deep dive | Literature Synthesizer | Trial Evaluator | Treatment Recommender | Compliance Reviewer |
| Pharmacovigilance review | Signal Detector | Causal Assessor | Mitigation Designer | Regulatory Reviewer |
| Formulary decision memo | Evidence Aggregator | Cost-Effectiveness Analyst | Formulary Recommender | P&T Compliance Reviewer |
| CME content drafting | Topic Researcher | Evidence Critic | Module Writer | Accreditation Reviewer |
Common Pitfalls
The Recommendations Editor always says 'Revision required'
The Recommendations Editor always says 'Revision required'
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.
The output is generic and not 'clinical-sounding'
The output is generic and not 'clinical-sounding'
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.Where does this fit in our compliance program?
Where does this fit in our compliance program?
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
- See the Clinical Case Conference example for the hierarchical (parallel-specialist) variant of this pattern
- See Hospital Team for a discharge-planning-focused multi-agent workflow
- Read the Production Readiness Checklist before shipping this pipeline to a regulated production environment