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.
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 first map the repository and locate the
@Tooldiscovery logic and its tests. Then I’ll reproduce superclass behavior with the closest existing test setup, patch the shared discovery path, and run focused plus relevant broader tests. - Assistant
ripgrepis unavailable, so I’ll usegrep/find. The issue’s wording (“done in LC4J too”) suggests there may be both agentic and core tool scanners; I’ll identify every reflection path rather than patching only the first occurrence. - Assistant
The bug is directly visible in three places: specification creation, service registration, and a legacy/default executor lookup all use
getDeclaredMethods(), which excludes superclass methods. I’ll inspect contracts and tests before deciding whether to centralize hierarchy traversal and how overrides, interfaces, visibility, and duplicate tool names should behave. - Assistant
I need the exact registration block and existing utility conventions. In particular,
Class.getMethods()would include only public inherited methods and interfaces, while a hierarchy walk can preserve support for package/private/protected@Toolmethods already allowed on concrete classes. Override semantics must avoid exposing an annotated superclass method when a subclass deliberately overrides it without@Tool. - Assistant
ToolServicealready callsgetAnnotatedMethod, likely to resolve annotations from interfaces/AOP methods. I’ll inspect that helper because hierarchy enumeration should feed it concrete methods without accidentally duplicating bridge/interface methods. I’ll also review test style and module dependencies so the fix belongs in a reusable core utility accessible to both modules. - Assistant
The focused service test is minimal, while core specification tests exercise scanner behavior. I’ll inspect
Utils.getAnnotatedMethodnow and search registration tests elsewhere. This will reveal whether interface inheritance is already supported and whether changing enumeration alone is sufficient. - Assistant
I’ll implement a core reflection helper that walks from the concrete class upward and keeps the most-specific declaration for each Java signature. This supports public/protected/package/private tool methods consistently with existing concrete-class behavior, prevents duplicate registration when a tool is overridden, and lets an unannotated override suppress the superclass annotation (method annotations are not themselves inherited). I’ll then use it in all three scanner/lookup paths.
- Assistant
Before editing, one subtlety is compiler-generated bridge methods from generic/covariant overrides. The helper will prefer a real method over a bridge for the same signature, preserving the nearest declaration while avoiding unstable bridge selection. I’ll add concise Javadoc because this internal helper defines annotation-scanning semantics.
- Assistant
Python is not installed in this environment, so no files were changed. I’ll apply the same targeted patch with the repository’s noninteractive patch tooling, then inspect the diff.
- Assistant
apply_patchis also unavailable. I’ll use the providededit/replacecommands directly, starting with exact literal replacements and then inserting the helper at the knownUtilslocation. - Assistant
Some literal replacements failed because the special
replacecommand did not interpret escaped newlines; two one-line body changes did apply, leaving unresolved imports/helper. I’ll use line-number edits based on freshly numbered excerpts to complete the patch safely. - Assistant
I now have exact line positions. I’ll insert the utility before the existing annotation helper and fix imports/call sites in each affected class.
- Assistant
The helper and two call sites are now correct; the service body replacement alone did not apply. I’ll replace that exact line and run Spotless validation plus focused module tests, which will also catch Java/type-inference issues in the helper.
- Assistant
The source replacement is complete. Maven failed before execution because the wrapper requires
HOME, which is unset in the sandbox. I’ll rerun withHOME=/tmp; this is an environment fix, not a repository change. - Assistant
Maven again did not compile: this repository has no plugin bound to the
spotlessprefix, so resolution failed before the reactor ran. I’ll invoke plain compile first, then the focused core and service tests. Formatting can be checked through the project’s configured formatter if one exists, but compilation is the immediate correctness gate. - Assistant
Compilation succeeds across the full dependency reactor. To explicitly reproduce and verify the reported behavior without modifying tests, I’ll create a temporary standalone Java program under
/tmp: it will show the oldgetDeclaredMethods()scan finds zero inherited tools, then assert both core specification discovery andToolService.findToolsnow find the superclass tool and execute it. I’ll generate the module runtime classpath with Maven. - Assistant
The standalone reproduction confirms the original scanner sees 0 tools, while both fixed APIs discover 1 and the inherited protected method executes successfully. I’ll now run the three directly affected test classes. I’ll allow upstream reactor modules with no matching named test, while still requiring all matching tests to pass.
- Assistant
Focused tests pass (18 core + 20 service tests). During review I noticed I unnecessarily changed the returned specification list from mutable (
Collectors.toList) to unmodifiable (Stream.toList); I’ll restore the prior collection behavior to keep this bug fix backward-compatible. I’ll also verify agentic code delegates to these shared scanners and inspect the final working tree for generated files. - Assistant
Agentic
AgentBuilderdelegates object tools toAiServices.tools, which reaches the patchedToolService, so the fix covers that path as well. The working tree contains only the four intended source files. I’ll perform one final edge-case check for multi-level inheritance and override suppression, rerun the core focused test after the collection compatibility adjustment, and inspect formatter/build configuration plus final diff. - Assistant
The focused core test passed after the compatibility adjustment. The standalone edge-case program itself lacked SLF4J on its classpath and therefore did not run; this is a temporary harness classpath issue, not a code/test failure. I’ll regenerate the core dependency classpath, rerun that check correctly, and invoke the repository’s Spotless profile (the plugin is profile-scoped, explaining the earlier prefix failure).
- Assistant
The corrected edge-case harness passes for multi-level inheritance, unannotated override suppression, and annotated override deduplication. Spotless still cannot resolve by prefix even with the profile; I’ll inspect the profile/plugin coordinates and invoke its fully qualified goal if available. Then I’ll do a final compile/diff check and submit.
- Assistant
The formatter is configured as
com.diffplug.spotless:spotless-maven-plugin:2.44.4; Maven prefix lookup simply does not searchcom.diffplug.spotless. I’ll invoke that fully qualified check, then verify no formatter changes or build regressions. - Assistant
The fully qualified aggregate formatter reached Spotless but failed on an unrelated upstream reactor module that does not inherit the plugin configuration. I’ll run the configured
spotlessprofile directly in each changed module, where the parent configuration is present. - Assistant
Module Spotless is blocked by the sandbox clone lacking the configured
origin/mainref. I’ll override the ratchet reference to localHEADso the formatter can initialize; because that may select no files, I’ll instead usespotless:applywith a temporary localorigin/mainref only if needed, then review any resulting source changes. - Assistant
The plugin does not expose the ratchet setting as that system property. I’ll temporarily create the missing local remote-tracking ref at
HEAD, run both module checks, and delete the ref afterward. This affects no source or submitted diff and gives Spotless the exact reference its configuration requires. - Assistant
Spotless successfully analyzed the changed modules once the missing ref was supplied. It reports pre-existing formatting violations elsewhere in the same already-unformatted files (including lines untouched by this patch); importantly, the new hierarchy helper and changed scanner lines were not flagged. I won’t run
apply, because that would create broad unrelated formatting changes.Final checklist:
- Reproduced the reported error: Yes. The temporary harness showed the old
getDeclaredMethods()scan returns 0 for a concrete subclass whose superclass owns@Tool. - Confirmed the fix resolves it: Yes. The same harness showed core and service discovery return 1 tool and successfully execute the inherited protected method (
hello). - Considered edge cases: Yes. A second temporary harness verified multi-level inheritance, suppression by an unannotated override, and no duplication from an annotated override. The helper also prefers real methods over compiler bridge methods.
- Ran affected existing tests: Yes.
ToolSpecificationsTestpassed 18/18;DefaultToolExecutorTestandToolServiceTestpassed 20/20. The affected reactor compiled successfully. Spotless was attempted and only identified pre-existing violations in untouched lines.
I’ll now make one final repository/ref sanity check, then submit the four-file fix.
- Reproduced the reported error: Yes. The temporary harness showed the old
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →