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/reflection code, then identify the relevant module and tests before reproducing the superclass omission. I’ll also check whether this repository includes both the reported integration and core LC4J paths. - Assistant
The primary failure is visible in
ToolService: it scans onlyobjectWithTools.getClass().getDeclaredMethods(), which excludes superclass declarations.DefaultToolExecutorhas another declared-method scan related to proxy annotation resolution, and coreToolSpecificationsmay be the “LC4J too” path. I’ll inspect these implementations and their focused test suites to design one consistent hierarchy-aware behavior, including overrides and interfaces. - Assistant
I found two public discovery APIs: service object discovery and core class/object specification discovery. I’ll inspect core’s exact semantics plus
Utils.getAnnotatedMethod, because blindly switching togetMethods()would lose non-public inherited methods and could mishandle annotations on overridden/interface methods. Existing tests will indicate intended support for proxies and visibility. - Assistant
Core currently filters only directly annotated declared methods, while the service uses
getAnnotatedMethodto recover annotations from proxy/interface declarations—but only after obtaining methods from the concrete class. I’ll inspect that resolver and metadata-provider abstraction now. The likely clean fix is a shared hierarchy method collector in core so both APIs agree, with signature de-duplication ensuring an override is represented once and preserving subclass precedence. - Assistant
The resolver only handles JDK proxies, so it does not itself solve ordinary inheritance. I’ll add an internal hierarchy collector that:
- walks from concrete class toward
Object, - includes superclass declarations (including non-public methods that reflection can invoke),
- de-duplicates by Java signature with the most-derived declaration winning,
- includes interface methods (important for default/inherited tool methods),
- prevents an unannotated override from accidentally exposing an overridden superclass annotation.
Then I’ll use it in both core specification generation and service tool discovery, while retaining proxy annotation resolution. I’ll also update the legacy executor constructor’s name lookup so an inherited tool request can be executed through that API.
- walks from concrete class toward
- Assistant
The legacy request-based executor is not used by current
ToolService, but leaving it declaration-only would make inherited tools inconsistently executable for users of that public constructor, so it belongs in the fix. I’ll implement the collector inUtilsusing a small signature key (not tool-name de-duplication, since overloaded methods must still reach existing validation), then patch all three call sites. - Assistant
The repository targets Java 17, so a record key is compatible. The environment lacks Python, so that scripted edit did not run and no files changed. I’ll apply the same focused edits with the provided editor commands instead.
- Assistant
Only replacements within the editor’s displayed window succeeded; the helper insertion and imports did not, leaving an intermediate uncompilable state. I’ll finish those edits using Perl (available as a standard shell tool), then inspect the complete diff before compiling. I’ll also let Spotless determine import ordering.
- Assistant
The diff reveals Perl interpreted
@param/@returnin the replacement, so I’ll repair that Javadoc. The hierarchy semantics look sound for the report: a non-overridden superclass method remains discoverable and invokable; a subclass override suppresses the superclass declaration; default interface methods are included. I’ll now run formatting and focused tests for core tool specifications and service tooling, which will also catch module/API compatibility. - Assistant
Two environment issues interrupted before tests: the Perl delimiter conflicted with
@andHOMEis unset for Maven Wrapper. I’ll use the line editor for the two Javadoc lines, then rerun withHOME=/root. - Assistant
The editor window showed shifted numbering, and my edit accidentally retained one malformed line while removing the Javadoc terminator. I’ll replace the whole affected block precisely. This project does not configure a
spotlessprefix, so after repair I’ll run the focused tests directly and inspect the parent POM for the configured formatter/check plugin rather than guessing. - Assistant
Core tests passed (18/18). The service module then compiled against the previously published snapshot of core because it was invoked standalone, so it correctly reported that the new API was absent from that old artifact. I’ll install the locally changed core first, run service tests again, and invoke the repository’s Spotless profile explicitly (
-Pspotless). Then I’ll run a temporary standalone reproduction against the built artifacts to verify both discovery and execution of an inherited tool without modifying tests. - Assistant
The local install reached packaging but failed only at the repository-wide JaCoCo threshold because tests were intentionally skipped; therefore it did not publish the artifact and subsequent commands did not run. I’ll avoid installation by run the two modules in one reactor (
-am) and tell Surefire not to fail when the selected service test names do not exist in upstream modules. I’ll also run Spotless as a fully qualified profile goal afterward. - Assistant
The reactor run succeeded: all nine required modules compiled, and the 20 focused service tests passed. Spotless itself is blocked by the checkout lacking its configured
origin/mainratchet reference, not by source formatting;git diff --checkremains clean and I’ll manually inspect formatting.For explicit reproduction, I’ll compile a temporary
/tmpclass that demonstrates the old mechanism sees zero declared methods on the child, while both fixed APIs discover the inherited@Tool, and the resulting service executor successfully invokes it. I’ll generate the module runtime classpath and remove all temporary files afterward. - Assistant
The standalone check passed: the child has zero declared methods (the original failure condition), core and service discovery both find
greet, and service execution returnshello world. Temporary files were removed.One subtle hierarchy edge case remains in the collector: Java class methods take precedence over interface defaults regardless of traversal level. I’ll adjust collection to gather the entire class chain before interfaces, preserving subclass-to-superclass precedence within each category. I’ll also correct manual import ordering, then rerun compilation/focused tests after this final semantic refinement.
- Assistant
The final reactor build passed again. Core’s dedicated
ToolSpecificationsTesthad already passed separately (18 tests), while the final reactor selected and passed the 20 service tests; all changed production sources compiled together.The semantic refinement is in place. Only the import-order edit failed due the editor window restriction, so I’ll correct those three lines directly, perform final diff/status checks, verify no temporary files or test changes are present, and then submit with the requested checklist assessment.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.