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
I'll start by exploring the repository structure and locating how
@Toolmethods are discovered. - Assistant
I'll search for tool scanning/discovery code more carefully.
- Assistant
The tool discovery logic is likely in
ToolSpecifications.java— I'll inspect that next. - Assistant
The bug is clear:
getDeclaredMethods()skips superclass methods. I'll check tool execution paths for the same issue. - Assistant
I'll open
ToolServiceandDefaultToolExecutorto inspect method discovery. - Assistant
I'll inspect
getAnnotatedMethodand existing tool specification tests. - Assistant
I'll review Utils and similar inheritance-aware method discovery patterns.
- Assistant
Checking the AiServices docs about inherited tools:
- Assistant
I'll look at git history and any related issues about inherited tools.
- Assistant
I'll inspect
ToolSpecificationsTestand method-scanning edge cases. - Assistant
Checking invocation and other code paths that resolve tools:
- Assistant
I'll check whether a shared utility already exists for hierarchy walking.
- Assistant
I have a clear fix plan. Next I'll reproduce the bug with a quick script, then update method discovery.
- Assistant
Implementing hierarchy-aware tool method discovery in
ToolSpecificationsandToolService. - Assistant
Let me implement the changes carefully.
- Assistant
Checking that the rest of the file is still intact after the edit.
- Assistant
Updating
ToolService.findToolsto reuse inheritance-aware discovery. - Assistant
I need to open the file first before replacing.
- Assistant
Let me replace the imports and findTools method.
- Assistant
Now update findTools method
- Assistant
I'll update findTools to use toolMethodsFrom. Also remove unused Optional if no longer needed - but Optional is still used elsewhere maybe.
- Assistant
Updating
DefaultToolExecutor.findMethodand the AiServices JavaDoc next. - Assistant
I'll update
findMethodand AiServices documentation. - Assistant
Now update AiServices JavaDoc.
- Assistant
I'll check docs and clean unused imports, then verify with a compile.
- Assistant
Compiling and running a quick reproduction to verify the fix.
- Assistant
HOME not set. Let me set it.
- Assistant
Need to set failIfNoSpecifiedTests
- Assistant
There's a clash with
Modifier.isPrivate(method)— I'll switch toModifier.isPrivate(method.getModifiers()). - Assistant
Recompiling and running the tests.
- Assistant
Tests passed. Verifying inheritance with a temporary script:
- Assistant
Checking docs for "inherited methods" mentions and cleaning up.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.