Skip to content

Commit 976ca32

Browse files
pgrayyWorkshop Participant
authored andcommitted
agent tool - remove invoke (#369)
1 parent 718bf5f commit 976ca32

File tree

7 files changed

+67
-153
lines changed

7 files changed

+67
-153
lines changed

src/strands/event_loop/event_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def run_tool(agent: "Agent", tool_use: ToolUse, kwargs: dict[str, Any]) -> ToolG
267267
kwargs: Additional keyword arguments passed to the tool.
268268
269269
Yields:
270-
Events of the tool invocation.
270+
Events of the tool stream.
271271
272272
Returns:
273273
The final tool result or an error response if the tool fails or is not found.

src/strands/handlers/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
Examples include:
44
5-
- Processing tool invocations
65
- Displaying events from the event stream
76
"""
87

src/strands/tools/decorator.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,21 +342,6 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
342342
Returns:
343343
The result of the original function call.
344344
"""
345-
if (
346-
len(args) > 0
347-
and isinstance(args[0], dict)
348-
and (not args[0] or "toolUseId" in args[0] or "input" in args[0])
349-
):
350-
# This block is only for backwards compatability so we cast as any for now
351-
logger.warning(
352-
"issue=<%s> | "
353-
"passing tool use into a function instead of using .invoke will be removed in a future release",
354-
"https://github.com/strands-agents/sdk-python/pull/258",
355-
)
356-
tool_use = cast(Any, args[0])
357-
358-
return cast(R, self.invoke(tool_use, **kwargs))
359-
360345
return self._tool_func(*args, **kwargs)
361346

362347
@property

src/strands/types/tools.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from abc import ABC, abstractmethod
9-
from typing import Any, Callable, Generator, Literal, Protocol, Union, cast
9+
from typing import Any, Callable, Generator, Literal, Protocol, Union
1010

1111
from typing_extensions import TypedDict
1212

@@ -172,7 +172,7 @@ class AgentTool(ABC):
172172
"""Abstract base class for all SDK tools.
173173
174174
This class defines the interface that all tool implementations must follow. Each tool must provide its name,
175-
specification, and implement an invoke method that executes the tool's functionality.
175+
specification, and implement a stream method that executes the tool's functionality.
176176
"""
177177

178178
_is_dynamic: bool
@@ -214,25 +214,6 @@ def supports_hot_reload(self) -> bool:
214214
"""
215215
return False
216216

217-
def invoke(self, tool_use: ToolUse, *args: Any, **kwargs: dict[str, Any]) -> ToolResult:
218-
"""Execute the tool's functionality with the given tool use request.
219-
220-
Args:
221-
tool_use: The tool use request containing tool ID and parameters.
222-
*args: Positional arguments to pass to the tool.
223-
**kwargs: Keyword arguments to pass to the tool.
224-
225-
Returns:
226-
The result of the tool execution.
227-
"""
228-
events = self.stream(tool_use, *args, **kwargs)
229-
230-
try:
231-
while True:
232-
next(events)
233-
except StopIteration as stop:
234-
return cast(ToolResult, stop.value)
235-
236217
@abstractmethod
237218
# pragma: no cover
238219
def stream(self, tool_use: ToolUse, *args: Any, **kwargs: dict[str, Any]) -> ToolGenerator:

tests/strands/tools/mcp/test_mcp_agent_tool.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ def test_tool_spec_without_description(mock_mcp_tool, mock_mcp_client):
5757
assert tool_spec["description"] == "Tool which performs test_tool"
5858

5959

60-
def test_invoke(mcp_agent_tool, mock_mcp_client):
61-
tool_use = {"toolUseId": "test-123", "name": "test_tool", "input": {"param": "value"}}
62-
63-
tru_result = mcp_agent_tool.invoke(tool_use)
64-
exp_result = mock_mcp_client.call_tool_sync.return_value
65-
assert tru_result == exp_result
66-
67-
mock_mcp_client.call_tool_sync.assert_called_once_with(
68-
tool_use_id="test-123", name="test_tool", arguments={"param": "value"}
69-
)
70-
71-
7260
def test_stream(mcp_agent_tool, mock_mcp_client, generate):
7361
tool_use = {"toolUseId": "test-123", "name": "test_tool", "input": {"param": "value"}}
7462

0 commit comments

Comments
 (0)