From 4afc6fef4f26d8461c8777cf50566761c0c553b1 Mon Sep 17 00:00:00 2001 From: Aaron Farntrog Date: Tue, 9 Dec 2025 10:55:18 -0500 Subject: [PATCH 1/2] feat(multiagent): add deprecation warning for **kwargs in __call__ Emit UserWarning when kwargs are passed outside invocation_state parameter for Graph and Swarm orchestrators. --- src/strands/multiagent/graph.py | 16 ---------------- src/strands/multiagent/swarm.py | 15 --------------- tests/strands/multiagent/test_graph.py | 12 ++++++++++++ tests/strands/multiagent/test_swarm.py | 9 +++++++++ 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/strands/multiagent/graph.py b/src/strands/multiagent/graph.py index 6156d332c..45f2d44fb 100644 --- a/src/strands/multiagent/graph.py +++ b/src/strands/multiagent/graph.py @@ -461,22 +461,6 @@ def __init__( run_async(lambda: self.hooks.invoke_callbacks_async(MultiAgentInitializedEvent(self))) - def __call__( - self, task: MultiAgentInput, invocation_state: dict[str, Any] | None = None, **kwargs: Any - ) -> GraphResult: - """Invoke the graph synchronously. - - Args: - task: The task to execute - invocation_state: Additional state/context passed to underlying agents. - Defaults to None to avoid mutable default argument issues. - **kwargs: Keyword arguments allowing backward compatible future changes. - """ - if invocation_state is None: - invocation_state = {} - - return run_async(lambda: self.invoke_async(task, invocation_state)) - async def invoke_async( self, task: MultiAgentInput, invocation_state: dict[str, Any] | None = None, **kwargs: Any ) -> GraphResult: diff --git a/src/strands/multiagent/swarm.py b/src/strands/multiagent/swarm.py index 7eec49649..6136f54cb 100644 --- a/src/strands/multiagent/swarm.py +++ b/src/strands/multiagent/swarm.py @@ -299,21 +299,6 @@ def __init__( self._inject_swarm_tools() run_async(lambda: self.hooks.invoke_callbacks_async(MultiAgentInitializedEvent(self))) - def __call__( - self, task: MultiAgentInput, invocation_state: dict[str, Any] | None = None, **kwargs: Any - ) -> SwarmResult: - """Invoke the swarm synchronously. - - Args: - task: The task to execute - invocation_state: Additional state/context passed to underlying agents. - Defaults to None to avoid mutable default argument issues. - **kwargs: Keyword arguments allowing backward compatible future changes. - """ - if invocation_state is None: - invocation_state = {} - return run_async(lambda: self.invoke_async(task, invocation_state)) - async def invoke_async( self, task: MultiAgentInput, invocation_state: dict[str, Any] | None = None, **kwargs: Any ) -> SwarmResult: diff --git a/tests/strands/multiagent/test_graph.py b/tests/strands/multiagent/test_graph.py index 4875d1bec..bdb2ca7f0 100644 --- a/tests/strands/multiagent/test_graph.py +++ b/tests/strands/multiagent/test_graph.py @@ -890,6 +890,18 @@ def test_graph_synchronous_execution(mock_strands_tracer, mock_use_span, mock_ag mock_use_span.assert_called_once() +def test_graph_call_kwargs_deprecation_warning(mock_strands_tracer, mock_use_span, mock_agents): + """Test that __call__ emits deprecation warning when kwargs are passed outside invocation_state.""" + builder = GraphBuilder() + builder.add_node(mock_agents["start_agent"], "start_agent") + builder.set_entry_point("start_agent") + + graph = builder.build() + + with pytest.warns(UserWarning, match=r"\*\*kwargs.*parameter is deprecating"): + result = graph("Test task", custom_param="custom_value") + + def test_graph_validate_unsupported_features(): """Test Graph validation for session persistence and callbacks.""" # Test with normal agent (should work) diff --git a/tests/strands/multiagent/test_swarm.py b/tests/strands/multiagent/test_swarm.py index f2abed9f7..7b53ac89e 100644 --- a/tests/strands/multiagent/test_swarm.py +++ b/tests/strands/multiagent/test_swarm.py @@ -301,6 +301,15 @@ def test_swarm_synchronous_execution(mock_strands_tracer, mock_use_span, mock_ag mock_use_span.assert_called_once() +def test_swarm_call_kwargs_deprecation_warning(mock_strands_tracer, mock_use_span, mock_agents): + """Test that __call__ emits deprecation warning when kwargs are passed outside invocation_state.""" + agents = list(mock_agents.values()) + swarm = Swarm(nodes=agents) + + with pytest.warns(UserWarning, match=r"\*\*kwargs.*parameter is deprecating"): + result = swarm("Test task", custom_param="custom_value") + + def test_swarm_builder_validation(mock_agents): """Test swarm builder validation and error handling.""" # Test agent name assignment From 2295a0e7bdef66a2f9f9799007a2936ee2d99d10 Mon Sep 17 00:00:00 2001 From: Aaron Farntrog Date: Tue, 9 Dec 2025 10:59:06 -0500 Subject: [PATCH 2/2] feat(multiagent): add deprecation warning for **kwargs in __call__ Emit UserWarning when kwargs are passed outside invocation_state parameter for Graph and Swarm orchestrators. --- tests/strands/multiagent/test_graph.py | 2 +- tests/strands/multiagent/test_swarm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/strands/multiagent/test_graph.py b/tests/strands/multiagent/test_graph.py index bdb2ca7f0..63ccfab56 100644 --- a/tests/strands/multiagent/test_graph.py +++ b/tests/strands/multiagent/test_graph.py @@ -899,7 +899,7 @@ def test_graph_call_kwargs_deprecation_warning(mock_strands_tracer, mock_use_spa graph = builder.build() with pytest.warns(UserWarning, match=r"\*\*kwargs.*parameter is deprecating"): - result = graph("Test task", custom_param="custom_value") + graph("Test task", custom_param="custom_value") def test_graph_validate_unsupported_features(): diff --git a/tests/strands/multiagent/test_swarm.py b/tests/strands/multiagent/test_swarm.py index 7b53ac89e..e5a49404d 100644 --- a/tests/strands/multiagent/test_swarm.py +++ b/tests/strands/multiagent/test_swarm.py @@ -307,7 +307,7 @@ def test_swarm_call_kwargs_deprecation_warning(mock_strands_tracer, mock_use_spa swarm = Swarm(nodes=agents) with pytest.warns(UserWarning, match=r"\*\*kwargs.*parameter is deprecating"): - result = swarm("Test task", custom_param="custom_value") + swarm("Test task", custom_param="custom_value") def test_swarm_builder_validation(mock_agents):