Skip to content

Commit 7d51d73

Browse files
committed
fix: linting
1 parent 72d420e commit 7d51d73

4 files changed

Lines changed: 36 additions & 47 deletions

File tree

src/strands/multiagent/swarm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ async def _execute_swarm(self, invocation_state: dict[str, Any]) -> None:
563563
f"{elapsed_time:.2f}",
564564
)
565565

566-
async def _execute_node(self, node: SwarmNode, task: str | list[ContentBlock], invocation_state: dict[str, Any]) -> AgentResult:
566+
async def _execute_node(
567+
self, node: SwarmNode, task: str | list[ContentBlock], invocation_state: dict[str, Any]
568+
) -> AgentResult:
567569
"""Execute swarm node."""
568570
start_time = time.time()
569571
node_name = node.node_id

tests/strands/agent/test_agent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from strands.handlers.callback_handler import PrintingCallbackHandler, null_callback_handler
1919
from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, BedrockModel
2020
from strands.session.repository_session_manager import RepositorySessionManager
21-
from strands.telemetry.tracer import serialize
2221
from strands.types._events import EventLoopStopEvent, ModelStreamEvent
2322
from strands.types.content import Messages
2423
from strands.types.exceptions import ContextWindowOverflowException, EventLoopException

tests/strands/multiagent/test_graph.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,30 +1088,31 @@ async def test_state_reset_only_with_cycles_enabled():
10881088
# With reset_on_revisit enabled, reset should be called
10891089
mock_reset.assert_called_once()
10901090

1091+
10911092
@pytest.mark.asyncio
10921093
async def test_graph_kwargs_passing_agent(mock_strands_tracer, mock_use_span):
10931094
"""Test that kwargs are passed through to underlying Agent nodes."""
10941095
# Create a mock agent that captures kwargs
10951096
kwargs_agent = create_mock_agent("kwargs_agent", "Response with kwargs")
1096-
1097+
10971098
async def capture_kwargs(*args, **kwargs):
10981099
# Store kwargs for verification
10991100
capture_kwargs.captured_kwargs = kwargs
11001101
return kwargs_agent.return_value
1101-
1102+
11021103
kwargs_agent.invoke_async = MagicMock(side_effect=capture_kwargs)
1103-
1104+
11041105
# Create graph
11051106
builder = GraphBuilder()
11061107
builder.add_node(kwargs_agent, "kwargs_node")
11071108
graph = builder.build()
1108-
1109+
11091110
# Execute with custom kwargs
11101111
test_kwargs = {"custom_param": "test_value", "another_param": 42}
11111112
result = await graph.invoke_async("Test kwargs passing", **test_kwargs)
1112-
1113+
11131114
# Verify kwargs were passed to agent
1114-
assert hasattr(capture_kwargs, 'captured_kwargs')
1115+
assert hasattr(capture_kwargs, "captured_kwargs")
11151116
assert capture_kwargs.captured_kwargs == test_kwargs
11161117
assert result.status == Status.COMPLETED
11171118

