Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/strands/event_loop/event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def run_tool(agent: "Agent", tool_use: ToolUse, kwargs: dict[str, Any]) -> ToolG
kwargs: Additional keyword arguments passed to the tool.

Yields:
Events of the tool invocation.
Events of the tool stream.

Returns:
The final tool result or an error response if the tool fails or is not found.
Expand Down
1 change: 0 additions & 1 deletion src/strands/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Examples include:

- Processing tool invocations
- Displaying events from the event stream
"""

Expand Down
15 changes: 0 additions & 15 deletions src/strands/tools/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,6 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
Returns:
The result of the original function call.
"""
if (
len(args) > 0
and isinstance(args[0], dict)
and (not args[0] or "toolUseId" in args[0] or "input" in args[0])
):
# This block is only for backwards compatability so we cast as any for now
logger.warning(
"issue=<%s> | "
"passing tool use into a function instead of using .invoke will be removed in a future release",
"https://github.com/strands-agents/sdk-python/pull/258",
)
tool_use = cast(Any, args[0])

return cast(R, self.invoke(tool_use, **kwargs))

return self._tool_func(*args, **kwargs)

@property
Expand Down
23 changes: 2 additions & 21 deletions src/strands/types/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from abc import ABC, abstractmethod
from typing import Any, Callable, Generator, Literal, Protocol, Union, cast
from typing import Any, Callable, Generator, Literal, Protocol, Union

from typing_extensions import TypedDict

Expand Down Expand Up @@ -172,7 +172,7 @@ class AgentTool(ABC):
"""Abstract base class for all SDK tools.

This class defines the interface that all tool implementations must follow. Each tool must provide its name,
specification, and implement an invoke method that executes the tool's functionality.
specification, and implement a stream method that executes the tool's functionality.
"""

_is_dynamic: bool
Expand Down Expand Up @@ -214,25 +214,6 @@ def supports_hot_reload(self) -> bool:
"""
return False

def invoke(self, tool_use: ToolUse, *args: Any, **kwargs: dict[str, Any]) -> ToolResult:
"""Execute the tool's functionality with the given tool use request.

Args:
tool_use: The tool use request containing tool ID and parameters.
*args: Positional arguments to pass to the tool.
**kwargs: Keyword arguments to pass to the tool.

Returns:
The result of the tool execution.
"""
events = self.stream(tool_use, *args, **kwargs)

try:
while True:
next(events)
except StopIteration as stop:
return cast(ToolResult, stop.value)

@abstractmethod
# pragma: no cover
def stream(self, tool_use: ToolUse, *args: Any, **kwargs: dict[str, Any]) -> ToolGenerator:
Expand Down
12 changes: 0 additions & 12 deletions tests/strands/tools/mcp/test_mcp_agent_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ def test_tool_spec_without_description(mock_mcp_tool, mock_mcp_client):
assert tool_spec["description"] == "Tool which performs test_tool"


def test_invoke(mcp_agent_tool, mock_mcp_client):
tool_use = {"toolUseId": "test-123", "name": "test_tool", "input": {"param": "value"}}

tru_result = mcp_agent_tool.invoke(tool_use)
exp_result = mock_mcp_client.call_tool_sync.return_value
assert tru_result == exp_result

mock_mcp_client.call_tool_sync.assert_called_once_with(
tool_use_id="test-123", name="test_tool", arguments={"param": "value"}
)


def test_stream(mcp_agent_tool, mock_mcp_client, generate):
tool_use = {"toolUseId": "test-123", "name": "test_tool", "input": {"param": "value"}}

Expand Down
Loading
Loading