sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] Python: a second plugin instance silently overwrites the first instance's @tool

Open strandly-the-agent opened this issue 3 weeks ago • 1 comments

Human Overview

n/a — drafted by strandly-the-agent during review of #6084; left for a human per team/AI_USAGE_POLICY.md.

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python

Strands Version

main (reproduced on 1.64.1.dev96+g42b7d98aa)

Language Runtime Version

Python 3.12.15

Operating System

Linux (aarch64)

Installation Method

git clone

Steps to Reproduce

from unittest.mock import MagicMock
from strands import Agent, tool
from strands.plugins import Plugin

class P(Plugin):
    def __init__(self, n): self._n = n; super().__init__()
    @property
    def name(self): return self._n
    @tool
    def ping(self) -> str:
        """Ping."""
        return self._n

a = Agent(model=MagicMock(), callback_handler=None, plugins=[P("a"), P("b")])
print(list(a.tool_registry.registry), a.tool.ping()["content"][0]["text"])

Expected Behavior

Registering the second plugin raises a duplicate-tool error, as TypeScript does (ToolRegistry throws Tool with name 'ping' already registered).

Actual Behavior

No error. Prints ['ping'] b: the agent has one ping tool, and plugin a's tool has been replaced by b's. ToolRegistry.register_tool skips the duplicate check for hot-reloadable tools (strands-py/src/strands/tools/registry.py:250), and DecoratedFunctionTool.supports_hot_reload is always True (tools/decorator.py:719). _PluginRegistry._register_tools therefore never sees the clash. Any plugin instance whose state the tool depends on (e.g. a state_key) loses its tool without any error.

Possible Solution

In _PluginRegistry._register_tools, reject a tool name already present in agent.tool_registry.registry unless the existing tool came from the same plugin instance. This would make Python match TypeScript, and plugins wouldn't need their own guards (#6084 adds one to Todos.init_agent for exactly this reason).

Additional Context

Found by the API bar-raising pass on #6084 and re-verified independently. Doesn't affect Todos once #6084 lands, because that PR adds its own guard.

Related Issues

#6084

strandly-the-agent avatar Nov 12 '26 20:11 strandly-the-agent

PR opened: https://github.com/strands-agents/harness-sdk/pull/6139

The root cause is ToolRegistry.register_tool skipping its duplicate-name check for hot-reloadable tools (registry.py:250) — and every @tool decorated function is hot-reloadable (decorator.py:719), so the check never fires for plugin tools. _PluginRegistry now tracks which plugin registered each tool name and rejects a plugin tool whose name is already taken by a different tool, matching the TypeScript behaviour (tool-registry.ts:35). Re-registering the same plugin's own tool is still allowed.

AnnasMazhar avatar Nov 13 '26 17:11 AnnasMazhar