Skip to content

Commit 70cefff

Browse files
committed
rename add_plugin to add_and_init
1 parent 3eae107 commit 70cefff

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/strands/plugins/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Plugin(Protocol):
1818
Plugins provide a composable way to add behavior changes to agents.
1919
They are initialized with an agent instance and can register hooks,
2020
modify agent attributes, or perform other setup tasks.
21-
21+
2222
Attributes:
2323
name: A stable string identifier for the plugin
2424

src/strands/plugins/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def init_plugin(self, agent: Agent) -> None:
3535
pass
3636
3737
plugin = MyPlugin()
38-
registry.add_plugin(plugin)
38+
registry.add_and_init(plugin)
3939
```
4040
"""
4141

@@ -48,7 +48,7 @@ def __init__(self, agent: "Agent") -> None:
4848
self._agent = agent
4949
self._plugins: dict[str, Plugin] = {}
5050

51-
def add_plugin(self, plugin: Plugin) -> None:
51+
def add_and_init(self, plugin: Plugin) -> None:
5252
"""Add and initialize a plugin with the agent.
5353
5454
This method registers the plugin and calls its init_plugin method.

tests/strands/plugins/test_plugins.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def registry(mock_agent):
134134
return _PluginRegistry(mock_agent)
135135

136136

137-
def test_plugin_registry_add_plugin_calls_init_plugin(registry, mock_agent):
137+
def test_plugin_registry_add_and_init_calls_init_plugin(registry, mock_agent):
138138
"""Test adding a plugin calls its init_plugin method."""
139139

140140
class TestPlugin:
@@ -148,7 +148,7 @@ def init_plugin(self, agent):
148148
agent.plugin_initialized = True
149149

150150
plugin = TestPlugin()
151-
registry.add_plugin(plugin)
151+
registry.add_and_init(plugin)
152152

153153
assert plugin.initialized
154154
assert mock_agent.plugin_initialized
@@ -166,14 +166,14 @@ def init_plugin(self, agent):
166166
plugin1 = TestPlugin()
167167
plugin2 = TestPlugin()
168168

169-
registry.add_plugin(plugin1)
169+
registry.add_and_init(plugin1)
170170

171171
with pytest.raises(ValueError, match="plugin_name=<test-plugin> | plugin already registered"):
172-
registry.add_plugin(plugin2)
172+
registry.add_and_init(plugin2)
173173

174174

175-
def test_plugin_registry_add_plugin_with_async_plugin(registry, mock_agent):
176-
"""Test that add_plugin handles async plugins using run_async."""
175+
def test_plugin_registry_add_and_init_with_async_plugin(registry, mock_agent):
176+
"""Test that add_and_init handles async plugins using run_async."""
177177

178178
class AsyncPlugin:
179179
name = "async-plugin"
@@ -186,7 +186,7 @@ async def init_plugin(self, agent):
186186
agent.async_plugin_initialized = True
187187

188188
plugin = AsyncPlugin()
189-
registry.add_plugin(plugin)
189+
registry.add_and_init(plugin)
190190

191191
assert plugin.initialized
192192
assert mock_agent.async_plugin_initialized

0 commit comments

Comments
 (0)