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/reflection code and its tests. Then I’ll reproduce superclass omission with the closest existing test suite, implement inheritance-aware discovery while considering overrides and duplicate signatures, and run focused plus broader tests. - Assistant
The initial search confirms three relevant uses of
getDeclaredMethods: specification generation inlangchain4j-core, tool registration inToolService, and a constructor path inDefaultToolExecutor. I’ll inspect these implementations and existing inheritance/annotation utilities to ensure one consistent fix rather than changing only the symptom. - Assistant
ToolServicealready resolves annotations declared on interfaces viagetAnnotatedMethod, but it never sees methods absent from the concrete class because it starts withgetDeclaredMethods.ToolSpecificationsis even narrower. I’ll inspect utility semantics and current tests, especially override cases, before choosing whether public inherited methods (getMethods) are intended or all visibility levels should be traversed. - Assistant
A hierarchy walk is preferable to simply
getMethods(): it preserves existing support for non-public tools while adding inherited ones. The key edge case is overriding: a subclass declaration should shadow the same superclass signature, so an unannotated override should not accidentally inherit@Tool; private/static methods require Java-specific handling. I’ll look at invocation accessibility and module dependency boundaries, then add a reusable method-discovery utility in core so both LC4J specification generation and AI-service registration behave identically. - Assistant
I’ll implement
getMethodsInClassHierarchyin the existing internal reflection utility. It will traverse from the concrete class upward, deduplicate by Java method signature so the most-derived declaration wins, and retain non-public methods. Then I’ll use it in specification discovery, AI-service discovery, and the request-based executor lookup (the latter otherwise remains an inconsistent inherited-method failure path). - Assistant
Python is unavailable in this environment, so no files were changed. I’ll apply the same targeted edits with the repository’s patch tooling, then compile immediately to catch type inference or formatting issues.
- Assistant
Neither
apply_patchnor a presetHOMEis available. I’ll use the provided noninteractiveeditcommand for exact line changes and run Maven withHOME=/root. - Assistant
The editor reports two range-boundary artifacts: a duplicated method declaration (which also dropped validation) and a duplicated Javadoc opener. The import changes succeeded, while the
ToolServiceloop replacement did not. I’ll correct those exact lines, apply the missed loop change, and rerun compilation. - Assistant
Compilation now passes for the core change, but the missed
ToolServiceloop still needs an exact line edit. After that I’ll create a temporary standalone Java reproducer outside the repository (not a test-file modification) to verify: inherited specifications are exposed,ToolService.findToolsregisters them, execution invokes them, and an unannotated override suppresses the inherited annotation. - Assistant
The external reproducer passes end-to-end, including protected superclass discovery/execution and override suppression. One semantic refinement is warranted: private superclass methods are not inherited in Java, so the hierarchy utility should retain private tools only on the concrete class (existing behavior) and exclude private ancestor methods. I’ll add that filter and clarify the Javadoc, then run the focused core/service test suites and formatting checks.
- Assistant
The range replacement left one extra closing brace, and the direct Spotless goal is not configured by prefix in this build. I’ll remove the artifact, restore standard spacing, compile, rerun the reproducer, and execute the two affected module test suites (the normal lifecycle will run configured checks).
- Assistant
The complete
langchain4j-coreandlangchain4jtest suites passed (the long warnings are expected logs from tests and embedded-server shutdown). The external reproducer also still passes after excluding private ancestor methods. I’ll now review the final diff for accidental/generated changes, verify test result files contain no failures, and check formatting conventions before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.