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
Let me start by exploring the repository structure to understand what we're dealing with. This is a LangChain4j repository (Java implementation of LangChain). The issue is about
@Toolmethods not being inherited from superclasses. Let me explore the codebase to understand how tools are currently handled.Let me start by exploring the repo structure and finding relevant files.
Assistant
Let me look at the ToolService and DefaultToolExecutor to understand how tools are processed.
Assistant
Let me look at the key files:
Assistant
Let me try using bash to read the file instead.
Assistant
I found the issue! The
findToolsmethod usesgetDeclaredMethods()which only returns methods declared directly in the class, not inherited ones. Let me also checkToolSpecifications.javaand understand the fullAssistant
Now I can see the problem clearly. Both
ToolService.findTools()andToolSpecifications.toolSpecificationsFrom(Class<?>)usegetDeclaredMethods()which only returns methods declared directly in the class, not inherited ones.Let me check if there are existing tests related to tool inheritance:
Assistant
Let me check how tools are typically registered. Let me also look at the
getAnnotatedMethodutility mentioned in the code, and look at how theAiServiceValidationand other files usegetDeclaredMethodsAssistant
Let me check the
getAnnotatedMethodutility and theUtilsclassAssistant
Let me look at the
getAnnotatedMethodin Utils.java.Assistant
Let me read that part of Utils.java
Assistant
Now let me check the same issue in langchain4j-agentic module:
Assistant
Let me also look at
DeclarativeUtil.javaandAgentUtil.javain langchain4j-agenticAssistant
OK so DeclarativeUtil already uses
getMethods. Let me also check AgentUtil.java and the other file in agentic.Assistant
Let me check the
@Toolannotation definition:Assistant
Let me see the Tool annotation.
Assistant
Let me look at some existing tool definitions in tests to see if they're always public:
Assistant
No results. Let me check if there are any non-public
@Toolmethods:Assistant
Let me check the TestTool classes to see if
@Toolmethods are always public:Assistant
Now I understand the issue better. The methods in tests can be package-private, so we can't just switch to
getMethods(). Instead, we need to traverse the class hierarchy. Let me first create a reproduction script:Assistant
Let me check the build system and create a reproduction script.
Assistant
Let me write a Java test to reproduce the issue
Assistant
This confirms the issue perfectly. Now let me look at the AgenticServices issue as well:
Assistant
Let me go back to the repo root and check again.
Assistant
Now I have a clear understanding. Let me fix the three files. The approach is to traverse the class hierarchy instead of only using
getDeclaredMethods().Let me start with `ToolService.java
Assistant
Let me just use
catwith line numbers to see the exact code and useeditto make changes.Assistant
Let me see the full context around line 229
Assistant
Let me check if package-private tool methods are used in tests:
Assistant
Let me check if
ToolExecutorTestuses `ToolService.findToolsAssistant
Let me check how tools are registered and find all usages of `findTools
Assistant
Now I'll fix the three files. Let me start with `ToolService.java
Assistant
Now let me make the fix. First, let me edit `ToolService.java
Assistant
Let me use
sedto make the edit instead.Assistant
Let me use
pythoninsteadAssistant
Let me check what tools are available
Assistant
Perl is available. Let me use perl for the replacement
Assistant
Let me verify the change was applied correctly
Assistant
Good, ToolService.java is fixed. Now let me fix `ToolSpecifications.java
Assistant
Now let me fix `ToolSpecifications.java
Assistant
Let me verify the change
Assistant
Now I need to check if the
streamimport in ToolSpecifications.java is still usedAssistant
I need to remove the unused imports and add
ArrayListif needed. Let me check all importsAssistant
Good -
ArrayList,List, andMethodare already imported. Let me remove the unused importsAssistant
Let me verify the imports are clean
Assistant
Now let me fix
AgenticServices.java. Let me look at the context around line 741Assistant
Let me fix
AgenticServices.javaasAssistant
Let me verify the AgenticServices change
Assistant
Now let me check for any other places that might have the same issue with
getDeclaredMethodsfor finding tool methodsAssistant
Let me also check other files in the agentic module that might need
Assistant
Now let me run existing tests to verify the changes don't break anything
Assistant
Let me run with more verbose output to see if
Assistant
Let me run tests related to tools in the main langchain4j module
Assistant
All tests pass. Let me also run the broader test suite for the langchain4j module
Assistant
All tests pass! Let me also run the agentic module
Assistant
All tests pass! Let me also run the langchain4j-core tests to make sure everything is fine there
Assistant
All 1088 tests pass. Now let me create a quick test to verify the inheritance fix works:
Assistant
The fix works correctly. Let me verify the full diff of my changes:
Assistant
The diff looks clean. Let me clean up the temporary files
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.