fix(swarm): correct AgentResult output extraction from message field#438
Open
jnzs1836 wants to merge 1 commit intostrands-agents:mainfrom
Open
fix(swarm): correct AgentResult output extraction from message field#438jnzs1836 wants to merge 1 commit intostrands-agents:mainfrom
jnzs1836 wants to merge 1 commit intostrands-agents:mainfrom
Conversation
The swarm tool was incorrectly accessing AgentResult.content instead of AgentResult.message["content"], causing all sub-agent output to be silently dropped. The defensive hasattr() checks prevented errors but resulted in empty "Individual Agent Contributions" sections. Changes: - Updated lines 451-459 to access node_result.result.message - Updated lines 466-470 to access last_result.result.message - Changed content_block access from attribute to dict style - Updated test mocks to use proper message structure - Added defensive handling for both dict and object message types The fix follows the pattern already used in workflow.py (lines 446-452) and aligns with the actual AgentResult dataclass structure defined in strands-agents SDK.
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.
Description
Fixes critical bug where the swarm tool silently drops all sub-agent output due to accessing
AgentResult.content(which doesn't exist) instead ofAgentResult.message["content"](which contains the actual response).Root Cause: The swarm tool checks
hasattr(node_result.result, "content"), butAgentResulthas no.contentattribute — only.message(a dict containing{"role": "assistant", "content": [...]}). Becausehasattr()returnsFalse, the extraction block is silently skipped and parent agents receive only metadata.Changes:
.messageinstead of.contentcontent_block.get("text"))test_swarm.pyto use correctAgentResult.messagestructureThe fix follows the pattern already used in
workflow.py(lines 446-452) and aligns with the actualAgentResultdataclass in the strands-agents SDK.Related Issues
Closes #437
Documentation PR
N/A - Bug fix, no documentation changes needed.
Type of Change
Bug fix
Testing
hatch run preparehatch test -k test_swarm)hatch fmt --formatter)hatch fmt --linter)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.