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
The issue is about
@Toolmethods not being inherited from superclasses. This is a LangChain4j (LC4J) repository. Let me explore the repository structure first to understand the codebase and find where@Toolannotation processing happens.Let me start by exploring the repository structure.
Assistant
Let me find the
@Toolannotation definition and the code that collects tool methodsAssistant
The
@Toolannotation is atlangchain4j-core/src/main/java/dev/langchain4j/agent/tool/Tool.java. Let me read it.Assistant
Now let me find where tool methods are collected. Let's look at the
ToolServiceclassAssistant
Now I can see the issue! The
findToolsmethod usesgetDeclaredMethods()which only returns methods declared directly in the class, not inherited ones. Let me check the `getAnnotatedMethodAssistant
Let me look at the
getAnnotatedMethodin Utils.javaAssistant
Let me look at the existing tests for tool inheritance:
Assistant
Let me look at the test for ToolExecutor and check for any existing test that might test inherited tools
Assistant
Now let me create a small reproduction script to confirm the bug
Assistant
Let me check the build system and try to compile/run the test
Assistant
It's a Maven project. Let me check the structure to find the right module for testing.
Assistant
Let me look at some of the relevant integration tests to understand how tools are tested
Assistant
Let me now look at the
findToolsmethod more carefully and write a minimal test within the project to reproduce the bugAssistant
Let me create a simple test to confirm the bug
Assistant
Let me try to compile and run this test using maven
Assistant
There's a
ToolServiceTest, let me lookAssistant
Let me look at it.
Assistant
Let me use the open command correctly.
Assistant
Now I understand the issue clearly. Let me look at the
findToolsmethod more closely and fix it.Assistant
Now I'll implement the fix. The issue is that
getDeclaredMethods()only returns methods declared directly in the class. I need to walk up the class hierarchy.Assistant
Let me also check the remaining imports to see if HashSet, Arrays, Set are already imported.
Assistant
Let me open the file and fix it. First, let me add the necessary
Assistant
Let me scroll to the
findToolsmethod.Assistant
Let me use the open command with line number.
Assistant
Now I can see the code. Let me add the imports first.
Assistant
Now let me add the
java.util.Arraysimport and then modify thefindToolsmethod. Let me check the current line numbers after the edit:Assistant
Now let me add the
java.util.Arraysimport and then modify thefindToolsmethod:Assistant
Now let me find the exact lines of the
findToolsmethod after the import changesAssistant
Let me see lines 218-248
Assistant
Now let me modify the
findToolsmethod to walk up the class hierarchyAssistant
I see there's an extra
}on line 250. Let me removeAssistant
The code looks correct now. Let me compile the module to verify
Assistant
The
LinkedHashMapimport was removed. Let me fix itAssistant
I need to add
LinkedHashMapimport back. Let me fix itAssistant
Now let me compile again
Assistant
Compilation successful. Now let me create a quick test to verify the fix
Assistant
Let me place this test in the test directory and run it
Assistant
The test needs to be a JUnit test. Let me convert it
Assistant
Now let me run the
Assistant
The test passes. Now let me run the existing tests to make sure nothing is broken
Assistant
Let me also check if there are other places in the codebase with similar issues
Assistant
There are several other places. Let me check each one
Assistant
Let me check
ToolSpecifications.javaAssistant
Let me also check
AgenticServices.javaAssistant
Now let me fix the other occurrences. Let me start with
DefaultToolExecutor.findMethodAssistant
Let me fix the
findMethodinDefaultToolExecutorAssistant
Now let me fix `ToolSpecifications.java
Assistant
Let me fix
ToolSpecifications.toolSpecificationsFrom(Class<?>)Assistant
Now let me fix
AgenticServices.javaAssistant
Let me find the exact section that needs
Assistant
Let me look at the method around line 741
Assistant
Let me fix
AgenticServices.nonAiAgentMethodtooAssistant
Now let me compile all modules to verify everything compiles correctly
Assistant
Everything compiles. Let me now run the core tests for the tool-related classes
Assistant
Let me run tests separately by
Assistant
Core tests pass. Let me run the langchain4j tests and agentic tests
Assistant
Let me also run the agentic module tests
Assistant
All tests pass. Let me clean up the test file I added since I shouldn't add new tests
Assistant
Now let me verify the overall changes with git diff
Assistant
Let me see the full diff
Assistant
Let me also double-check that the
ToolSpecifications.javafile doesn't have unused imports now (it previously usedstreambut now doesnAssistant
Let me run all the tests for the affected modules one more time
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →