Skip to main content
The HeavySwarm is a multi-agent orchestration system inspired by X.AI’s Grok Heavy implementation. It decomposes a task into role-specific questions, runs those questions through specialized expert agents in parallel, and then synthesizes the outputs into a single comprehensive answer. The exact set of experts is controlled by the variant parameter.

When to Use

  • Complex research tasks — in-depth investigation across multiple angles
  • Financial analysis — investment decisions requiring multiple viewpoints
  • Strategic planning — comprehensive evaluation of options and trade-offs
  • Due diligence — thorough verification and risk assessment
  • Multi-faceted problems — issues that need research, analysis, and synthesis combined

Key Features

  • Intelligent question generation tailored to each agent role, with its own decomposer per variant
  • Image-aware decomposition: pass img and the questions are written from what the image shows
  • Three preset variants — default (5 agents), medium (4 Grok-style agents), heavy (16 agents)
  • Parallel execution on a thread pool; each worker runs the autonomous loop on its question
  • Synthesis agent that integrates expert outputs into a final answer
  • Token usage summed across question generation and every agent, via usage
  • Optional real-time rich dashboard
  • Multi-loop iterative refinement (each loop builds on the previous result)
  • Tool integration through worker_tools
  • Inherits SerializableMixin — to_dict() is available for telemetry / persistence

Architecture

Basic Example

With Tool Integration

Selecting a Variant

The variant parameter controls which agents are instantiated.
SwarmVariant is exported from swarms.agents.heavy_swarm_agents. Passing an unknown variant raises ValueError during initialization.

Specialized Agents (default variant)

Research Agent

  • Comprehensive information gathering
  • Data collection and validation
  • Source verification
  • Literature review
  • Statistical data interpretation

Analysis Agent

  • Pattern recognition
  • Statistical analysis
  • Predictive modeling
  • Data interpretation
  • Performance metrics

Alternatives Agent

  • Strategic thinking
  • Creative problem-solving
  • Option generation
  • Trade-off evaluation
  • Scenario planning

Verification Agent

  • Fact-checking
  • Feasibility assessment
  • Risk analysis
  • Compliance verification
  • Quality assurance

Synthesis Agent

  • Multi-perspective integration
  • Comprehensive analysis
  • Executive summary creation
  • Strategic alignment
  • Actionable recommendations

Key Parameters

str
default:"HeavySwarm"
Identifier for the swarm instance.
str
Description of the swarm’s purpose.
int
default:"900"
Seconds passed to each worker future’s result() call. Results are read as workers finish, so it does not interrupt a running worker.
str
default:"gpt-5.4"
Model used by the question-generation agent.
str
default:"gpt-5.4"
Model used by every agent the variant builds, including the synthesis agent or captain.
bool
default:"False"
Enable detailed logging output.
bool
default:"False"
Enable the real-time rich progress dashboard.
bool
default:"False"
Print each specialist worker’s output. The synthesis agent or captain always prints.
str
default:"dict-all-except-first"
Format of the returned conversation history.
Optional[tool_type]
Tools made available to every agent the variant builds.
int
default:"1"
Number of full swarm iterations. Each loop refines the previous synthesis.
Literal["default", "medium", "heavy"]
default:"\"default\""
Which agent line-up to instantiate. See Selecting a Variant above.

Methods

run(task, img=None)

Execute the full multi-phase workflow.
Each call clears the swarm’s conversation first, so the returned transcript covers only the current task.

usage

Provider token counts summed over question generation and every agent, including the synthesis agent or captain. The total keeps growing across loops and run() calls. See Token usage.

get_questions_only(task, img=None) and get_questions_as_list(task, img=None)

Run only the decomposer and return its questions as a dict of *_question keys or as an ordered list. Useful for previewing what each worker will be asked.

to_dict()

Inherited from SerializableMixin. Returns a JSON-friendly snapshot of the swarm’s config. The agents, conversation, dashboard, and worker_tools attributes are excluded via _to_dict_exclude to keep the snapshot lightweight.

Question Generation

The question agent emits a JSON object whose schema depends on the variant. For the default variant it looks like:
The "medium" and "heavy" variants return one <name>_question key per specialist instead, such as harper_question. Each variant has its own decomposer prompt and schema, and the decomposer sends no temperature or top-p, so it also runs on Anthropic models. When you pass img, the decomposer is told an image accompanies the task and reads it. Example generated questions for “Invest in NVIDIA?”:

Multi-Loop Refinement

With max_loops > 1 the swarm iterates, each loop feeding the previous synthesis back as context:
Per-loop semantics:
  1. Loop 1: original task only
  2. Loop 2: "Previous loop results: <output>\n\nOriginal task: <task>\n\n" followed by an instruction to refine and build on the previous loop
  3. Loop 3: same shape — refine, fill gaps, deepen the analysis
The conversation is kept across loops within one run(), so a later synthesis also sees the earlier loops’ questions and answers.

Dashboard Features

When show_dashboard=True, the HeavySwarmDashboard renders rich progress panels: Configuration Panel:
  • Swarm name and description
  • Model configuration (question + worker)
  • Timeout and worker counts
Reliability Check Phase:
  • Animated progress bars
  • Per-component validation status
Question Generation Phase:
  • Real-time generation progress
Agent Execution Phase:
  • Per-agent progress bars
  • Status (INITIALIZING, PROCESSING QUERY, EXECUTING, GENERATING RESPONSE, COMPLETE, or ERROR / TIMEOUT)
  • Variant-aware agent labels
Synthesis Phase:
  • Integration progress
  • Final report generation
  • Completion confirmation

Use Cases

Investment Analysis

Market Research with Live Web Data

Strategic Planning

Heavy Variant for Deep Research

Performance Notes

Parallel Execution

All workers fan out on a thread pool that carries the tracing context into each thread. self.max_workers is set to int(os.cpu_count() * 0.9); it is not a constructor parameter.

Timeout

The timeout is passed to future.result() after as_completed() has already returned that future, so it does not cut a slow worker short.

Verbose Logging

Output Structure

The swarm returns the conversation history formatted by output_type. The default "dict-all-except-first" returns a list of message dicts, without the initial task message:
Worker messages appear in the order the workers finished. Each message also carries timestamp, message_id and category keys. Use output_type="final" to get only the synthesis.

Best Practices

Model Selection: use stronger models (Claude Sonnet, GPT-5.4) for worker agents on complex tasks.
  1. Question Quality — a stronger question-generation model produces tighter, less overlapping expert questions.
  2. Worker Models — balance cost vs quality for the worker pool; mixing providers via LiteLLM works out of the box.
  3. Loop Count — start at max_loops=1. Add more only when the synthesis clearly needs refinement.
  4. Variant Choice — default covers most tasks; reach for heavy only when you genuinely benefit from 15+ specialist perspectives.
  5. Dashboard — leave on for demos and debugging; off for production.
  6. Tools — supply worker_tools when the task requires real-time data (search, web fetch, etc.).
HeavySwarm is resource-intensive. Each loop runs N expert agents + a question generator + a synthesizer. Token costs scale roughly linearly with both variant and max_loops.

Reliability Checks

reliability_check() runs automatically during __init__:
When show_dashboard=True, the validation steps animate through the dashboard. Otherwise a single confirmation panel prints. An unknown variant raises ValueError before this check, when __init__ builds the agents.

Conversation History

Access the full transcript through the conversation object:

Error Handling

run() does not raise when a phase fails. It logs the error and returns a message string instead of the formatted conversation:
If a single worker raises, the error is logged, that worker’s answer is left out of the conversation, and the other workers and the synthesis still run.