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.
Interface
No new interfaces are introduced.
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
Now let's add a utility method
getAllMethodsright aftergetAnnotatedMethod.Assistant
No python, but perl is available. I'll use the
open/replacespecial commands instead.Assistant
Need a blank line before line 580's
/**.Assistant
Now let's clean up the fully-qualified names to use proper imports.
Assistant
SetandArrayListalready imported. Needjava.util.Arraysandjava.util.HashSetimport, then remove fully qualified usage.Assistant
Let's fix ordering (HashSet should be before HexFormat alphabetically... actually alphabetical: HashMap, HashSet, HexFormat). Let's fix the order.
Assistant
Now update the method to use unqualified Arrays and HashSet.
Assistant
Now let's compile core module to check for errors.
Assistant
Maven project. Let's now update the three usages to use
Utils.getAllMethods.Assistant
Now change the stream usage:
Assistant
Remove now-unused
import static java.util.Arrays.stream;.Assistant
Good, that's fine. Now let's update ToolService.java and DefaultToolExecutor.java.
Assistant
Now let's fix line 229 in ToolService.java to use getAllMethods.
Assistant
Fix ordering alphabetically (getAllMethods before getAnnotatedMethod).
Assistant
Now update line ~229 usage.
Assistant
Good,
tools(Collection<Object>)usesfindToolswhich we fixed. Now fixDefaultToolExecutor.findMethod.Assistant
Good, those are the two files we already fixed (plus DefaultToolExecutor for method invocation lookup). Now let's compile the affected modules.
Assistant
Compiles fine. Now let's write a quick reproduction test.
Assistant
Good, already compiled. Let's build a classpath for langchain4j module dependencies and run our reproduce script.
Assistant
Both inherited and own tool methods are now found. Now let's test tool execution (DefaultToolExecutor) also works for inherited method.
Assistant
Now let's check that method override deduplication works correctly (i.e., overridden methods aren't duplicated, and the most derived version is used).
Assistant
Excellent, override deduplication works correctly, using the most-derived version's annotation. Now let's run the existing test suites for these modules to make sure nothing broke.
Assistant
Test ran without errors (no failures shown). Let's confirm with more verbose output.
Assistant
All 18 tests pass. Now let's run the langchain4j module tests for ToolService and DefaultToolExecutor.
Assistant
Installed successfully. Now let's run tests in langchain4j module for ToolService and DefaultToolExecutor.
Assistant
All existing tests pass. Let's also run broader tool-related tests in the langchain4j module (AiServices tests referencing tools) to double check.
Assistant
Most are IT (integration tests needing real APIs). Let's run the non-IT unit tests specifically.
Assistant
All good — no failures. Let's view the summary counts.
Assistant
All tests pass (skipped IT tests are expected, no network). Now let's also run the core test suite fully to make sure nothing else broke.
Assistant
All 133 test files in core have 0 failures/errors. Now let's view the full diff of the changes.
Assistant
This diff looks clean and minimal. Let's clean up temp files/scripts.
Assistant
Multi-level inheritance works correctly too. Let's clean up any leftover temp directories.
Assistant
Now let's go through the checklist:
Assistant
Checklist review:
- Reproduced the reported error: Yes — wrote a reproduction script demonstrating that
@Tool-annotated methods in a superclass were not discovered byToolSpecifications.toolSpecificationsFrom,ToolService.findTools, andDefaultToolExecutor.findMethod(all of which usedgetDeclaredMethods(), which only returns methods declared directly in the class, not inherited ones). - Confirmed the fix resolves the error: Yes — after adding
Utils.getAllMethods(Class<?>)(which walks up the class hierarchy collecting declared methods from each class, excludingObject) and using it in all three places, the reproduction scripts show inherited methods are now discovered, correctly listed in tool specifications, and successfully invoked via .
- Reproduced the reported error: Yes — wrote a reproduction script demonstrating that
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.