@@ -1121,28 +1122,28 @@ async def test_graph_kwargs_passing_multiagent(mock_strands_tracer, mock_use_spa
11211122
"""Test that kwargs are passed through to underlying MultiAgentBase nodes."""
11221123
# Create a mock MultiAgentBase that captures kwargs
11231124
kwargs_multiagent = create_mock_multi_agent("kwargs_multiagent", "MultiAgent response with kwargs")
1124-
1125+
11251126
# Store the original return value
11261127
original_result = kwargs_multiagent.invoke_async.return_value
1127-
1128+
11281129
async def capture_kwargs(*args, **kwargs):
11291130
# Store kwargs for verification
11301131
capture_kwargs.captured_kwargs = kwargs
11311132
return original_result
1132-
1133+
11331134
kwargs_multiagent.invoke_async = AsyncMock(side_effect=capture_kwargs)
1134-
1135+
11351136
# Create graph
11361137
builder = GraphBuilder()
11371138
builder.add_node(kwargs_multiagent, "multiagent_node")
11381139
graph = builder.build()
1139-
1140+
11401141
# Execute with custom kwargs
11411142
test_kwargs = {"custom_param": "test_value", "another_param": 42}
11421143
result = await graph.invoke_async("Test kwargs passing to multiagent", **test_kwargs)
1143-
1144+
11441145
# Verify kwargs were passed to multiagent
1145-
assert hasattr(capture_kwargs, 'captured_kwargs')
1146+
assert hasattr(capture_kwargs, "captured_kwargs")
11461147
assert capture_kwargs.captured_kwargs == test_kwargs
11471148
assert result.status == Status.COMPLETED
11481149

@@ -1151,24 +1152,24 @@ def test_graph_kwargs_passing_sync(mock_strands_tracer, mock_use_span):
11511152
"""Test that kwargs are passed through to underlying nodes in sync execution."""
11521153
# Create a mock agent that captures kwargs
11531154
kwargs_agent = create_mock_agent("kwargs_agent", "Response with kwargs")
1154-
1155+
11551156
async def capture_kwargs(*args, **kwargs):
11561157
# Store kwargs for verification
11571158
capture_kwargs.captured_kwargs = kwargs
11581159
return kwargs_agent.return_value
1159-
1160+
11601161
kwargs_agent.invoke_async = MagicMock(side_effect=capture_kwargs)
1161-
1162+
11621163
# Create graph
11631164
builder = GraphBuilder()
11641165
builder.add_node(kwargs_agent, "kwargs_node")
11651166
graph = builder.build()
1166-
1167+
11671168
# Execute with custom kwargs
11681169
test_kwargs = {"custom_param": "test_value", "another_param": 42}
11691170
result = graph("Test kwargs passing sync", **test_kwargs)
1170-
1171+
11711172
# Verify kwargs were passed to agent
1172-
assert hasattr(capture_kwargs, 'captured_kwargs')
1173+
assert hasattr(capture_kwargs, "captured_kwargs")
11731174
assert capture_kwargs.captured_kwargs == test_kwargs
1174-
assert result.status == Status.COMPLETED
1175+
assert result.status == Status.COMPLETED

tests/strands/multiagent/test_swarm.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -470,42 +470,29 @@ def test_swarm_validate_unsupported_features():
470470
with pytest.raises(ValueError, match="Session persistence is not supported for Swarm agents yet"):
471471
Swarm([agent_with_session])
472472

473-
# Test with callbacks (should fail)
474-
class TestHookProvider(HookProvider):
475-
def register_hooks(self, registry, **kwargs):
476-
registry.add_callback(AgentInitializedEvent, lambda e: None)
477-
478-
agent_with_hooks = create_mock_agent("agent_with_hooks")
479-
agent_with_hooks._session_manager = None
480-
agent_with_hooks.hooks = HookRegistry()
481-
agent_with_hooks.hooks.add_hook(TestHookProvider())
482-
483-
with pytest.raises(ValueError, match="Agent callbacks are not supported for Swarm agents yet"):
484-
Swarm([agent_with_hooks])
485-
486473

487474
@pytest.mark.asyncio
488475
async def test_swarm_kwargs_passing(mock_strands_tracer, mock_use_span):
489476
"""Test that kwargs are passed through to underlying agents."""
490477
# Create a mock agent that captures kwargs
491478
kwargs_agent = create_mock_agent("kwargs_agent", "Response with kwargs")
492-
479+
493480
async def capture_kwargs(*args, **kwargs):
494481
# Store kwargs for verification
495482
capture_kwargs.captured_kwargs = kwargs
496483
return kwargs_agent.return_value
497-
484+
498485
kwargs_agent.invoke_async = MagicMock(side_effect=capture_kwargs)
499-
486+
500487
# Create swarm
501488
swarm = Swarm(nodes=[kwargs_agent])
502-
489+
503490
# Execute with custom kwargs
504491
test_kwargs = {"custom_param": "test_value", "another_param": 42}
505492
result = await swarm.invoke_async("Test kwargs passing", **test_kwargs)
506-
493+
507494
# Verify kwargs were passed to agent
508-
assert hasattr(capture_kwargs, 'captured_kwargs')
495+
assert hasattr(capture_kwargs, "captured_kwargs")
509496
assert capture_kwargs.captured_kwargs == test_kwargs
510497
assert result.status == Status.COMPLETED
511498

@@ -514,22 +501,22 @@ def test_swarm_kwargs_passing_sync(mock_strands_tracer, mock_use_span):
514501
"""Test that kwargs are passed through to underlying agents in sync execution."""
515502
# Create a mock agent that captures kwargs
516503
kwargs_agent = create_mock_agent("kwargs_agent", "Response with kwargs")
517-
504+
518505
async def capture_kwargs(*args, **kwargs):
519506
# Store kwargs for verification
520507
capture_kwargs.captured_kwargs = kwargs
521508
return kwargs_agent.return_value
522-
509+
523510
kwargs_agent.invoke_async = MagicMock(side_effect=capture_kwargs)
524-
511+
525512
# Create swarm
526513
swarm = Swarm(nodes=[kwargs_agent])
527-
514+
528515
# Execute with custom kwargs
529516
test_kwargs = {"custom_param": "test_value", "another_param": 42}
530517
result = swarm("Test kwargs passing sync", **test_kwargs)
531-
518+
532519
# Verify kwargs were passed to agent
533-
assert hasattr(capture_kwargs, 'captured_kwargs')
520+
assert hasattr(capture_kwargs, "captured_kwargs")
534521
assert capture_kwargs.captured_kwargs == test_kwargs
535522
assert result.status == Status.COMPLETED

0 commit comments

Comments
 (0)