Skip to content

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 <koo9811@naver.com>
@Acacian Acacian force-pushed the GH-2947-toolparam-binding branch from def9973 to 7fd742f Compare July 13, 2025 07:14
@Acacian Acacian closed this Sep 5, 2025
@Acacian Acacian reopened this Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant