[Bug] ConcurrentWorkflow silently drops one agent's answer, and which one changes every run - #1884
Open
ayaangazali wants to merge 1 commit into
Open
Conversation
`return_all_except_first` slices `[2:]`, hardcoding the assumption that
every history begins `[System, User, ...]`. Two things break that:
- `Agent.short_memory` only adds the System row when a `system_prompt`
was given — `_initialize_new_conversation` makes it conditional.
- Swarms build their own Conversation with no system prompt at all.
`ConcurrentWorkflow`'s history is `[User, agent, agent, ...]`.
So for a swarm the slice consumes the first agent's output. With
`dict-all-except-first` — `ConcurrentWorkflow`'s default `output_type` —
three agents return two answers:
history ['User', 'B', 'C', 'A']
returned [{'role': 'C', ...}, {'role': 'A', ...}]
and because results are collected as they complete, the answer that
disappears is whichever agent happened to finish first: a different one
on every run, with no error.
Derive the offset instead: skip a leading System row when there is one,
then skip the first real message, which is the input. Agent histories
behave exactly as before (System and task both dropped); swarm histories
now keep every agent.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ayaangazali
force-pushed
the
fix/all-except-first-drops-an-agent
branch
from
August 15, 2026 17:48
64e41a4 to
d41ab96
Compare
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Conversation.return_all_except_firstslices[2:]:The docstring says one; the code skips two. It hardcodes the assumption that every history begins
[System, User, ...], which is not true in two ways:Agent.short_memoryadds the System row conditionally —_initialize_new_conversationonly callsadd("System", ...)if self.system_prompt is not None.Conversationwith no system prompt at all.ConcurrentWorkflow's history is[User, agent, agent, agent].So on a swarm the slice eats the first agent's answer, not a preamble.
Impact
dict-all-except-firstisConcurrentWorkflow's defaultoutput_type, so this is default behaviour, not an opt-in path. Three agents in, two answers out:Results are collected as they complete, so the answer that disappears is whichever agent finished first — a different agent on each run. No exception, no warning; the output is still well-formed, just missing one contributor.
AgentRearrangeis affected conditionally:team_awareness=Trueinserts a System message and makes[2:]correct,team_awareness=Falsemakes it drop an agent. An unrelated flag changes how much of the output survives.Fix
Derive the offset instead of hardcoding it: skip a leading System row when one exists, then skip the first real message, which is the input task. Both slicing methods share one helper so they cannot drift apart.
Verification
The Agent-shaped case is the one that must not move: with a System row present it still drops both the System row and the task, exactly as before.
tests/structs/test_conversation.py— 51 passed.tests/structs/test_concurrent_workflow.py— 10 passed.One file, 24 lines.
(Unrelated to this PR:
black . --checkcurrently fails onexamples/mcp/agents/07_huggingface_model_search.pyand12_semgrep_security_scan.py, which arrived with 47d94eb. The file this PR touches is clean.)