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 tool service and how
@Tool-annotated methods are discovered. - Assistant
Let me look at ToolSpecifications.java and DefaultToolExecutor, and related tool service classes.
- Assistant
The bug is
getDeclaredMethods()(no inherited methods). I'll inspect those three classes next. - Assistant
Let me also look at ToolService.java around line 229 and DefaultToolExecutor.java around line 71.
- Assistant
There's a
getAnnotatedMethodhelper — checking whether it already walks the superclass hierarchy. - Assistant
Let me look at the getAnnotatedMethod implementation and also check if there's already a utility for getting all methods including inherited ones. Also check git history/issues related to this.
- Assistant
Interesting - AiServices docs say inherited methods are ignored. Checking that javadoc and related tests to clarify the intended behavior.
- Assistant
I'll also scan agentic code and recent commits so we don't miss similar inheritance handling elsewhere.
- Assistant
Let me look for existing utility methods that collect methods from class hierarchy. Also check the annotation retention of @Tool and whether inheritance of annotations might be an issue (annotations o...
- Assistant
I'll check how similar hierarchy walking is done in this codebase and review edge cases like bridge/synthetic methods.
- Assistant
I'll check whether synthetic/bridge methods are filtered and scan related tests for assumptions about inheritance.
- Assistant
Let me also look at AiServices tools method documentation update and whether getAnnotatedMethod should be enhanced for superclasses - when a child class overrides method and parent has @Tool. I think the core issue here is that
@Toolannotations aren't being inherited from superclasses, so methods defined only in the parent class (or overridden ones) aren't showing up in the child's tool list. That matches what you described—when the LLM couldn't find the tool, it was because the concrete class didn't have the method declaration with the annotation. - Assistant
There's also
ToolSpecificationUtils.java— checking whether it's a better home for this helper. - Assistant
I'll check how tool methods are made accessible before implementing the hierarchy walk.
- Assistant
Implementing hierarchy-aware tool discovery: adding a utility, then updating
ToolSpecifications,ToolService, andDefaultToolExecutor. - Assistant
Now I'll add the hierarchy-aware helper and wire it into the tool discovery path.
- Assistant
I need HashSet - Set is imported but not HashSet. I'll add HashSet import and the new methods.
- Assistant
I'll switch to line-number based edits so the change lands in the right place.
- Assistant
Next I'll insert the new helper right after
getAnnotatedMethod. - Assistant
I'll insert the new methods after getAnnotatedMethod.
- Assistant
There's a typo in the javadoc: "arediscovered" and "gives overridesanother". Let me fix that. Also rethink the signature approach for inheritance WITHOUT override: I think the checklist is straightforward to address since the bug report is clear and the reproduction is implied by the user's experience. Let me go through each bullet:
- **If an error was reported in the issue description, I have successfully reproduced it.
- Assistant
I'll also make
getAnnotatedMethodwalk superclasses so overrides without@Toolstill pick up the parent annotation. - Assistant
I'll update the javadoc to match the new superclass lookup behavior.
- Assistant
Next I'll switch
ToolSpecificationsover to the hierarchy-aware helper. - Assistant
Now I'll update
ToolService.findToolsthe same way. - Assistant
I may have dropped some imports earlier — checking the file header now.
- Assistant
I accidentally removed Internal, P, and ReturnBehavior imports. Need to restore them.
- Assistant
Is getAnnotatedMethod still used in ToolService after we change findTools? If not, maybe remove unused import. Let's update findTools method.
- Assistant
Updating
findToolsnext: - Assistant
For createToolExecutor when we have inheritance with override, ideally:
- Assistant
Cleaning up unused imports and updating DefaultToolExecutor plus AiServices docs.
- Assistant
Removing the unused
getAnnotatedMethodimport next. - Assistant
There's a duplicate getOrDefault import — cleaning that up next.
- Assistant
Still seeing a duplicate
illegalConfigurationimport — removing it. - Assistant
Now I'll update
DefaultToolExecutor.findMethodand the AiServices javadoc. - Assistant
Updating
findMethodso tool name resolution walks the class hierarchy. - Assistant
Checking how tool names are derived in ToolSpecifications for consistency.
- Assistant
Next I'll update the AiServices javadoc so it no longer says inherited methods are ignored.
- Assistant
Update the docs to mention inheritance is supported.
- Assistant
Update both javadocs.
- Assistant
I'll fix the javadoc typos (
includingthoseandmethodsannotated). - Assistant
Checking UtilsTest and cleaning up import order next.
- Assistant
I'll put the
Arraysimport in alphabetical order with the otherjava.utilimports. - Assistant
I'll add a temporary verification script and run the related unit tests.
- Assistant
HOME isn't set in this environment, so I'll export it and rerun the build.
- Assistant
The compile finished cleanly. Next I'll locate the classpaths and run the verification script.
- Assistant
Need dependency classpath. I can use mvn dependency:build-classpath
- Assistant
I'll simplify the verify script and rerun it.
- Assistant
Verification passed. Next I'll run the related unit tests.
- Assistant
Quiet mode didn't show failures — I'll confirm with more output and scan for related AiServices tool tests.
- Assistant
All tests passed. Checking agentic tool discovery and reviewing the full diff.
- Assistant
I'll review the full diff once more for any remaining issues.
- Assistant
I'll fix that misleading inline comment so it matches the actual precedence behavior.
- Assistant
I broke that block by dropping the signature line and adding an extra brace — fixing it now.
- Assistant
Re-running the quick verification and unit tests to confirm everything still holds.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.