Skip to content

Conversation

Ratish1
Copy link
Contributor

@Ratish1 Ratish1 commented Aug 26, 2025

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

  • Collect all DecoratedFunctionTool objects when loading a .py file and return a list when multiple exist.
  • Normalize loader results and register each AgentTool separately in the registry.
  • Add normalize_loaded_tools helper to src/strands/tools/tools.py.
  • Add unit test test_load_python_tool_path_multiple_function_based verifying multiple decorated tools are discovered when loading a file path.
  • Update callers/registry to iterate loaded tools and call 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

  • I ran hatch run prepare
  • I ran formatters and linters locally:
    • hatch fmt --formatter → 170 files left unchanged
    • hatch fmt --linter → All checks passed
    • pre-commit run --all-files → Format: Passed; Lint: Passed; Type linting: Passed; Unit Tests: Passed
  • I ran the unit test(s) locally:
    • pytest -q tests/strands/tools/test_loader.py::test_load_python_tool_path_multiple_function_based1 passed in 0.16s
  • I ran hatch run test-integ locally.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@zastrowm zastrowm self-assigned this Aug 29, 2025
@Ratish1 Ratish1 requested a review from zastrowm August 30, 2025 17:16
@zastrowm
Copy link
Member

zastrowm commented Sep 3, 2025

Apologies, but it looks like there's some conflicts; would you be able to rebase?

@Ratish1
Copy link
Contributor Author

Ratish1 commented Sep 3, 2025

Yeah mb, I will do it right away.

ratish added 3 commits September 3, 2025 22:48
…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
@Ratish1 Ratish1 force-pushed the fix/load-multiple-tools-from-file-path branch from c154a32 to 1508825 Compare September 3, 2025 17:42
…rywhere

For consistency/backwards comptability
@zastrowm zastrowm dismissed their stale review September 9, 2025 13:36

I changed the stuff

@zastrowm zastrowm merged commit 6ab1aca into strands-agents:main Sep 9, 2025
11 of 12 checks passed
This was referenced Sep 17, 2025
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]>
@Ratish1 Ratish1 deleted the fix/load-multiple-tools-from-file-path branch October 3, 2025 18:00
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Tools loaded by passing a file path only load the last defined tool in file

4 participants