Skip to content

Commit 4c29806

Browse files
authored
Merge pull request #1499 from Steve-Dusty/feat/grok-heavy-agents
feat: add Grok 4.20 Heavy architecture agents to HeavySwarm
2 parents db2b8c8 + 812293e commit 4c29806

File tree

10 files changed

+1699
-385
lines changed

10 files changed

+1699
-385
lines changed

docs/swarms/structs/heavy_swarm.md

Lines changed: 203 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# HeavySwarm
22

3-
HeavySwarm is a sophisticated multi-agent orchestration system that decomposes complex tasks into specialized questions and executes them using four specialized agents: Research, Analysis, Alternatives, and Verification. The results are then synthesized into a comprehensive response.
3+
HeavySwarm is a sophisticated multi-agent orchestration system that decomposes complex tasks into specialized questions and executes them using specialized agents in parallel. The results are then synthesized into a comprehensive response.
44

5-
Inspired by X.AI's Grok 4 heavy implementation, HeavySwarm provides robust task analysis through intelligent question generation, parallel execution, and comprehensive synthesis with real-time progress monitoring.
5+
HeavySwarm supports two agent architectures:
6+
7+
- **Default mode** — 5 task-phase agents (Research, Analysis, Alternatives, Verification, Synthesis)
8+
- **Grok mode** (`use_grok_agents=True`) — 4 thinking-style agents inspired by the [Grok 4.20 Heavy architecture](https://x.com/elonmusk/status/2034710771075273177) (Captain Swarm, Harper, Benjamin, Lucas)
69

710
## Installation
811

@@ -30,15 +33,17 @@ print(result)
3033

3134
## Architecture
3235

33-
The HeavySwarm follows a structured 5-phase workflow:
36+
The HeavySwarm follows a structured workflow:
3437

3538
1. **Task Decomposition**: Complex tasks are broken down into specialized questions
3639
2. **Question Generation**: AI-powered generation of role-specific questions
37-
3. **Parallel Execution**: Four specialized agents work concurrently
40+
3. **Parallel Execution**: Specialized agents work concurrently
3841
4. **Result Collection**: Outputs are gathered and validated
3942
5. **Synthesis**: Integration into a comprehensive final response
4043

41-
### Agent Specialization
44+
### Default Mode — Task-Phase Agents
45+
46+
The default mode decomposes work by **task phase** — each agent handles a different stage of analysis.
4247

4348
| Agent | Role/Function |
4449
|-------|---------------|
@@ -48,6 +53,31 @@ The HeavySwarm follows a structured 5-phase workflow:
4853
| **Verification Agent** | Validation, feasibility assessment, and quality assurance |
4954
| **Synthesis Agent** | Multi-perspective integration and executive reporting |
5055

56+
**Flow:** LiteLLM question generator → 4 workers in parallel → Synthesis Agent
57+
58+
### Grok Mode — Thinking-Style Agents (`use_grok_agents=True`)
59+
60+
The Grok mode is inspired by the [Grok 4.20 Heavy architecture](https://x.com/elonmusk/status/2034710771075273177) and decomposes work by **thinking style** — each agent applies a fundamentally different cognitive approach.
61+
62+
| Agent | Specialization | Thinking Style |
63+
|-------|---------------|----------------|
64+
| **Captain Swarm** | Orchestration, task decomposition, conflict resolution, final synthesis | Structured, managerial |
65+
| **Harper** | Research and facts, evidence gathering, source verification, data grounding | Empirical, evidence-based |
66+
| **Benjamin** | Logic, math, and code — rigorous reasoning, numerical verification, stress-testing | Rigorous, analytical |
67+
| **Lucas** | Creative and divergent thinking, contrarian analysis, blind-spot detection, bias identification | Divergent, lateral |
68+
69+
**Flow:** Captain Swarm decomposes → Harper, Benjamin, Lucas work in parallel → Captain Swarm mediates conflicts and synthesizes
70+
71+
#### Key Differences from Default Mode
72+
73+
| Aspect | Default Mode | Grok Mode |
74+
|--------|-------------|-----------|
75+
| **Decomposition** | By task phase (research → analyze → verify) | By thinking style (facts vs logic vs creativity) |
76+
| **Agent count** | 5 (4 workers + 1 synthesizer) | 4 (3 specialists + 1 leader) |
77+
| **Synthesis** | Generic integration agent | Captain Swarm mediates conflicts between agents |
78+
| **Contrarian check** | Not present | Lucas specifically challenges assumptions and detects biases |
79+
| **Question schema** | 4 questions (research, analysis, alternatives, verification) | 3 questions (harper, benjamin, lucas) |
80+
5181
## API Reference
5282

5383
### HeavySwarm Class
@@ -73,6 +103,7 @@ HeavySwarm(
73103
worker_tools: Optional[tool_type] = None,
74104
random_loops_per_agent: bool = False,
75105
max_loops: int = 1,
106+
use_grok_agents: bool = False,
76107
)
77108
```
78109

@@ -94,7 +125,8 @@ HeavySwarm(
94125
| `output_type` | `str` | `"dict-all-except-first"` | Output formatting type for conversation history |
95126
| `worker_tools` | `Optional[tool_type]` | `None` | Tools available to worker agents for enhanced functionality |
96127
| `random_loops_per_agent` | `bool` | `False` | Enable random number of loops per agent (1-10 range) |
97-
| `max_loops` | `int` | `1` | Maximum number of loops when using random_loops_per_agent |
128+
| `max_loops` | `int` | `1` | Maximum number of execution loops for iterative refinement |
129+
| `use_grok_agents` | `bool` | `False` | Enable Grok 4.20 Heavy architecture with Captain Swarm, Harper, Benjamin, and Lucas agents instead of the default Research/Analysis/Alternatives/Verification agents |
98130

99131
##### Raises
100132

@@ -160,19 +192,35 @@ Generate and extract only the specialized questions without metadata or executio
160192

161193
**Returns:**
162194

163-
- `Dict[str, str]`: Clean dictionary containing only the questions:
195+
- `Dict[str, str]`: Clean dictionary containing only the questions.
196+
197+
**Default mode keys:**
164198
- `research_question` (str): Question for comprehensive information gathering
165199
- `analysis_question` (str): Question for pattern analysis and insights
166200
- `alternatives_question` (str): Question for exploring creative solutions
167201
- `verification_question` (str): Question for validation and feasibility
202+
203+
**Grok mode keys** (`use_grok_agents=True`):
204+
- `harper_question` (str): Question for evidence-based research and fact verification
205+
- `benjamin_question` (str): Question for logical reasoning and mathematical verification
206+
- `lucas_question` (str): Question for creative/contrarian analysis and blind-spot detection
207+
168208
- `error` (str): Error message if question generation fails (on error only)
169209

170210
**Example:**
171211

172212
```python
213+
# Default mode
173214
questions = swarm.get_questions_only("Analyze market trends for EVs")
174215
print(questions['research_question'])
175216
print(questions['analysis_question'])
217+
218+
# Grok mode
219+
grok_swarm = HeavySwarm(use_grok_agents=True, worker_model_name="gpt-4.1", question_agent_model_name="gpt-4.1")
220+
questions = grok_swarm.get_questions_only("Analyze market trends for EVs")
221+
print(questions['harper_question'])
222+
print(questions['benjamin_question'])
223+
print(questions['lucas_question'])
176224
```
177225

178226
##### `get_questions_as_list(task: str) -> List[str]`
@@ -187,11 +235,19 @@ Generate specialized questions and return them as an ordered list.
187235

188236
**Returns:**
189237

190-
- `List[str]`: Ordered list of 4 specialized questions:
238+
- `List[str]`: Ordered list of specialized questions.
239+
240+
**Default mode** (4 questions):
191241
- `[0]` Research question for comprehensive information gathering
192242
- `[1]` Analysis question for pattern analysis and insights
193243
- `[2]` Alternatives question for exploring creative solutions
194244
- `[3]` Verification question for validation and feasibility assessment
245+
246+
**Grok mode** (3 questions):
247+
- `[0]` Harper question for evidence-based research and fact verification
248+
- `[1]` Benjamin question for logical reasoning and mathematical verification
249+
- `[2]` Lucas question for creative/contrarian analysis and blind-spot detection
250+
195251
- Single-item list containing error message (on error)
196252

197253
**Example:**
@@ -252,13 +308,13 @@ except ValueError as e:
252308

253309
##### `create_agents() -> Dict[str, Agent]`
254310

255-
Create and cache the 4 specialized agents with detailed role-specific prompts.
311+
Create and cache specialized agents with detailed role-specific prompts. The agents created depend on the `use_grok_agents` setting.
256312

257313
**Parameters:**
258314

259315
- None
260316

261-
**Returns:**
317+
**Returns (default mode):**
262318

263319
| Key | Agent Instance | Description |
264320
|-----------------|-----------------------|---------------------------------------------|
@@ -268,17 +324,150 @@ Create and cache the 4 specialized agents with detailed role-specific prompts.
268324
| `'verification'`| Verification Agent | Verification Agent instance |
269325
| `'synthesis'` | Synthesis Agent | Synthesis Agent instance |
270326

327+
**Returns (Grok mode, `use_grok_agents=True`):**
328+
329+
| Key | Agent Instance | Description |
330+
|-------------|-----------------|------------------------------------------------------|
331+
| `'captain'` | Captain Swarm | Leader and orchestrator — handles decomposition and synthesis |
332+
| `'harper'` | Harper | Research and facts specialist |
333+
| `'benjamin'`| Benjamin | Logic, math, and code specialist |
334+
| `'lucas'` | Lucas | Creative and divergent thinking specialist |
335+
271336
**Example:**
272337

273338
```python
339+
# Default mode
274340
agents = swarm.create_agents()
275341
research_agent = agents['research']
276342
print(f"Research agent name: {research_agent.agent_name}")
343+
344+
# Grok mode
345+
grok_swarm = HeavySwarm(use_grok_agents=True, worker_model_name="gpt-4.1", question_agent_model_name="gpt-4.1")
346+
agents = grok_swarm.create_agents()
347+
print(f"Captain: {agents['captain'].agent_name}")
348+
print(f"Harper: {agents['harper'].agent_name}")
277349
```
278350

279351
## Examples
280352

281-
### Basic Usage
353+
### Grok Mode — Quick Start
354+
355+
```python
356+
from swarms.structs.heavy_swarm import HeavySwarm
357+
358+
# Enable Grok 4.20 Heavy architecture
359+
swarm = HeavySwarm(
360+
name="Grok Analysis Team",
361+
description="Multi-agent analysis with Grok-style agents",
362+
worker_model_name="gpt-4.1",
363+
question_agent_model_name="gpt-4.1",
364+
use_grok_agents=True,
365+
show_dashboard=True,
366+
)
367+
368+
# Captain Swarm decomposes the task, Harper/Benjamin/Lucas
369+
# work in parallel, then Captain synthesizes with conflict resolution
370+
result = swarm.run("Evaluate whether Tesla should expand into commercial trucking")
371+
print(result)
372+
```
373+
374+
### Grok Mode — Medical Research
375+
376+
```python
377+
from swarms.structs.heavy_swarm import HeavySwarm
378+
379+
swarm = HeavySwarm(
380+
name="Medical Research Team",
381+
worker_model_name="gpt-4.1",
382+
question_agent_model_name="gpt-4.1",
383+
use_grok_agents=True,
384+
loops_per_agent=2,
385+
show_dashboard=True,
386+
)
387+
388+
# Harper gathers clinical evidence, Benjamin verifies
389+
# statistical claims, Lucas challenges treatment assumptions
390+
result = swarm.run(
391+
"Analyze the latest research on GLP-1 receptor agonists "
392+
"for treating obesity: efficacy, long-term safety, cost-effectiveness, "
393+
"and potential off-label applications"
394+
)
395+
print(result)
396+
```
397+
398+
### Grok Mode — Strategic Analysis with Tools
399+
400+
```python
401+
from swarms.structs.heavy_swarm import HeavySwarm
402+
403+
def web_search(query: str) -> str:
404+
"""Search the web for information."""
405+
# Your search implementation
406+
...
407+
408+
swarm = HeavySwarm(
409+
name="Strategic Intel Team",
410+
worker_model_name="gpt-4.1",
411+
question_agent_model_name="gpt-4.1",
412+
use_grok_agents=True,
413+
worker_tools=[web_search],
414+
show_dashboard=True,
415+
timeout=600,
416+
)
417+
418+
# Harper uses tools for real-time fact-gathering,
419+
# Benjamin stress-tests the strategy mathematically,
420+
# Lucas identifies blind spots and contrarian opportunities
421+
result = swarm.run(
422+
"Should our company enter the Southeast Asian market in 2026? "
423+
"Consider regulatory environment, competitive landscape, "
424+
"logistics costs, and consumer behavior patterns."
425+
)
426+
print(result)
427+
```
428+
429+
### Grok Mode via SwarmRouter
430+
431+
```python
432+
from swarms.structs.swarm_router import SwarmRouter
433+
434+
router = SwarmRouter(
435+
name="GrokRouter",
436+
description="Router with Grok Heavy agents",
437+
swarm_type="HeavySwarm",
438+
heavy_swarm_worker_model_name="gpt-4.1",
439+
heavy_swarm_question_agent_model_name="gpt-4.1",
440+
heavy_swarm_use_grok_agents=True,
441+
)
442+
443+
result = router.run("Analyze the future of autonomous vehicles")
444+
print(result)
445+
```
446+
447+
### Grok Mode — Question Preview
448+
449+
```python
450+
from swarms.structs.heavy_swarm import HeavySwarm
451+
452+
swarm = HeavySwarm(
453+
worker_model_name="gpt-4.1",
454+
question_agent_model_name="gpt-4.1",
455+
use_grok_agents=True,
456+
)
457+
458+
# Preview what Captain Swarm will ask each specialist
459+
questions = swarm.get_questions_only("Should we migrate from PostgreSQL to CockroachDB?")
460+
print(f"Harper (facts): {questions['harper_question']}")
461+
print(f"Benjamin (logic): {questions['benjamin_question']}")
462+
print(f"Lucas (creative): {questions['lucas_question']}")
463+
464+
# Or as a list
465+
question_list = swarm.get_questions_as_list("Should we migrate from PostgreSQL to CockroachDB?")
466+
for i, q in enumerate(question_list):
467+
print(f"Agent {i+1}: {q}")
468+
```
469+
470+
### Basic Usage (Default Mode)
282471

283472
```python
284473
from swarms.structs.heavy_swarm import HeavySwarm
@@ -550,8 +739,10 @@ print(result)
550739
| Aspect | Recommendation/Description |
551740
|---------------------|-------------------------------------------------------------------------------------------------------------|
552741
| **Performance** | Use `max_workers` based on your CPU cores for optimal parallel execution |
553-
| **Cost** | Higher model versions (`gpt-4o`) provide better analysis but increase costs |
742+
| **Cost** | Higher model versions provide better analysis but increase costs. Grok mode uses 4 agents vs 5, slightly reducing cost per run |
554743
| **Timeouts** | Complex tasks may require longer `timeout` values |
555744
| **Tools** | Integrate domain-specific tools for enhanced analysis capabilities |
556745
| **Dashboard** | Enable `show_dashboard=True` for visual progress tracking |
557746
| **Batch Processing**| Disable dashboard and verbose logging for efficient batch operations |
747+
| **When to use Grok mode** | Best for tasks requiring debate-style analysis where facts, logic, and creative thinking need to be weighed against each other (e.g., strategic decisions, investment analysis, policy evaluation). Captain Swarm's conflict mediation is especially valuable when different perspectives might disagree. |
748+
| **When to use Default mode** | Best for systematic, phased analysis where each step builds on the previous one (e.g., research reports, market studies, compliance audits). The dedicated Verification Agent provides stronger validation coverage. |
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Basic Grok 4.20 Heavy mode example.
3+
4+
Uses Captain Swarm as the orchestrator with Harper (research/facts),
5+
Benjamin (logic/math/code), and Lucas (creative/contrarian) agents.
6+
"""
7+
8+
from swarms import HeavySwarm
9+
10+
swarm = HeavySwarm(
11+
name="Grok Analysis Team",
12+
description="Multi-agent analysis with Grok-style agents",
13+
worker_model_name="gpt-4.1",
14+
question_agent_model_name="gpt-4.1",
15+
use_grok_agents=True,
16+
show_dashboard=True,
17+
loops_per_agent=1,
18+
)
19+
20+
result = swarm.run(
21+
"Should a mid-size SaaS company pursue an IPO or "
22+
"seek acquisition in the current market? Consider "
23+
"valuation multiples, market conditions, team "
24+
"retention implications, and long-term strategic value."
25+
)
26+
27+
print(result)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Grok 4.20 Heavy mode — medical research example.
3+
4+
Harper gathers clinical evidence, Benjamin verifies
5+
statistical claims, Lucas challenges treatment assumptions.
6+
Captain Swarm mediates and synthesizes.
7+
"""
8+
9+
from swarms import HeavySwarm
10+
11+
swarm = HeavySwarm(
12+
name="Medical Research Team",
13+
description="Grok-style medical analysis",
14+
worker_model_name="gpt-4.1",
15+
question_agent_model_name="gpt-4.1",
16+
use_grok_agents=True,
17+
show_dashboard=True,
18+
loops_per_agent=2,
19+
timeout=600,
20+
)
21+
22+
result = swarm.run(
23+
"Analyze the latest research on GLP-1 receptor agonists "
24+
"for treating obesity: efficacy data, long-term safety "
25+
"profile, cost-effectiveness vs bariatric surgery, and "
26+
"potential off-label applications. Include any emerging "
27+
"concerns about muscle mass loss and cardiovascular effects."
28+
)
29+
30+
print(result)

0 commit comments

Comments
 (0)