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 inspect the repository structure and search for
@Tooldiscovery/reflection code and relevant tests. Then I’ll reproduce the inheritance gap with the project’s existing test conventions, patch the production implementation, and run the focused and broader affected tests. - Assistant
The search shows two primary discovery paths that only inspect declared methods: runtime tool registration in
ToolServiceand standalone specification extraction inToolSpecifications. I’ll inspect both implementations and their tests, including any existing interface/default-method annotation handling, so the fix preserves override semantics and supports the intended inheritance cases consistently. - Assistant
ToolServicealready callsgetAnnotatedMethod, suggesting annotations on overridden interface/super methods are intentionally resolved—but it never sees inherited methods becausegetDeclaredMethods()excludes them.ToolSpecificationsis even narrower. I’ll inspect the shared reflection helper and focused tests to determine whether usinggetMethods()directly is sufficient or whether package-private/protected inherited tools must also be traversed. - Assistant
The annotation itself is not
@Inherited(and Java does not support annotation inheritance for methods automatically), so discovery must resolve the defining method. I’ll now readUtils.getAnnotatedMethodin full and check module dependencies: ideally one shared hierarchy-aware utility should serve both core specification generation and service execution, avoiding divergent behavior. - Assistant
A simple
getMethods()change would silently drop non-public methods that currently work and would not include inherited protected/package-private methods. I’ll design hierarchy traversal that starts at the concrete class, walks superclasses, and includes interfaces, while de-duplicating by Java method signature so an override wins. For an unannotated override, I need determine expected semantics: existing proxy handling treats the inherited/interface annotation as authoritative, so hierarchy resolution should likely preserve that behavior. I’ll inspect invocation accessibility and related proxy tests before implementing. - Assistant
Invocation explicitly makes methods accessible, so inherited protected/package-visible methods can be supported. I’ll add a shared
getAnnotatedMethodsutility with subclass-first signature de-duplication, recursive superclass/interface traversal, and exclusion of private ancestor/interface-static methods because those are not inherited in Java. Root-class private tools remain supported for backward compatibility. Then both discovery paths will consume it;ToolServicecan retaingetAnnotatedMethodonly as an internal detail if needed elsewhere. - Assistant
I’ve settled the key semantics: de-duplication uses method name plus parameter types (matching Java override signatures and handling covariant returns), annotated contracts remain tools even when implemented/overridden without repeating
@Tool, and the nearest annotated declaration wins when multiple hierarchy levels annotate the same signature. I’ll implement this shared behavior now. - Assistant
The environment lacks
python3, so the scripted edit did not run; Maven also requiresHOMEto be set. No repository files were changed by that command. I’ll apply the same targeted edits using the providededit/replaceutilities, then compile withHOME=/root. - Assistant
The replacement utility interpreted
\\nliterally in two imports and constrained multiline searches to the editor window, so only part of the edits applied. I’ll repair the malformed imports and use line-orientededitoperations at the exact locations for the larger changes. - Assistant
I now have exact line locations. I’ll use
editto avoid escape handling, then inspect the resulting source before compiling. - Assistant
One malformed import shifted after the first line edit, causing
Collectionto be replaced rather than the intended malformed line. I’ll correct that import block, updateToolServiceby exact current lines, and then rely on Spotless to normalize import ordering. - Assistant
The
ToolServiceblock replacement consumed theif (result.isEmpty())line because removing the import shifted its line number. The inspection caught this before compilation. I’ll restore the complete empty-result guard, then format and compile. - Assistant
The source now parses structurally; only the optional Spotless invocation failed because this checkout does not expose that Maven plugin by prefix, so compilation did not run in that combined command. I’ll compile directly, then create a temporary (outside-repository) Java harness against the built classes to verify both specification discovery and executable tool discovery for superclass and interface inheritance.
- Assistant
Compilation found that
Optionalis also used by parameter-default validation earlier inToolService; removing its import was incorrect. I’ll restore it and rerun compilation plus the external inheritance harness. - Assistant
Compilation now passes. The external harness compiled but runtime lacked transitive dependencies (first missing class: SLF4J), so the application-level check did not yet run. I’ll ask Maven to generate the module’s runtime classpath, rerun the harness, and then run the focused existing unit suites for
Utils,ToolSpecifications, andToolService. - Assistant
The external reproduction now passes for both superclass and interface inheritance, and all focused existing tests pass. Before finalizing, I’ll review the complete diff and API compatibility. In particular, I’ll avoid accidentally changing
toolSpecificationsFromfrom a mutable list to Java’s unmodifiableStream.toList()result, since inheritance support should not introduce unrelated behavior changes. I’ll also inspect whether the harness can execute the discovered inherited method, not merely discover it. - Assistant
The diff confirms one unrelated mutability regression from
.toList(). I’ll restoreCollectors.toList()behavior. I’ll also extend the temporary harness to invoke both discovered executors, ensuring reflection dispatch works for protected superclass methods and interface declarations. - Assistant
The mutability behavior is restored. I’ll now run the executor check and then test the full two affected modules (not just focused classes), which will also surface formatting/checkstyle enforcement if configured.
- Assistant
The reproduction now verifies actual execution and passes. The complete
langchain4j-coreandlangchain4jtest suites also pass; the long warnings are expected outputs from tests that deliberately exercise failing listeners and server shutdown paths, and Maven exited successfully.I’ll perform a final style/diff review, check for the repository’s configured formatter (the earlier
spotlessguess was wrong), and inspect generated/untracked files before submission. - Assistant
The project configures Spotless only under the
spotlessprofile, explaining the earlier prefix failure. The import block visibly needs normalization, so I’ll run the configured formatter through that profile and confirm it changes only our three files, then rerun the focused tests if formatting alters source. - Assistant
Even with the profile, Maven cannot resolve the plugin by prefix in this environment. I’ll inspect the exact configured coordinates/version and invoke the plugin by full coordinates, which bypasses prefix resolution.
- Assistant
The configured version is
2.44.4; I’ll invokecom.diffplug.spotless:spotless-maven-plugin:2.44.4:applyexplicitly under the profile. - Assistant
The full-coordinate invocation resolved correctly but failed on an upstream
-amhelper module where Spotless is intentionally absent. I’ll invoke it only on the two changed modules (their dependencies are already built), then inspect modifications. - Assistant
Spotless itself is blocked because this shallow/offline checkout has no
origin/main, the configured ratchet reference. I’ll manually fix the only visible formatting issue introduced by our edit (missing separator after static imports), then run Spotless’scheckwith the ratchet overridden toHEADif the plugin supports the standard property; otherwise compilation/tests already validate source correctness. - Assistant
Spotless’s ratchet setting cannot be overridden from the CLI and remains unavailable without
origin/main; the import formatting is now manually correct. I noticed the helper’s “closest declaration” wording is stronger than the deterministic traversal guarantee in rare mixed superclass/interface diamonds, so I’ll make the documentation precise: duplicate signatures are returned once, with class declarations prioritized over interface declarations. Then I’ll run one final focused verification and inspect the final diff. - Assistant
The final focused tests pass. The documentation replacement was not applied because the editor window did not include that location, so I’ll make that small exact-line edit, inspect the final diff, and then complete the requested checklist before submission.
- Assistant
I’ll update those exact lines and review the complete patch for accidental changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.