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
str
default:"SelfMoASeq"
Human-readable name for this orchestrator
str
default:"Self-MoA-Seq: Sequential Self-Mixture of Agents"
Short description of the orchestrator
str
default:"gpt-5.4"
Base model used when specific proposer/aggregator models are not provided
float
default:"0.7"
Sampling temperature for the proposer; must be in [0, 2]
int
default:"6"
Total window size used during aggregation. Must be at least 2.
int
default:"3"
Number of slots reserved for the current best (and possibly other fixed items) in the window. Must be less than
window_size.int
default:"10"
Maximum aggregation loops. Must be at least 1.
int
default:"2000"
Token budget to consider for downstream consumers. Not enforced internally.
int
default:"30"
Number of candidate responses to generate overall; must be at least 2
bool
default:"True"
Enable internal logging via
logurustr
default:"INFO"
Log level string
bool
default:"True"
If True, prints a run summary after completion
Optional[str]
default:"None"
Overrides the model for the proposer agent; falls back to
model_name if not providedOptional[str]
default:"None"
Overrides the model for the aggregator agent; falls back to
model_name if not providedint
default:"3"
Stored and range-validated (must be at least 0) at construction time. Not currently applied to retry any operation.
float
default:"1.0"
Stored and range-validated (must be at least 0) at construction time. Not currently applied to retry any operation.
float
default:"2.0"
Stored and range-validated (must be at least 1) at construction time. Not currently applied to retry any operation.
float
default:"60.0"
Stored and range-validated (must be at least
retry_delay) at construction time. Not currently applied to retry any operation.Dict[str, Any]
default:"{}"
Accepted by the constructor but not currently stored or forwarded to the proposer/aggregator agents.
Optional[float]
default:"None"
Top-p (nucleus) sampling parameter passed to the model. Left unset when
None.ValueErrorfor 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
Raises:
ValueErroriftaskis not a non-empty string- Propagates any exceptions from generation/aggregation without retrying
get_metrics()
Get a snapshot of the internal metrics counters.to_dict()
Inherited fromSerializableMixin. Serializes the instance’s __dict__ into a JSON-friendly dictionary (callables are represented by name/docstring, nested objects with their own to_dict() are recursed into, non-serializable values are stringified).
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
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 Configuration
The constructor acceptsmax_retries, retry_delay, retry_backoff_multiplier, and retry_max_delay, and validates them in setup() (e.g. max_retries >= 0, retry_backoff_multiplier >= 1, retry_max_delay >= retry_delay). These values are stored on the instance but are not currently used to retry run(), _generate_samples(), or _aggregate_window() — exceptions from those methods are logged and re-raised immediately without a retry loop.
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.