import os
from swarms_client import SwarmsClient
client = SwarmsClient(api_key=os.environ["SWARMS_API_KEY"])
# A HeavySwarm runs four stages in order: question, research, analysis,
# synthesis. The alert cluster and the related events are pasted in; in
# production an integration builds this string from the SIEM. No agent here
# has access to a console, a credential or a containment action.
ALERT_CLUSTER = """
Cluster INC-2026-0419, first seen 2026-11-06 02:14 UTC, 7 alerts, 3 hosts.
- EDR: lsass.exe memory read by an unsigned binary on WKS-2231 (user j.alvarez)
- EDR: same binary hash on WKS-2240 and SRV-FILE-03 within 11 minutes
- SIEM: 4 failed then 1 successful logon for svc_backup from WKS-2231 to SRV-FILE-03
- SIEM: scheduled task created on SRV-FILE-03 named 'WindowsUpdateCheck'
- Proxy: 38 MB POST from SRV-FILE-03 to a domain registered 9 days ago
- Mail: j.alvarez opened an attachment 'Invoice_Q4.pdf.lnk' at 01:58 UTC
"""
response = client.swarms.run(
name="Incident Investigation INC-2026-0419",
description="Question, research, analysis and synthesis on one alert cluster.",
swarm_type="HeavySwarm",
task=(
"Investigate the alert cluster below. Establish the likely sequence of "
"events, map every indicator to a tactic and technique with the evidence "
"for each mapping, list what is still unknown, and draft an incident report "
"in sections: summary, timeline, affected assets, technique mapping, open "
"questions, recommended next steps for the analyst. Mark the report DRAFT.\n"
+ ALERT_CLUSTER
),
agents=[
{
"agent_name": "Question Agent",
"description": "Frames the questions the investigation must answer.",
"system_prompt": "You are an incident commander. From the alerts, write the specific questions that must be answered to understand initial access, scope, persistence and exfiltration. Do not speculate on answers.",
"model_name": "gpt-5.4-mini", # framing is short, a fast model is enough
"max_loops": 1,
},
{
"agent_name": "Research Agent",
"description": "Gathers related events and indicator context.",
"system_prompt": "You are a threat researcher. For each question, pull together the related events from the cluster, what is known about each indicator (hash, domain, task name) and the gaps. Cite the alert line you rely on.",
"model_name": "gemini-2.5-pro", # long context across many events
"max_loops": 1,
},
{
"agent_name": "Analysis Agent",
"description": "Maps indicators to tactics and techniques.",
"system_prompt": "You are a detection analyst. Map every indicator to a tactic and a technique, give the evidence for each mapping and a confidence of low, medium or high. Build the most likely timeline.",
"model_name": "claude-sonnet-5-5",
"max_loops": 1,
},
{
"agent_name": "Synthesis Agent",
"description": "Writes the draft incident report.",
"system_prompt": "You write incident reports for a security operations team. Use the sections requested, keep claims tied to evidence, list the open questions plainly and end with recommended next steps that the analyst, not you, will approve.",
"model_name": "claude-opus-5-5", # the report is the deliverable
"max_loops": 1,
},
],
max_loops=1,
)
print(response)