Skip to content

Commit 0d1ab2e

Browse files
authored
Merge pull request #1681 from adichaudhary/feat/mixture-stop-pass
[feat] [MixtureOfAgents] workers receive task + prev-layer synthesis instead of full transcript
2 parents 3505755 + b4179d7 commit 0d1ab2e

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

swarms/structs/mixture_of_agents.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
class MixtureOfAgents:
2121
"""Run a layered Mixture-of-Agents workflow.
2222
23-
``MixtureOfAgents`` sends the task and accumulated conversation
24-
context to each worker agent concurrently for each configured layer.
25-
After all layers complete, the aggregator agent receives the full
26-
conversation and produces the final synthesized answer.
23+
``MixtureOfAgents`` runs workers in parallel across multiple layers,
24+
then synthesises their outputs with an aggregator agent.
25+
26+
Worker context per layer:
27+
- Layer 0: each worker receives only the original task.
28+
- Layer 1+: each worker receives the original task plus the
29+
concatenated outputs from the previous layer.
30+
31+
The aggregator always receives the full conversation transcript.
2732
2833
Args:
2934
id: Optional identifier accepted for API compatibility.
@@ -158,8 +163,8 @@ def step(
158163
"""Run one worker layer concurrently.
159164
160165
Args:
161-
task: Task or accumulated conversation context to send to each
162-
worker agent.
166+
task: On layer 0 this is the raw user task. On later layers it
167+
is ``"Original task: …\\n\\nPrevious layer synthesis:\\n…"``.
163168
img: Optional image path, URL, or encoded image payload passed
164169
through to each worker agent.
165170
@@ -192,20 +197,31 @@ def _run(
192197

193198
self.conversation.add(role="User", content=task)
194199

195-
full_context = self.conversation.get_str()
200+
# Workers receive only the original task on the first layer, and
201+
# task + previous-layer synthesis on subsequent layers. This avoids
202+
# re-sending the full growing transcript to every worker on every layer.
203+
worker_input = task
204+
prev_layer_output: Optional[str] = None
196205

197206
for i in range(self.layers):
198-
# Pass the full context/history string to the step method
199-
step_output = self.step(task=full_context, img=img)
207+
if prev_layer_output is not None:
208+
worker_input = (
209+
f"Original task: {task}\n\n"
210+
f"Previous layer synthesis:\n{prev_layer_output}"
211+
)
212+
213+
step_output = self.step(task=worker_input, img=img)
200214

201-
# Log each agent's output with full context awareness
202215
for agent_name, agent_output in step_output.items():
203216
self.conversation.add(
204217
role=agent_name, content=agent_output
205218
)
206219

207-
# Update the full_context with the latest conversation history
208-
full_context = self.conversation.get_str()
220+
# Summarise the layer as the concatenation of worker outputs so
221+
# the next layer has a compact view of what was produced.
222+
prev_layer_output = "\n\n".join(
223+
f"{name}: {out}" for name, out in step_output.items()
224+
)
209225

210226
aggregator_output = self.aggregator_agent.run(
211227
task=self.conversation.get_str()

0 commit comments

Comments
 (0)