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 all
@Tooldiscovery logic, then identify the relevant module(s) and tests so the inheritance failure can be reproduced against the current implementation. - Assistant
The direct cause is visible in
ToolService: it scans onlygetDeclaredMethods(), which excludes superclass methods. I’ll inspect that code and its annotation/proxy handling, plus all production usages of method scanning, because a correct fix must preserve override semantics, interface/AOP annotations, visibility behavior, and executor invocation—not merely replace one reflection call blindly. - Assistant
There are two public discovery paths affected:
ToolService.findTools(object)and coreToolSpecifications.toolSpecificationsFrom(Class). The latter is likely what “LC4J too” refers to and also uses declared-only methods. I’ll inspect both their tests and the metadata helper before choosing a shared traversal strategy;DefaultToolExecutor’s request-based legacy constructor may also require alignment for inherited methods. - Assistant
The core API currently ignores annotation lookup on interfaces while
ToolServicedeliberately supports it viagetAnnotatedMethod. I’ll inspect that helper and existing specification test conventions. Then I’ll implement inheritance with Java’s actual method-override rules: subclass declarations must suppress same-signature superclass declarations (including when the override drops@Tool), while inherited non-overridden tools remain discoverable. This avoids accidentally exposing a superclass tool that a concrete class intentionally overrides without annotation. - Assistant
A hierarchy walk is preferable to
Class.getMethods(): existing LC4J supports non-public tool methods and makes them accessible at invocation time, whereasgetMethods()would only add public inheritance. I’ll check project history/dependencies for an established reflection utility, then centralize hierarchy method resolution in core so both discovery APIs and the executor use identical behavior without adding a dependency. - Assistant
No existing hierarchy utility or production caller of the request-based executor constructor was found. I’ll add an internal
getMethods(Class<?>)resolver in core. It will walk concrete class to ancestors, retain the most-derived declaration for each Java signature, and exclude superclass private methods because Java does not inherit them. Package-private methods will only be inherited when declaring and concrete classes share a package; protected/public methods are retained. Synthetic/bridge declarations need careful handling, so I’ll inspect compiler-level conventions and then patch the three discovery points. - Assistant
I’ll now implement the shared resolver and wire it into:
- core tool specification discovery,
- AI-service tool discovery/execution registration, and
- the legacy executor’s name-based lookup.
The resolver will preserve existing support for private methods declared directly on the concrete class, but only include genuinely inherited superclass methods. It will suppress overridden parent signatures and compiler bridge methods, preventing duplicate tool registrations in generic hierarchies.
- Assistant
The environment lacks Python and has no
HOME, so the scripted edit did not run and no source was changed. I’ll apply the same patch with the repository editor-compatibleapply_patch, then compile with an explicit temporary Maven home. - Assistant
apply_patchis also unavailable; compilation therefore only confirmed the untouched baseline. I’ll use Perl literal replacements (available in this shell), verify every replacement count through the resulting diff, and then compile again. - Assistant
Compilation succeeds, but diff review caught two issues before testing: Perl interpreted Javadoc
@tags, and bridge methods must reserve their erased signature even when excluded; otherwise an overridden generic parent can leak back in. I’ll correct both. I’ll also tighten package-private inheritance across multi-package ancestry (every link must remain in the declaring package), then run formatting/compilation and a temporary executable reproduction covering discovery and invocation. - Assistant
The formatting goal is not configured at the reactor root, so that command stopped before compilation; source inspection shows the corrections are present. I’ll locate the project’s actual formatting/check plugin, compile normally, and create a temporary Java reproduction outside the repository. The reproduction will assert inherited public/protected/package tools are specified and executable, private parent methods are not inherited, and unannotated overrides suppress parent tools.
- Assistant
Compilation exposed one missing import from the new resolver (
HashSet); I’ll add it, compile, and use Maven’s generated dependency classpath for the external reproduction. - Assistant
The external reproduction now passes: the bug was reproduced conceptually by the old declared-only scan and is resolved for both specification and service discovery, including successful execution of the inherited method. It also confirms override suppression and visibility edge cases. I’ll run the focused core and service tool test suites next, followed by formatting checks under the repository’s
spotlessprofile. - Assistant
The core focused tests passed. The service test command then used the previously installed core artifact because it selected
langchain4jwithout reactor dependencies, causingNoSuchMethodError; this is a test invocation/classpath issue, not a source failure (the external reproduction used current reactor classes successfully). I’ll rerun service tests with-amand allow upstream modules with no matching specified tests, ensuring the modified core is on the test classpath. - Assistant
The corrected service test suite passed; only the chained formatting invocation failed because the profile config binds Spotless by full coordinates rather than exposing its prefix at the root. I’ll inspect the profile and invoke the configured plugin by full GAV. I’ll also review the final diff and run the broader complete test suites for both affected modules if formatting is clean.
- Assistant
The full-GAV command was incorrectly applied to an internal reactor module that does not inherit Spotless, while the changed files’ modules do. I’ll run the plugin from each affected module POM directly (where parent plugin management is available), then execute complete tests for
langchain4j-coreandlangchain4jwith reactor dependencies. - Assistant
Spotless now resolves correctly but cannot find its configured
origin/mainratchet reference because this uploaded repository has no remote refs. I’ll create a localorigin/mainreference at the unchanged baseline commit (repository metadata only, not a submitted source change), rerun both formatting checks, and then run the complete module tests that were skipped by the failed&&chain. - Assistant
Spotless found one new long line plus pre-existing formatting drift in
ToolSpecifications.javathat becomes in-scope because the file is now modified. I’ll apply the project formatter to the two affected modules (ratcheted to changed files only), verify the resulting diff contains only formatting plus the intended fix, then run all tests. - Assistant
All complete tests for the affected reactor (
langchain4j-core,langchain4j, and required internal modules) passed; noisy listener/server logs were expected test output, and Maven exited successfully. Formatting checks also pass. I’ll perform one final diff/status review, rerun the standalone inheritance reproduction against the post-format build, and inspect test report summaries before submission. - Assistant
Final review revealed one subtle generic/covariant edge case: JVM reflection does not guarantee whether a synthetic bridge or its real method appears first. The current single-pass resolver could therefore let a bridge suppress the real annotated method. I’ll make traversal deterministic by processing non-bridge declarations first, then reserving bridge signatures solely to suppress erased parent declarations. This keeps generic inherited tools correct regardless of reflection order. I’ll then rerun formatting, focused tests, and the reproduction.
- Assistant
The deterministic bridge handling passes focused tests and the inheritance reproduction. One last temporary generic-hierarchy check will ensure an overriding generic tool yields exactly one specification (not a bridge/parent duplicate). I’ll also capture final status and ensure no repository tests or generated files were changed.
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 →