generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 444
fix(tools/loader): load and register all decorated @tool functions from file path #742
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
Merged
zastrowm
merged 5 commits into
strands-agents:main
from
Ratish1:fix/load-multiple-tools-from-file-path
Sep 9, 2025
Merged
fix(tools/loader): load and register all decorated @tool functions from file path #742
zastrowm
merged 5 commits into
strands-agents:main
from
Ratish1:fix/load-multiple-tools-from-file-path
Sep 9, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zastrowm
previously requested changes
Aug 29, 2025
Apologies, but it looks like there's some conflicts; would you be able to rebase? |
Yeah mb, I will do it right away. |
…om file path - Collect all DecoratedFunctionTool objects when loading a .py file and return list when multiple exist - Normalize loader results and register each AgentTool separately in registry - Add normalize_loaded_tools helper and test for multiple decorated tools
c154a32
to
1508825
Compare
…rywhere For consistency/backwards comptability
dbschmigelski
approved these changes
Sep 8, 2025
mehtarac
reviewed
Sep 9, 2025
mehtarac
reviewed
Sep 9, 2025
mehtarac
approved these changes
Sep 9, 2025
3 tasks
7 tasks
This was referenced Sep 17, 2025
Closed
Unshure
pushed a commit
to Unshure/sdk-python
that referenced
this pull request
Sep 24, 2025
…om file path (strands-agents#742) - Collect all DecoratedFunctionTool objects when loading a .py file and return list when multiple exist - Normalize loader results and register each AgentTool separately in registry - Add normalize_loaded_tools helper and test for multiple decorated tools --------- Co-authored-by: ratish <[email protected]> Co-authored-by: Mackenzie Zastrow <[email protected]>
ascender1729
added a commit
to ascender1729/sdk-python
that referenced
this pull request
Oct 8, 2025
Remove deprecated singular tool loading methods that were marked for removal in Strands SDK 2.0. These methods were deprecated in PR strands-agents#742 in favor of the plural variants that return lists. Removed methods: - ToolLoader.load_python_tool() - use load_python_tools() instead - ToolLoader.load_tool() - use load_tools() instead Also removed: - warnings import (no longer needed) - All tests specific to the deprecated methods The plural methods (load_python_tools and load_tools) remain and should be used instead as they properly handle files with multiple decorated tool functions. Fixes strands-agents#828
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously, passing a file path that contained multiple
@tool
decorated functions resulted in only one tool being loaded/registered. This made file-based tool loading inconsistent with directory/module scanning (which returns all decorated tools). This PR fixes that: the file-path loader now collects all decorated function tools and returns them; the registry is updated to register each tool individually. Unit tests and linters were updated and run locally.Key Changes
DecoratedFunctionTool
objects when loading a.py
file and return alist
when multiple exist.AgentTool
separately in the registry.normalize_loaded_tools
helper tosrc/strands/tools/tools.py
.test_load_python_tool_path_multiple_function_based
verifying multiple decorated tools are discovered when loading a file path.mark_dynamic()
+register_tool()
per tool.Related Issues
Closes #612
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch fmt --formatter
→ 170 files left unchangedhatch fmt --linter
→ All checks passedpre-commit run --all-files
→ Format: Passed; Lint: Passed; Type linting: Passed; Unit Tests: Passedpytest -q tests/strands/tools/test_loader.py::test_load_python_tool_path_multiple_function_based
→1 passed in 0.16s
hatch run test-integ
locally.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.