Documentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SelfMoASeq (Self-MoA-Seq: Sequential Self-Mixture of Agents) is an ensemble method that generates multiple candidate responses from a single high-performing model and synthesizes them sequentially using a sliding window approach. This keeps context within bounds while leveraging diversity across samples for a high-quality final output.
- Phase 1: Generate
num_samplesresponses using a proposer agent. - Phase 2: Aggregate responses in windows with an aggregator agent, biasing toward the current best.
- Phase 3: Iterate until all samples are processed or
max_loopsis reached.
Installation
Attributes
Human-readable name for this orchestrator
Short description of the orchestrator
Base model used when specific proposer/aggregator models are not provided
Sampling temperature for the proposer; must be in [0, 2]
Total window size used during aggregation. Must be at least 2.
Number of slots reserved for the current best (and possibly other fixed items) in the window. Must be less than
window_size.Maximum aggregation loops. Must be at least 1.
Token budget to consider for downstream consumers. Not enforced internally.
Number of candidate responses to generate overall; must be at least 2
Enable internal logging via
loguruLog level string
If True, prints a run summary after completion
Overrides the model for the proposer agent; falls back to
model_name if not providedOverrides the model for the aggregator agent; falls back to
model_name if not providedMax retry attempts for key operations (
_generate_samples, _aggregate_window, run). Must be at least 0.Initial delay before first retry (seconds). Must be at least 0.
Exponential backoff multiplier; must be at least 1
Maximum backoff delay (seconds); must be at least
retry_delayValueErrorfor invalid parameter ranges (e.g.,window_size < 2,reserved_slots >= window_size, temperature outside [0, 2], etc.)
Methods
run()
Execute the full Self-MoA-Seq process: sample generation, sliding-window aggregation, and final synthesis.task(str): The task to process; must be a non-empty string
| Key | Type | Description |
|---|---|---|
final_output | str | The final synthesized best response |
all_samples | List[str] | All generated candidate responses |
aggregation_steps | int | Number of aggregation iterations executed |
metrics | Dict[str, Any] | Snapshot of performance metrics for this run |
task | str | Echoes the original task |
timestamp | str | ISO 8601 timestamp of completion |
ValueErroriftaskis not a non-empty string- Propagates any exceptions from generation/aggregation; both are retried according to the instance retry configuration
get_metrics()
Get a snapshot of the internal metrics counters.Internal Methods
Methods prefixed with
_ are internal but documented here for completeness._generate_samples()
Generatenum_samples candidate responses using the proposer agent.
task(str): The task description to pass to the proposer agentnum_samples(int): Number of samples to generate
_format_aggregation_prompt()
Create the prompt that the aggregator agent will receive for a given window.task(str): The original task stringsamples(List[str]): Window of candidate responses to synthesizebest_so_far(Optional[str]): Previously synthesized best output, if any
_aggregate_window()
Aggregate a window of samples using the aggregator agent, biased bybest_so_far.
task(str): The original task stringwindow_samples(List[str]): Current window, typically[best_output] + current_windowbest_so_far(Optional[str]): Current best aggregation to bias the synthesizer
_log_summary()
Log a brief summary of the run whenverbose=True.
result(Dict[str, Any]): The run result bundle returned byrun
Usage Examples
Basic Usage
Medical Diagnosis with High Sample Count
This example demonstrates using SelfMoASeq for a complex medical diagnosis task with a larger number of samples for comprehensive analysis.Creative Writing with Different Models
This example shows how to use different models for the proposer and aggregator, with a creative writing task.Retry Behavior
Key methods (_generate_samples, _aggregate_window, and run) are wrapped with an instance-configurable retry policy:
- stop: Up to
max_retries + 1total attempts - wait: Exponential backoff with
retry_backoff_multiplier, minretry_delay, and maxretry_max_delayseconds - retry on: Any
Exception - before sleep: Logs a warning before each retry
When to Choose SelfMoASeq
ChooseSelfMoASeq when you need:
- High-quality outputs that benefit from multiple perspectives
- To work within context length constraints
- Reliable, production-ready ensemble methods
- Fine-grained control over the generation and synthesis process
- Comprehensive observability and error handling
MixtureOfAgents for more straightforward aggregation strategies.