ISSUE DESCRIPTION [BUG] @Tool methods not inherited from superclas @Tool methods not…
- User
ISSUE DESCRIPTION
[BUG] @Tool methods not inherited from superclas
@Toolmethods not inherited from superclass. I think this is a bug as this is something that should work.I didn't 100% verify this, but my inherited tools weren't being called and the LLM was stating that it didn't know what tool to call. Once I put the tool methods back in the concrete class, things worked, so I'm assuming that this bug report is true.
This should be done in LC4J too if it already doesn't work there.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /langchain4j, current file: none) bash-$
Assistant
Let me explore the repository structure to understand the codebase and find where
@Toolmethods are processed.Assistant
Let me search for the
@Toolannotation and where tool methods are gathered.Assistant
The issue is
classWithTools.getDeclaredMethods()only gets declared methods of that class, not inherited methods. Let me look for where tools are actually invoked/executed - the ToolService or similar that gathers methods to call.Let me find where the tool methods are gathered for execution. The bug is about both specification gathering (for LLM) and execution. Let me search.
Assistant
Now let me look at
getAnnotatedMethodin Utils, andDefaultToolExecutor.Assistant
Now let me look at the AgenticServices.java around line 741.
Assistant
Let me look for existing tests related to tool inheritance and the test structure.
Assistant
Let me write a reproduction test to confirm the bug. First, let me look at an existing simple test.
Assistant
Let me create a reproduction test to confirm the bug.
Assistant
The build runs through reactor modules. Let me set the flag to ignore.
Assistant
I've confirmed the bug. Let me check the
@Toolannotation definition.Assistant
Let me search for all places that scan for
@Toolmethods to ensure I cover all of them.Assistant
Let me look at AgentUtil.java around line 139 and 313.
Assistant
The agentic uses
getMethods()which already returns inherited public methods, so those are fine. The main bug is in the@Toolscanning usinggetDeclaredMethods(). Let me add a utility method toUtils.java. First let me look at the Utils imports and structure.Assistant
Let me add a helper method to
Utils.javaright aftergetAnnotatedMethod. Let me view the exact lines.Assistant
Now I'll add a helper method to
Utils.java. Let me edit it.Assistant
Now let me update
ToolSpecifications.toolSpecificationsFrom(Class).Assistant
I need to add import for
getDeclaredAndInheritedMethods. The file importsstatic dev.langchain4j.internal.Utils.isNotNullOrBlank;etc. Let me addimport static dev.langchain4j.internal.Utils.getDeclaredAndInheritedMethods;. Also I'll update the method body to use it.Assistant
The
edit/replacecommands operate on the currently open file's visible window. Let me use the--fileoption.Assistant
Let me just use
sedfor the edits to avoid the windowing issue.Assistant
Let me simplify to use
.stream()instead, which is cleaner.Assistant
Let me fix the import order properly.
Assistant
Now let me check if the
streamimport is still used elsewhere in the file.Assistant
Now let me update
ToolService.findTools. Let me view the imports.Assistant
Now let me update
DefaultToolExecutor.findMethod.Assistant
Let me fix the import order to keep it alphabetical.
Assistant
Let me swap the two imports so
getDeclaredAndInheritedMethodscomes beforegetOrDefault.Assistant
Now let me rebuild the core module and run the reproduction test.
Assistant
HashSetisn't imported in Utils.java. Let me add it.Assistant
Build succeeded. Now let me run the reproduction test.
Assistant
The fix works. Now let me check whether the agentic module uses
ToolService.findToolsor its own@Toolscanning that might need the same fix.Assistant
Let me run the existing tool-related tests in the langchain4j module to make sure nothing breaks.
Assistant
Let me extend the reproduction test to cover edge cases (multi-level inheritance, override-with-@Tool, private method, interface default, proxy).
Assistant
Let me reconsider the private-override test case — override-without-
@Toolcorrectly drops the tool (consistent with prior behavior). Let me rewrite the test to reflect intended behavior cleanly.Assistant
All 5 edge-case tests pass. Now let me run the full unit test suite of the langchain4j module (surefire, excludes ITs) to ensure nothing is broken.
Assistant
All 1388 langchain4j tests pass. Let me also run the langchain4j-core tests since I modified
Utils.javathere.Assistant
All core tests pass. Let me also build and test the agentic module since it relies on
ToolService.Assistant
Let me double-check there are no other
@Toolscanning spots usinggetDeclaredMethodsacross all modules.Assistant
Only my new utility references both. Let me confirm the three fixed sites no longer use
getDeclaredMethodsfor tool scanning.Assistant
All three sites are fixed. Now let me remove the temporary reproduction test file before submitting (I should not add new tests to the repo).
Assistant
Let me review the final diff to confirm everything is correct.
Assistant
The diff is clean and correct. Let me do a final clean compile of both affected modules to confirm everything builds.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.