Skip to main content
SelfMoASeq (Sequential Self-Mixture of Agents) asks one model the same question several times and merges the answers into one. A proposer agent writes the samples. An aggregator agent then works through them a few at a time: each step reads the best answer so far plus the next few samples and writes a new best answer. Because each step sees only a small window, the merge stays within the model’s context however many samples you take. Reference: SelfMoASeq.

How a run works

  1. Sample. The proposer answers the task num_samples times. Its history is cleared before each sample, so every sample is an independent draw. Samples are generated one after another.
  2. Start. The first sample becomes the best answer so far.
  3. Merge. Each step takes the next window_size - reserved_slots samples, adds the best answer so far, and asks the aggregator to combine them. The aggregator runs at temperature 0, and its reply becomes the new best answer.
  4. Stop. The run ends when every sample is merged or after max_loops steps.
run() never generates more samples than max_loops steps can merge: at most 1 + max_loops * (window_size - reserved_slots).

1. Merge a few samples

With window_size=3 and reserved_slots=1, each step merges two new samples into the best answer. Five samples take two steps: sample 1 starts as the best, then samples 2 and 3, then samples 4 and 5. verbose=False turns off the progress logs. The proposer and aggregator still print each of their replies in a panel.

2. Read the result

run() returns a dict. Continuing from step 1:
A run printed:
metrics is reset at the start of every run(), and get_metrics() returns a copy of the latest run’s metrics. moa.usage adds up the provider token usage of the proposer and the aggregator across every run.

3. Size the window and the loop limit

max_loops caps the merge steps, and so the number of samples. Here num_samples=10 asks for ten, but one step of three new samples can only merge four, so only four are generated:
This prints 4 samples, 1 step, then the merged list of names. How the settings fit together: The defaults make 30 proposer calls and 10 aggregator calls on gpt-5.4. Start smaller while you try a task.

4. Use a different model for each role

proposer_model_name and aggregator_model_name override model_name for one role each. A cheaper model can draft while a stronger one merges. temperature applies to the proposer only, and max_tokens caps each reply from both agents.
This prints gpt-5.4-mini -> gpt-5.4, then the merged tips. The two agents are on the instance as moa.proposer and moa.aggregator. top_p, when set, goes to both.

5. Invalid settings fail early

The constructor checks its settings before it builds any agent, so a bad value fails without a model call:
Output:
run() raises ValueError for an empty task. A failed model call is raised as it is; there are no retries inside SelfMoASeq.

Tips

  • Use it for open-ended writing and answers, where merging several drafts beats any one of them. For a single correct answer, MajorityVoting is cheaper.
  • Raise temperature when the samples come back too alike. In step 1 the five samples differed by only a few words.
  • Expect sequential calls. Samples and merges run one after another, so time grows with num_samples.

Next steps