import os
from swarms_client import SwarmsClient
client = SwarmsClient(api_key=os.environ["SWARMS_API_KEY"])
# A sequential workflow: each agent receives the previous agent's output.
# Send de-identified text only. Every output is a draft for a clinician.
response = client.swarms.run(
name="ED Intake Pipeline",
description="Intake summary, proposed acuity, draft note and candidate codes for clinician review.",
swarm_type="SequentialWorkflow",
task=(
"Intake form, de-identified. 54-year-old, chest tightness for 2 hours "
"while climbing stairs, now resolved at rest. History: hypertension, "
"smoker. Vitals: HR 96, BP 152/94, SpO2 97%, temp 37.1 C. Takes "
"amlodipine. No allergies recorded."
),
agents=[
{
"agent_name": "Intake Reader",
"description": "Structures the raw intake form.",
"system_prompt": (
"You read emergency department intake forms. Return the chief "
"complaint, onset and duration, vitals, relevant history and "
"medications as labelled fields. Do not add anything that is not "
"in the form."
),
"model_name": "gemini-2.5-flash", # fast extraction, no reasoning needed
"max_loops": 1,
},
{
"agent_name": "Triage Agent",
"description": "Proposes an acuity level for the triage nurse.",
"system_prompt": (
"You support emergency triage nurses. From the structured intake, "
"propose an Emergency Severity Index level from 1 to 5 and list the "
"specific findings that drove it, including any red flags. State "
"plainly that the triage nurse assigns the final level."
),
"model_name": "gpt-5.4", # stronger model for the judgement call
"max_loops": 1,
},
{
"agent_name": "Note Drafter",
"description": "Drafts the visit note sections.",
"system_prompt": (
"You draft emergency visit notes for a physician to edit and sign. "
"Write HPI, pertinent history, vitals and an assessment that lists "
"differentials to consider, never a diagnosis. Mark every missing "
"element as [CLINICIAN TO COMPLETE]."
),
"model_name": "claude-sonnet-5-5",
"max_loops": 1,
},
{
"agent_name": "Coding Agent",
"description": "Lists candidate ICD-10-CM codes.",
"system_prompt": (
"You assist certified medical coders. From the draft note, list up "
"to three candidate ICD-10-CM codes with the exact note text that "
"supports each and a confidence from 0 to 1. The coder selects the "
"final codes."
),
"model_name": "gpt-4.1-mini",
"max_loops": 1,
},
],
max_loops=1,
)
# The whole response: the draft package plus the usage block.
print(response)