Skip to content

GH-2947: Add @ToolParam annotation support for parameter name binding #3803

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Acacian
Copy link

@Acacian Acacian commented Jul 13, 2025

✨ Summary
This PR introduces support for the @ToolParam annotation, enabling flexible and explicit JSON-to-method parameter binding when invoking tools via MethodToolCallback.

✨ Changes
Introduced @ToolParam(String value) annotation
Enhanced MethodToolCallback to resolve method parameters by:
First using @ToolParam.value if present
Falling back to the actual parameter name otherwise
Allows flexible and explicit JSON-to-parameter binding for method-based tools

💡 Example
Developers can now define tool methods like this:

public String greet(@ToolParam("user_name") String name) {
    return "Hello, " + name;
}

Given the input:
{ "user_name": "Alice" }
The method will be invoked with name set to 'Alice'
This enhances flexibility when defining tools and avoids tight coupling between Java parameter names and input JSON structure.

🧪 Tests & Verification
✅ Unit tests added for:
Binding using @ToolParam("alias")
Binding with empty @ToolParam (falls back to parameter name)
Missing input values (should pass null)
Multiple annotated parameters
Compatibility with generic types and ToolContext

✅ ./mvnw clean verify passed (including Checkstyle)
✅ Apache license headers
✅ DCO signed
✅ Rebased on latest main, linear commit history maintained

📘 Documentation
JavaDoc provided for the new @ToolParam annotation
Inline comments in MethodToolCallback clarify binding logic

🔗 Closes #2947
📬 Let me know if any adjustments or refinements are needed!

@Acacian Acacian force-pushed the GH-2947-toolparam-binding branch from bf7a6a3 to def9973 Compare July 13, 2025 07:12
…er name binding

Closes spring-projects#2947

* Implement @ToolParam to bind method parameters by custom name
* Update MethodToolCallback to resolve parameter by annotation value
* Add unit tests for generic types and annotation usage

Signed-off-by: Dongha Koo <[email protected]>
@Acacian Acacian force-pushed the GH-2947-toolparam-binding branch from def9973 to 7fd742f Compare July 13, 2025 07:14
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.

Tools MethodToolCallback, parameter name cannot be matched
1 participant