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
I'll start by exploring the repository structure to understand the codebase and find where
@Toolmethods are processed.Assistant
Let me look at where
@Toolannotation is defined and where methods are processed.Assistant
Found the issue.
getDeclaredMethods()only returns methods declared in that class, not inherited ones. Let me also check how tools are invoked.Assistant
Let me look at the
ToolService.javatoo to understand the full picture.Assistant
Let me look at the
getAnnotatedMethodhelper.Assistant
Let me look at the AgenticServices.java usage too.
Assistant
Now let me write a reproduction test to confirm the issue. Let me first check the test structure.
Assistant
Let me write a reproduction test to confirm the bug.
Assistant
Let me build the full classpath using maven.
Assistant
The bug is confirmed -
inheritedToolfrom the superclass is not found. Now let me fix the issue. First, let me look at the full structure to understand all places that need fixing.Assistant
Now let me look at the
Toolannotation to see if it's@Inherited.Assistant
Now let me check where
DefaultToolExecutor(Object, ToolExecutionRequest)is used.Assistant
Let me check who calls
DefaultToolExecutor(Object, ToolExecutionRequest).Assistant
So the
DefaultToolExecutor(Object, ToolExecutionRequest)andDefaultToolExecutor(Object, Method)constructors may be public API. ThefindMethodis used in theToolExecutionRequestconstructor. Let me check who actually uses these public constructors in tests or other modules.Assistant
Let me look at the tests using the request-based constructor to understand expectations.
Assistant
Now I have a clear understanding. Let me implement the fixes. First,
ToolSpecifications.java:Assistant
Now let me edit the
ToolSpecifications.javato walk the class hierarchy:Assistant
No python3. Let me use the edit command. Let me open the file first.
Assistant
The first edit looks good. Now let me fix
DefaultToolExecutor.findMethod:Assistant
Let me verify imports in
DefaultToolExecutor.java:Assistant
Methodis imported. Now let me fixToolService.findTools:Assistant
Let me check imports in
ToolService.java:Assistant
Setis imported butHashSetis not. Let me add theHashSetimport:Assistant
Now let me search more broadly for other places that scan
@Toolmethods viagetDeclaredMethods.Assistant
Now let me check the deprecated
toolsmethod inToolServiceand other places that build tool specifications:Assistant
Let me check if there are other tool-scanning code paths in the main langchain4j module:
Assistant
Let me check the deprecated tool scanning methods in the codebase:
Assistant
Now let me rebuild the core module to verify the changes compile:
Assistant
Now let me build the langchain4j module which depends on core:
Assistant
Both modules built successfully. Now let me write a comprehensive reproduction test using the installed jars:
Assistant
Let me find the
AiServiceToolclass:Assistant
The fix works for finding tools. The argument
nullis a separate parameter-name issue. Let me check whether the project compiles with-parameters:Assistant
No
-parametersflag, so parameter names are synthetic (arg0). Let me update the reproduction to use the correct key:Assistant
Let me debug the parameter name issue:
Assistant
Let me debug by printing the actual parameter name:
Assistant
Let me verify the langchain4j jar was actually updated with my changes:
Assistant
Let me write a focused debug test to print the parameter names from the found method:
Assistant
It works here! Let me re-run ReproTest2 to check:
Assistant
Let me recompile ReproTest2 (maybe stale class) and rerun:
Assistant
Let me add debug printing to ReproTest2:
Assistant
Let me verify the actual arguments string in ReproTest2:
Assistant
The sed didn't apply due to escaping. The argument key is
argbut the parameter name isarg0. That's a test error, not a fix error. Let me fix the arguments:Assistant
All edge cases work correctly now. Let me run the existing tests to make sure nothing breaks. First the core tests:
Assistant
Offline mode is missing surefire. Let me try online:
Assistant
The core tests pass. Now let me run the langchain4j module tool tests:
Assistant
Let me find and run tests related to
findToolsand tool inheritance:Assistant
Let me run the broader tool-related tests in the langchain4j module:
Assistant
All tests pass. Let me check the agentic module for any
@Toolscanning that I might have missed:Assistant
Let me check
AgentUtil.javalines 139 and 313 to see if they're about@Tool:Assistant
These are about
@Agent, not@Tool. They usegetMethods()which already returns inherited methods. So no change needed there.Now, the agentic module uses
@Toolindirectly throughToolSpecifications? Let me check how agentic handles@Tooltools. Let me look atAgentUtil.java:313.Assistant
Let me verify how agentic handles
@Tool-annotated tools, by searching forToolSpecificationsandfindToolsusage:Assistant
Let me search the entire repository for any other
@Toolscanning viagetDeclaredMethodsin main code:Assistant
Let me verify the
AgenticServices.java:741is for@Agent, not@Tool:Assistant
The remaining one is for
@Agent, not@Tool- out of scope. Now let me clean up my temp files and verify the final diff:Assistant
Let me verify the
streamimport is still used elsewhere inToolSpecifications.java(since I removed its only usage):Assistant
The
import static java.util.Arrays.stream;is now unused. Let me remove it to avoid a potential lint failure:Assistant
The edit created a duplicate import. Let me fix that:
Assistant
Now let me rebuild both modules to confirm everything still compiles:
Assistant
The error is a jacoco coverage check (not compilation). Let me skip jacoco:
Assistant
Let me check when the jacoco check runs (phase) to understand if normal test runs are affected:
Assistant
Let me find where the jacoco
checkgoal is configured:Assistant
The jacoco check runs in
verifyphase. The coverage check counts thedev.langchain4j.agent.toolpackage. My newtoolMethodsFrommethod adds uncovered branches.The check happened during
install(which runs up toverify). But duringtestphase, the jacoco check doesn't run. So when the evaluation runsmvn testor specific tests, it won't fail on coverage.But to be safe, the coverage gate might be a concern. Let me check the coverage rule threshold. Actually, let me see the rule configuration.
Assistant
The jacoco failure was because I used
-DskipTests(no test coverage data generated → 0% coverage). Let me run with tests to get realistic coverage. Let me run the full core test suite:Assistant
There's a test error in the full suite. Let me see which test failed:
Assistant
All tests pass (the stack trace was likely a logged error from a test that catches it). Let me check the final build status more carefully:
Assistant
Now let me run WITHOUT skipping jacoco to see if the coverage gate passes with tests running:
Assistant
The coverage gate passes with the full test suite. Now let me verify the langchain4j module's verify phase:
Assistant
The langchain4j module doesn't have a jacoco check. Let me do a final review of the complete diff and run a final comprehensive test:
Assistant
The diff looks clean. Let me run a final comprehensive test of the relevant tests in both modules:
Assistant
All tests pass. Let me run the core
ToolSpecificationsTestonce more after the import cleanup to be certain:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.