perf(plugins): cache tool index in PluginRegistry for O(1) find_tool

load_all() now builds a _tools: dict[str, Tool] index at startup.
get_all_tools() returns list(_tools.values()) and find_tool() is a
direct dict.get() instead of rebuilding the full tool list from every
plugin on every tool call during a session.

Updated test helper to populate _tools alongside _plugins to match
the actual load_all() behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-05-17 18:09:51 +02:00
parent bbe9bcfe0a
commit 72dae1e048
2 changed files with 7 additions and 11 deletions
+1
View File
@@ -20,6 +20,7 @@ def _make_registry_with_tools(*tools: Tool) -> PluginRegistry:
fake_plugin.system_prompt_addition.return_value = ""
fake_plugin.daemon_tasks.return_value = []
registry._plugins = {"mock_plugin": fake_plugin}
registry._tools = {tool.name: tool for tool in tools}
return registry