import os
from swarms_client import SwarmsClient
client = SwarmsClient(api_key=os.environ["SWARMS_API_KEY"])
# A hierarchical swarm: the director plans, the analysts work in parallel,
# and the risk officer reviews before anything is returned.
response = client.swarms.run(
name="Equity Research Desk",
description="Director-led research on a single ticker with a risk sign-off.",
swarm_type="HierarchicalSwarm",
task=(
"Prepare an investment memo on NVDA ahead of earnings. Cover the macro "
"backdrop, fundamentals from the latest 10-Q, price and volume action, "
"and end with a position size and stop level the desk can act on."
),
agents=[
{
"agent_name": "Macro Analyst",
"description": "Rates, FX and sector rotation context.",
"system_prompt": (
"You are a macro strategist at a long/short fund. Explain how the "
"rates path, the dollar and sector flows affect the name. Be specific "
"and cite the data you rely on."
),
"model_name": "gemini-2.5-pro",
"max_loops": 1,
},
{
"agent_name": "Equity Analyst",
"description": "Fundamentals from filings and transcripts.",
"system_prompt": (
"You are a sell-side equity analyst. Extract revenue mix, gross margin "
"trend, guidance changes and capex from the latest filing. Flag anything "
"that changed since the prior quarter."
),
"model_name": "claude-haiku-5-5",
"max_loops": 1,
},
{
"agent_name": "Quant Analyst",
"description": "Momentum, volume and factor exposure.",
"system_prompt": (
"You are a quantitative analyst. Score momentum, relative volume and "
"factor exposures, and state the technical levels that matter into the print."
),
"model_name": "gpt-5.4-mini",
"max_loops": 1,
},
{
"agent_name": "Risk Officer",
"description": "Sizing, limits and stops.",
"system_prompt": (
"You are the desk risk officer. Given the analysts' views, propose a "
"position size in basis points of NAV, a stop level and the mandate "
"limits that apply. Reject the trade if the setup breaks a limit."
),
"model_name": "claude-sonnet-5-5",
"max_loops": 1,
},
],
max_loops=1,
)
# The memo, then the usage block billing is computed from.
print(response["output"])
print(response["usage"])