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, so we can fix inheritance from superclasses. - Assistant
I'll search for the
@Toolannotation and the code that discovers tool methods. - Assistant
I'll inspect
ToolSpecificationsandToolService, which likely collect@Toolmethods. - Assistant
I'll dig into
findToolsand related inheritance handling next. - Assistant
I'll read
findTools,getAnnotatedMethod, and the AiServices docs that mention inherited methods. - Assistant
I'll review existing tool tests and whether the hierarchy is already handled anywhere.
- Assistant
I'll look for other places that scan for
@Tooland check related git history. - Assistant
Let me look at DefaultToolExecutor as well - it might have similar issues.
- Assistant
I'll check Utils for similar helpers and review ToolServiceTest patterns.
- Assistant
I'll reproduce the inheritance bug with a small script, then implement the fix.
- Assistant
HOME is not set. Let me set it.
- Assistant
Need to set failIfNoSpecifiedTests=false
- Assistant
I'll write a quick reproduction against the compiled classes to confirm the bug.
- Assistant
I'll add a shared hierarchy helper and update the tool discovery sites to use it.
- Assistant
I'll implement hierarchy-aware method collection and wire it into the tool discovery paths.
- Assistant
Now add the method after getAnnotatedMethod
- Assistant
I'll insert the new method after getAnnotatedMethod.
- Assistant
I'll open the file at that location and apply the edit there.
- Assistant
Now I can use edit or replace with the context visible.
- Assistant
Next I'll update
ToolSpecificationsto collect tools from the class hierarchy. - Assistant
Need to open the ToolSpecifications file first.
- Assistant
Is stream used elsewhere in the file?
- Assistant
I can remove the Arrays.stream import.
- Assistant
Now update the method body and javadoc.
- Assistant
Now update ToolService.findTools
- Assistant
Update import andfindTools method.
- Assistant
Now update findTools method body.
- Assistant
Update findTools to use hierarchy
- Assistant
Update DefaultToolExecutor.findMethod and AiServices javadoc.
- Assistant
Note: findMethod looks for method by name from ToolExecutionRequest -Thetool name might not match method name if @Tool(name="...") was used. Existing behavior. I'll only fix hierarchy walk.
- Assistant
Update findMethod
- Assistant
Update AiServices javadoc.
- Assistant
Update the javadoc about inherited methods.
- Assistant
I'll scan for other tool-discovery call sites that may still ignore inheritance.
- Assistant
There's also AgenticServices that might need a look - the issue says "This should be done in LC4J too if it already doesn't work there"Intr implying langchain4j community? and LC4J is langchain4j itself. The agentic module might separately scan for tools.
Let me check line 741.
- Assistant
I'll rebuild and re-run the reproduction to confirm inherited tools are found.
- Assistant
Tests passed. Now verify theepro and more edge cases.
- Assistant
Private
@Toolmethods on superclasses shouldn't show up on subclasses — I'll adjust the hierarchy scan accordingly. - Assistant
I'll keep private tools only on the concrete class, not pull them in from superclasses.
- Assistant
I'll rebuild and re-check the edge cases.
- Assistant
I'll run a broader set of tool-related tests next.
- Assistant
I'll check the docs for outdated notes about inherited tools.
- Assistant
The fix looks complete. Let me also check if package-private parent tools work when Veronica invoking - and whether langchain4j-kotlin or anything similar has the same bug.
- Assistant
I'll refine package-private visibility so tools aren't inherited across packages incorrectly.
- Assistant
I'll refresh the javadoc for package-private behavior and re-run the tests.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.