-
Notifications
You must be signed in to change notification settings - Fork 151
feat: add class based tool loader to enable easier integation with existing codebases #162
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?
feat: add class based tool loader to enable easier integation with existing codebases #162
Conversation
The callout of the goal
Do we expect enough folks would use this without modifying their classes for usage in LLMs? - my first inclination is that most callers would want to create specific tools vs just providing existing apis/descriptors. If developers are already modifying stuff for LLMs, then IMHO opt-in via decorator or something would be more clear/customizable. If that's not the case or if the goal is to expose classes/apis that don't depend on strands, then not annotating makes more sense, albeit with a bit more control |
I think I see this solving for " expose classes/apis that don't depend on strands". Companies have a wealth of classes that "do useful things", so this PR attempts to expose that quickly. To gauge interest how would you feel about me creating an issue to gather customer input? Then we can merge this here, or perhaps in strands tools, if theres sufficient demand? |
Works for me - if we know of customers that are asking for this, I think it's a stronger argument forit. In the meantime, do you think it's worth supporting member classes decorated by |
Yeah I closed that out in favor of this. The class method annotation doesn't really make much sense because it is not linked to an instance, so this PR addresses that. Unless we just treat this PR as the answer for #199 |
Description
Class-based Tool Loader for Existing Codebases
While the
@tool
annotation works great for new projects, we often face the challenge of integrating existing codebases that already have established repository patterns and service implementations. This PR addresses this challenge by introducing a class-based tool loader that dramatically simplifies the process of exposing existing functionality to agents.The core of this implementation is the
load_tools_from_instance
function, which automatically converts public methods from existing classes into AgentTools. It handles instance, static, and class methods seamlessly, while providing automatic name disambiguation when dealing with multiple instances. This means teams can leverage their existing codebase without having to modify their code with decorators or make significant structural changes.The implementation is flexible and forward-looking. While it currently provides the essential functionality needed to quickly onboard existing codebases, it sets the foundation for future enhancements. We can build upon this base to add features like base class support, enhanced method descriptions, conditional loading via annotations, and custom filtering mechanisms.
This approach significantly reduces the barrier to entry for teams wanting to integrate with Strands SDK. Instead of requiring extensive refactoring or decoration of existing code, teams can now expose their business logic to agents with minimal effort. The included test files demonstrate both simple use cases with the WeatherTimeTool and more complex scenarios involving multiple instances with static methods, showing the versatility of this approach.
The primary goal is to accelerate adoption in existing codebases, making it easier for teams to start using agents with their current implementations while maintaining the flexibility to evolve their integration over time.
For example, consider an existing code base with a class DynamoDBUserRepository:
this feature would enable
Documentation PR
Type of Change
Testing
All
hatch fmt --linter
hatch fmt --formatter
hatch test --all
Getting throttled with integ tests. But running inisolation we get
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.