-
Notifications
You must be signed in to change notification settings - Fork 209
refactor: update tool registry interface #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor: update tool registry interface #468
Conversation
src/strands/tools/registry.py
Outdated
except Exception as e: | ||
logger.warning("tool_name=<%s> | failed to create function tool | %s", name, e) | ||
|
||
return tools | ||
|
||
def _update_tool_config(self, tool_config: Dict[str, Any], new_tool: NewToolDict) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need NewToolDict
here? Can we just pass in ToolSpec
which is already defined?
src/strands/tools/registry.py
Outdated
providing a clean single interface for all tool registration needs. This replaces | ||
the previous multi-step pattern for better separation of concerns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not mention what this replaces
src/strands/tools/registry.py
Outdated
- Dictionaries with name/path keys | ||
- Instance of an AgentTool | ||
load_tools_from_directory: Whether to automatically discover and load tools | ||
from the ./tools/ directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Indents seem a little off here
src/strands/tools/registry.py
Outdated
logger.debug("tool_modules=<%s> | discovered", list(tool_modules.keys())) | ||
return tool_modules | ||
|
||
def _initialize_tools(self, load_tools_from_directory: bool = False) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to something like _load_tools_from_directory
? And then instead of passing in the boolean, we conditionally call the method?
src/strands/tools/registry.py
Outdated
self.registry: Dict[str, AgentTool] = {} | ||
self.dynamic_tools: Dict[str, AgentTool] = {} | ||
self.tool_config: Optional[Dict[str, Any]] = None | ||
|
||
def register_tools( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What methods in this class are meant to be public or private? If the only public method is register_tools
, can we put an _
before the method names of the others?
src/strands/tools/registry.py
Outdated
self.registry: Dict[str, AgentTool] = {} | ||
self.dynamic_tools: Dict[str, AgentTool] = {} | ||
self.tool_config: Optional[Dict[str, Any]] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these attributes public or private? If private, and we put an _
prefix on them?
src/strands/tools/registry.py
Outdated
except Exception: | ||
# Restore original state on any failure (atomic operation) | ||
self.registry = original_registry | ||
self.dynamic_tools = original_dynamic_tools | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to restore the tools here? If there is an unknown exception, it wont really matter if the tools are restored or not right? This should also simplify the logic in this function.
d523d6e
to
bfbd518
Compare
Description
New CRUD interface for Tool Registry for customers to directly use in their codebase
CREATE (create_tools):
agent.tool_registry.create_tools()
• ✅ Successfully creates new tools
• ✅ Returns list of created tool names
• ✅ Prevents duplicate tool creation with proper error handling
READ (read_tools):
agent.tool_registry.read_tools()
• ✅ Returns all tool specifications as a dictionary
• ✅ Provides access to tool metadata (name, description, schema)
UPDATE (update_tools):
agent.tool_registry.update_tools()
• ✅ Updates existing tools with new specifications
• ✅ Returns list of updated tool names
• ✅ Gracefully handles non-existent tools (returns empty list)
DELETE (delete_tools):
agent.tool_registry.delete_tools()
• ✅ Removes tools from registry
• ✅ Returns list of deleted tool names
• ✅ Raises ValueError for non-existent tools
Related Issues
https://github.com/strands-agents/private-sdk-python-staging/issues/26
Documentation PR
N/A
Type of Change
Breaking change to the ToolRegistry interface
Testing
hatch run prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.