Untitled conversation
- User
[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.
- Assistant
Now let me check existing tests to understand expectations:
- Assistant
Now update the three call sites. First
ToolSpecifications: - Assistant
Now
ToolService: - Assistant
Add a
getAllDeclaredMethodstest toUtilsTest: - Assistant
Now build and run the tests:
- Assistant
The tests pass, but the core
installstep showed an error — let me check what failed: - Assistant
While that runs, let me verify there are no other
@Toolscanning sites in other modules: - Assistant
The background test run will notify on completion — waiting for it.
- Assistant
Tests are still running (Maven output goes to
/tmp/full-test.log; the final summary will appear when the run exits). I'll summarize results once the notification arrives.Changes made so far:
-
langchain4j-core/.../internal/Utils.java— addedgetAllDeclaredMethods(Class<?>): walks the class hierarchy (superclasses, excludingObject) plus implemented interfaces (for default methods), skips synthetic/bridge methods, and de-duplicates overridden methods keeping the most specific declaration. -
langchain4j-core/.../agent/tool/ToolSpecifications.java:63—toolSpecificationsFrom(Class)now usesgetAllDeclaredMethodsinstead ofgetDeclaredMethods(), so inherited@Toolmethods produce specifications. -
langchain4j/.../service/tool/ToolService.java:229—findTools(Object)(the path used byAiServices.tools(...)) now scans inherited methods too. -
langchain4j/.../service/tool/DefaultToolExecutor.java:71— (tool-name → method resolution) now searches the whole hierarchy.
-
- Assistant
Confirmed — the single failing test downloads from
raw.githubusercontent.comand this sandbox has no network access; it's unrelated to the fix.Summary
Fixed
@Toolmethods not being inherited from superclasses (and interfaces) by replacing single-classgetDeclaredMethods()scans with hierarchy-aware discovery.Changes
New helper —
Utils.getAllDeclaredMethods(Class<?>)(langchain4j-core/src/main/java/dev/langchain4j/internal/Utils.java:525)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.