Skip to content

fix(swarm): correct AgentResult output extraction from message field#438

Open
jnzs1836 wants to merge 1 commit intostrands-agents:mainfrom
jnzs1836:fix/swarm-agentresult-output-extraction
Open

fix(swarm): correct AgentResult output extraction from message field#438
jnzs1836 wants to merge 1 commit intostrands-agents:mainfrom
jnzs1836:fix/swarm-agentresult-output-extraction

Conversation

@jnzs1836
Copy link
Copy Markdown

@jnzs1836 jnzs1836 commented Apr 2, 2026

Description

Fixes critical bug where the swarm tool silently drops all sub-agent output due to accessing AgentResult.content (which doesn't exist) instead of AgentResult.message["content"] (which contains the actual response).

Root Cause: The swarm tool checks hasattr(node_result.result, "content"), but AgentResult has no .content attribute — only .message (a dict containing {"role": "assistant", "content": [...]}). Because hasattr() returns False, the extraction block is silently skipped and parent agents receive only metadata.

Changes:

  • Updated Individual Agent Contributions extraction (line 451) to access .message instead of .content
  • Updated Final Team Result extraction (line 466) with the same fix
  • Changed content block access from attribute style to dict style (content_block.get("text"))
  • Added defensive handling for both dict and object message types
  • Updated test mocks in test_swarm.py to use correct AgentResult.message structure

The fix follows the pattern already used in workflow.py (lines 446-452) and aligns with the actual AgentResult dataclass 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

  • I ran hatch run prepare
  • All 24 swarm tests pass (hatch test -k test_swarm)
  • Code formatters pass (hatch fmt --formatter)
  • Linters pass (hatch fmt --linter)
  • Type checks pass
  • All 5 pre-commit hooks pass (format, lint, type linting, unit tests, commit message)

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Swarm tool silently drops all sub-agent output

1 participant