Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/strands_tools/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,13 @@ def swarm(
if hasattr(result, "results") and result.results:
response_parts.append("\n**🤖 Individual Agent Contributions:**")
for agent_name, node_result in result.results.items():
if hasattr(node_result, "result") and hasattr(node_result.result, "content"):
if hasattr(node_result, "result") and hasattr(node_result.result, "message"):
agent_content = []
for content_block in node_result.result.content:
if hasattr(content_block, "text") and content_block.text:
agent_content.append(content_block.text)
message = node_result.result.message
content_blocks = message.get("content", []) if hasattr(message, "get") else []
for content_block in content_blocks:
if isinstance(content_block, dict) and content_block.get("text"):
agent_content.append(content_block["text"])

if agent_content:
response_parts.append(f"\n**{agent_name.upper().replace('_', ' ')}:**")
Expand All @@ -463,11 +465,13 @@ def swarm(
last_agent = result.node_history[-1].node_id
if last_agent in result.results:
last_result = result.results[last_agent]
if hasattr(last_result, "result") and hasattr(last_result.result, "content"):
if hasattr(last_result, "result") and hasattr(last_result.result, "message"):
response_parts.append("\n**🎯 Final Team Result:**")
for content_block in last_result.result.content:
if hasattr(content_block, "text") and content_block.text:
response_parts.append(content_block.text)
message = last_result.result.message
content_blocks = message.get("content", []) if hasattr(message, "get") else []
for content_block in content_blocks:
if isinstance(content_block, dict) and content_block.get("text"):
response_parts.append(content_block["text"])

# Add resource usage metrics
if hasattr(result, "accumulated_usage") and result.accumulated_usage:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def mock_request_state():
"""Create a mock request state dictionary."""
return {}


@pytest.fixture
def mock_env_vars():
"""Set up mock environment variables for testing."""
Expand All @@ -44,6 +45,7 @@ def extract_result_text(result):
return "\n".join([item["text"] for item in result["content"]])
return str(result)


@responses.activate
def test_basic_get_request():
"""Test a basic GET request with direct invocation."""
Expand Down
15 changes: 12 additions & 3 deletions tests/test_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ def mock_swarm_result():

# Mock results from individual agents
mock_agent_result1 = MagicMock()
mock_agent_result1.result.content = [MagicMock(text="Research findings: The market shows strong growth potential.")]
mock_agent_result1.result.message = {
"role": "assistant",
"content": [{"text": "Research findings: The market shows strong growth potential."}],
}
mock_agent_result2 = MagicMock()
mock_agent_result2.result.content = [MagicMock(text="Analysis complete: Data indicates 25% market opportunity.")]
mock_agent_result2.result.message = {
"role": "assistant",
"content": [{"text": "Analysis complete: Data indicates 25% market opportunity."}],
}
mock_agent_result3 = MagicMock()
mock_agent_result3.result.content = [MagicMock(text="Final report: Comprehensive strategy document created.")]
mock_agent_result3.result.message = {
"role": "assistant",
"content": [{"text": "Final report: Comprehensive strategy document created."}],
}

mock_result.results = {
"researcher": mock_agent_result1,
Expand Down
Loading