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..63ccfab56 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"): + 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..e5a49404d 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"): + 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