Skip to content

Commit 3849183

Browse files
committed
[DOCS][Maker][Tests][Maker]
1 parent 4a63849 commit 3849183

File tree

8 files changed

+430
-9
lines changed

8 files changed

+430
-9
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ This feature is perfect for rapid prototyping, complex task decomposition, and c
242242
| **[ForestSwarm](https://docs.swarms.world/en/latest/swarms/structs/forest_swarm/)** | Dynamically selects the most suitable agent or tree of agents for a given task. | Task routing, optimizing for expertise, and complex decision-making trees. |
243243
| **[HierarchicalSwarm](https://docs.swarms.world/en/latest/swarms/structs/hierarchical_swarm/)** | Orchestrates agents with a director who creates plans and distributes tasks to specialized worker agents. | Complex project management, team coordination, and hierarchical decision-making with feedback loops. |
244244
| **[HeavySwarm](https://docs.swarms.world/en/latest/swarms/structs/heavy_swarm/)** | Implements a five-phase workflow with specialized agents (Research, Analysis, Alternatives, Verification) for comprehensive task analysis. | Complex research and analysis tasks, financial analysis, strategic planning, and comprehensive reporting. |
245+
| **[MAKER](https://docs.swarms.world/en/latest/swarms/structs/maker/)** | Long-horizon tasks decomposed into steps; each step uses first-to-ahead-by-k voting and red-flagging on micro-agent samples (from Meyerson et al., 2025). | Extremely long or fragile pipelines where you want statistical agreement and validation on every atomic step—not a hand-designed multi-agent graph. |
245246
| **[SwarmRouter](https://docs.swarms.world/en/latest/swarms/structs/swarm_router/)** | A universal orchestrator that provides a single interface to run any type of swarm with dynamic selection. | Simplifying complex workflows, switching between swarm strategies, and unified multi-agent management. |
246247

247248
-----
@@ -613,6 +614,31 @@ This architecture is perfect for financial analysis, strategic planning, researc
613614

614615
---
615616

617+
### MAKER
618+
619+
`MAKER` implements **maximal agentic decomposition** with **first-to-ahead-by-k voting** and **red-flagging**: you supply `format_prompt`, `parse_response`, and optional `validate_response` / `update_state`, then run for a fixed number of steps (or until a stop condition). Each step spins up a focused one-shot `Agent` (or cycles a pool you provide) until one parsed answer leads all others by `k` votes. This matches the error-correction story in [Solving a Million-Step LLM Task with Zero Errors](https://arxiv.org/abs/2511.09030). [Full documentation](https://docs.swarms.world/en/latest/swarms/structs/maker/)
620+
621+
```python
622+
from swarms.structs.maker import MAKER
623+
624+
maker = MAKER(
625+
model_name="gpt-4.1-mini",
626+
system_prompt="You solve tasks in one clear line per step.",
627+
k=3,
628+
)
629+
630+
# Optional: override format_prompt / parse_response / validate_response for your domain.
631+
results = maker.run(
632+
task="List three concise benefits of typed APIs, one per step.",
633+
max_steps=3,
634+
)
635+
print(results)
636+
```
637+
638+
For lower latency when `k` is large, use `run_parallel_voting` with the same `task` and `max_steps`.
639+
640+
---
641+
616642
### Social Algorithms
617643

618644
**Social Algorithms** provide a flexible framework for defining custom communication patterns between agents. You can upload any arbitrary social algorithm as a callable that defines the sequence of communication, enabling agents to talk to each other in sophisticated ways. [Learn more about Social Algorithms](https://docs.swarms.world/en/latest/swarms/structs/social_algorithms/)

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ nav:
284284

285285
- DebateWithJudge: "swarms/structs/debate_with_judge.md"
286286
- MajorityVoting: "swarms/structs/majorityvoting.md"
287+
- MAKER: "swarms/structs/maker.md"
287288
- RoundRobin: "swarms/structs/round_robin_swarm.md"
288289
- Mixture of Agents: "swarms/structs/moa.md"
289290
- SelfMoASeq: "swarms/structs/self_moa_seq.md"

docs/swarms/concept/swarm_architectures.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-Agent Architectures
22

3-
### What is a Multi-Agent Architecture?
3+
*What are Multi-Agent Architectures?*
44

55
A multi-agent architecture refers to a group of more than two agents working collaboratively to achieve a common goal. These agents can be software entities, such as LLMs that interact with each other to perform complex tasks. The concept of multi-agent architectures is inspired by how humans communicate and work together in teams, organizations, and communities, where individual contributions combine to create sophisticated collaborative problem-solving capabilities.
66

@@ -14,10 +14,6 @@ Multi-agent architectures are designed to establish and manage communication bet
1414

1515
3. **Sequential Communication**: Sequential architectures process tasks in a linear order, where each agent's output becomes the input for the next agent. This ensures that tasks with dependencies are handled in the correct sequence, maintaining the integrity of the workflow.
1616

17-
4. **Mesh Communication**: In mesh architectures, agents are fully connected, allowing any agent to communicate with any other agent. This setup provides high flexibility and redundancy, making it ideal for complex systems requiring dynamic interactions.
18-
19-
5. **Federated Communication**: Federated architectures involve multiple independent systems that collaborate by sharing information and results. Each system operates autonomously but can contribute to a larger task, enabling distributed problem-solving across different nodes.
20-
2117
Multi-agent architectures leverage these communication patterns to ensure that agents work together efficiently, adapting to the specific requirements of the task at hand. By defining clear communication protocols and interaction models, multi-agent architectures enable the seamless orchestration of multiple agents, leading to enhanced performance and problem-solving capabilities.
2218

2319
## Core Multi-Agent Architectures
@@ -37,6 +33,7 @@ Multi-agent architectures leverage these communication patterns to ensure that a
3733
| Heavy | High-performance architecture for handling intensive computational tasks with multiple agents. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/heavy_swarm/) | Large-scale data processing, intensive computational workflows |
3834
| Council as Judge | Multiple agents act as a council to evaluate and judge outputs or decisions. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/council_of_judges/) | Quality assessment, decision validation, peer review processes |
3935
| Majority Voting | Agents vote on decisions with the majority determining the final outcome. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/majorityvoting/) | Democratic decision-making, consensus building, error reduction |
36+
| MAKER | Decomposes work into sequential steps; each step uses repeated micro-agent samples, red-flagging, and first-to-ahead-by-k voting before committing. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/maker/) | Very long or high-precision pipelines where every atomic step should be statistically validated |
4037
| Round Robin | Tasks are distributed cyclically among agents in a rotating order. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/round_robin_swarm/) | Load balancing, fair task distribution, resource optimization |
4138
| Auto-Builder | Automatically constructs and configures multi-agent systems based on requirements. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/auto_swarm_builder/) | Dynamic system creation, adaptive architectures, rapid prototyping |
4239
| Hybrid Hierarchical Cluster | Combines hierarchical and peer-to-peer communication patterns for complex workflows. | [Learn More](https://docs.swarms.world/en/latest/swarms/structs/hhcs/) | Complex enterprise workflows, multi-department coordination |
@@ -768,6 +765,37 @@ graph TD
768765

769766
---
770767

768+
### MAKER
769+
770+
**Overview:**
771+
MAKER (**M**aximal **A**gentic decomposition, first-to-ahead-by-**K** **E**rror correction, and **R**ed-flagging) breaks a task into many sequential steps. At each step, one-shot micro-agents sample answers; invalid outputs are discarded (red-flagging), and the framework only commits when one parsed result leads every other candidate by `k` votes. It is task-agnostic: you supply prompt formatting, parsing, and optional validation and state updates. Based on Meyerson et al. (2025); see the [paper](https://arxiv.org/abs/2511.09030).
772+
773+
**Use Cases:**
774+
775+
- Very long-horizon workflows where each atomic step must be reliable
776+
777+
- Pipelines where correlated failures are reduced by voting and response validation
778+
779+
- Domains where you can decompose work into explicit steps with clear per-step I/O
780+
781+
**[Learn More](https://docs.swarms.world/en/latest/swarms/structs/maker/)**
782+
783+
```mermaid
784+
graph TD
785+
T[Task + step budget] --> S[Step loop]
786+
S --> P[format_prompt → Agent.run]
787+
P --> R{Valid sample?}
788+
R -->|red-flag| P
789+
R -->|ok| V[parse → vote tally]
790+
V --> W{Leader ahead by k?}
791+
W -->|no| P
792+
W -->|yes| U[update_state, record result]
793+
U --> S
794+
S --> D[Final trajectory]
795+
```
796+
797+
---
798+
771799
### Auto-Builder
772800

773801
**Overview:**

docs/swarms/structs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Multi-agent systems unlock new levels of intelligence, reliability, and efficien
3535
| **[SwarmRouter](https://docs.swarms.world/en/latest/swarms/structs/swarm_router/)** | Universal orchestrator that provides a single interface to run any type of swarm with dynamic selection. | Simplifying complex workflows, switching between swarm strategies, unified multi-agent management. |
3636
| **[HierarchicalSwarm](https://docs.swarms.world/en/latest/swarms/structs/hierarchical_swarm/)** | Director agent coordinates specialized worker agents in a hierarchy. | Complex, multi-stage tasks, iterative refinement, enterprise workflows. |
3737
| **[Hybrid Hierarchical-Cluster Swarm (HHCS)](https://docs.swarms.world/en/latest/swarms/structs/hhcs/)** | Router agent distributes tasks to specialized swarms for parallel, hierarchical processing. | Enterprise-scale, multi-domain, and highly complex workflows. |
38+
| **[MAKER](https://docs.swarms.world/en/latest/swarms/structs/maker/)** | Decomposes a task into many steps; each step uses micro-agents, red-flagging, and first-to-ahead-by-k voting before committing. | Long or fragile workflows where you want statistical agreement on every atomic step (see Meyerson et al., 2025). |
3839

3940
---
4041

docs/swarms/structs/maker.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# MAKER
2+
3+
**MAKER** (**M**aximal **A**gentic decomposition, first-to-ahead-by-**K** **E**rror correction, and **R**ed-flagging) is a task-agnostic orchestrator for long-horizon problems. It decomposes work into many small steps; at each step it samples LLM outputs, discards bad ones (red-flagging), and commits only when one parsed answer leads the next-best by `k` votes (“first-to-ahead-by-k”).
4+
5+
This implementation follows the framework described in *Solving a Million-Step LLM Task with Zero Errors* (Meyerson et al., 2025) — [arXiv:2511.09030](https://arxiv.org/abs/2511.09030).
6+
7+
**Import:** `from swarms.structs.maker import MAKER`
8+
9+
## When to use MAKER
10+
11+
| Use MAKER when… | Consider something else when… |
12+
|-----------------|-------------------------------|
13+
| You can express the problem as a fixed or conditionally bounded sequence of steps | You need a fixed DAG of different agents ([GraphWorkflow](graph_workflow.md)) |
14+
| Each step should be a single focused LLM call with statistical agreement | You want multi-agent debate + judge ([DebateWithJudge](debate_with_judge.md)) |
15+
| You care about per-step reliability (voting + validation) over raw speed | You only need one-shot or simple majority across agents ([MajorityVoting](majorityvoting.md)) |
16+
17+
## How it works
18+
19+
```mermaid
20+
flowchart TD
21+
T[Task + max_steps] --> S[For each step]
22+
S --> V[Sample votes via Agent.run]
23+
V --> R{Red-flag?}
24+
R -->|invalid / exception| V
25+
R -->|valid| P[parse_response → hashable result]
26+
P --> C{Leader ahead by k?}
27+
C -->|no| V
28+
C -->|yes| U[update_state, append result]
29+
U --> S
30+
```
31+
32+
1. **MAD (maximal agentic decomposition)** — You run up to `max_steps` iterations; each iteration is one micro-step with a prompt built from the task, optional state, step index, and the previous step’s result (`format_prompt`).
33+
2. **First-to-ahead-by-k voting** — Parsed answers are counted until some candidate’s count is at least `k` greater than every other candidate (`do_voting`). Optional **`run_parallel_voting`** batches the first round of samples with a thread pool.
34+
3. **Red-flagging** — Before parsing, `validate_response` can reject outputs (default rejects empty or overly long text vs `max_tokens`).
35+
36+
## Constructor parameters
37+
38+
| Parameter | Role |
39+
|-----------|------|
40+
| `model_name`, `system_prompt`, `max_tokens`, `temperature`, `temperature_first` | Passed through to per-step `Agent` instances (first vote often uses `temperature_first=0`). |
41+
| `k` | Votes a winner must lead the runner-up by (higher ⇒ more reliable, more cost). |
42+
| `format_prompt(task, state, step_idx, previous_result)` | Builds the user prompt for the current step. |
43+
| `parse_response(text)` | Turns raw LLM output into a **hashable** result for voting (strings, numbers, tuples of primitives, etc.). |
44+
| `validate_response(text, max_tokens)` | Returns `False` to discard a sample. |
45+
| `update_state(state, result, step_idx)` | Fold step output into state (default: unchanged). |
46+
| `initial_state` | Starting state for `run` / `run_until_condition`. |
47+
| `max_workers` | Thread pool size for `run_parallel_voting` (default: `k`). |
48+
| `max_retries_per_step` | Cap on samples per step before `RuntimeError`. |
49+
| `agents` | Optional list of pre-built `Agent`s; votes cycle through this pool instead of creating fresh micro-agents. |
50+
51+
## Main methods
52+
53+
| Method | Description |
54+
|--------|-------------|
55+
| `run(task, max_steps)` | Run exactly `max_steps` voting rounds; returns `list` of per-step results. |
56+
| `run_until_condition(task, stop_condition, max_steps=1000)` | Like `run`, but before each step the loop checks `stop_condition(state, results, step_idx)`; if true, it exits without running another vote for that index. |
57+
| `run_parallel_voting(task, max_steps)` | Like `run` but uses parallel sampling for the first batch of votes per step. |
58+
| `get_statistics()` | Copy of internal counters (samples, votes, red-flags, per-step vote/sample lists). |
59+
| `reset()` | Clears stats and conversation. |
60+
| `estimate_cost(total_steps, target_success_probability=0.95)` | Heuristic cost / `k` guidance from paper-style estimates (uses run statistics when available). |
61+
62+
## Minimal example
63+
64+
```python
65+
from swarms.structs.maker import MAKER
66+
67+
68+
def format_prompt(task, state, step_idx, previous_result):
69+
prev = f"\nPrevious: {previous_result}" if previous_result is not None else ""
70+
return f"{task}\nStep {step_idx + 1} of the plan. One short line only.{prev}"
71+
72+
73+
def parse_response(response: str) -> str:
74+
return response.strip().splitlines()[0]
75+
76+
77+
def validate_response(response: str, max_tokens: int) -> bool:
78+
if not response.strip():
79+
return False
80+
return len(response) // 4 <= max_tokens # rough token estimate, same idea as default
81+
82+
83+
maker = MAKER(
84+
name="LineByLine",
85+
model_name="gpt-4.1-mini",
86+
system_prompt="Answer in one short line per step.",
87+
format_prompt=format_prompt,
88+
parse_response=parse_response,
89+
validate_response=validate_response,
90+
k=2,
91+
verbose=True,
92+
)
93+
94+
results = maker.run(task="List three benefits of unit tests, one per step.", max_steps=3)
95+
print(results)
96+
```
97+
98+
## Related
99+
100+
- Source: `swarms/structs/maker.py` (module and class docstrings mirror this behavior).
101+
- [MajorityVoting](majorityvoting.md) — multi-agent loops with a consensus agent, not step-wise first-to-ahead-by-k on a decomposed trajectory.

docs/swarms/structs/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This page provides a comprehensive overview of all available multi-agent archite
88
| Architecture | Use Case | Key Functionality | Documentation |
99
|-------------|----------|-------------------|---------------|
1010
| MajorityVoting | Decision making through consensus | Combines multiple agent opinions and selects the most common answer | [Docs](majorityvoting.md) |
11+
| MAKER | Long-horizon precision | Step-wise decomposition with first-to-ahead-by-k voting and red-flagging per step | [Docs](maker.md) |
1112
| AgentRearrange | Optimizing agent order | Dynamically reorders agents based on task requirements | [Docs](agent_rearrange.md) |
1213
| RoundRobin | Equal task distribution | Cycles through agents in a fixed order | [Docs](round_robin_swarm.md) |
1314
| Mixture of Agents | Complex problem solving | Combines diverse expert agents for comprehensive analysis | [Docs](moa.md) |

swarms/structs/llm_council.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
often selecting responses from other models as superior to their own.
1111
"""
1212

13-
from typing import Dict, List, Optional
1413
import random
14+
from typing import Dict, List, Optional
15+
1516
from swarms.structs.agent import Agent
17+
from swarms.structs.conversation import Conversation
1618
from swarms.structs.multi_agent_exec import (
17-
run_agents_concurrently,
1819
batched_grid_agent_execution,
20+
run_agents_concurrently,
1921
)
22+
from swarms.structs.swarm_id import swarm_id
2023
from swarms.utils.history_output_formatter import (
2124
HistoryOutputType,
2225
history_output_formatter,
2326
)
24-
from swarms.structs.conversation import Conversation
25-
from swarms.structs.swarm_id import swarm_id
2627

2728

2829
def get_gpt_councilor_prompt() -> str:

0 commit comments

Comments
 (0)