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 for any other places scanning
@Toolmethods: - Assistant
Now update the three scanning sites. First
ToolSpecifications: - Assistant
Now
ToolService.findTools: - Assistant
Now let's check that invoking inherited (possibly non-public) methods works — check how
DefaultToolExecutorinvokes: - Assistant
Invocation already handles accessibility. Now add tests. Let me look at existing tests:
- Assistant
Now add tests. First to
ToolSpecificationsTest: - Assistant
Now add a test for
getAllDeclaredMethodsinUtilsTest: - Assistant
Now add a
findToolsinheritance test toToolServiceTest: - Assistant
Now build and run the tests. First core module:
- Assistant
Core tests pass. Now install core locally and run the
langchain4jmodule tests: - Assistant
Now run the broader set of tool-related tests to check for regressions:
- Assistant
All Tool-related tests pass (my awk summary was just malformed — every report shows
Failures: 0, Errors: 0). Let me run the full test suites of both affected modules to be thorough: - Assistant
The single failure is
UrlDocumentLoaderTest.should_load_text_document— a network timeout fetching an external URL, unrelated to this change (this sandbox has restricted internet access). All other 1384 tests in thelangchain4jmodule and all 1090 inlangchain4j-corepass.Summary
@Toolmethods declared in a superclass were invisible because tool scanning usedClass.getDeclaredMethods(), which only returns methods declared directly on the concrete class.Fix — added
Utils.getAllDeclaredMethods(Class<?>)inlangchain4j-core(Utils.java:555), which walks the class hierarchy up to (excluding)Object, collects declared methods including non-public ones, dedupes overridden methods by signature keeping the most specific declaration, and skips synthetic/bridge methods. Then switched all three tool-scanning sites to it:ToolSpecifications.toolSpecificationsFrom(Class)—langchain4j-core/.../agent/tool/ToolSpecifications.java:64ToolService.findTools(Object)—langchain4j/.../service/tool/ToolService.java:230(the path used by AI Services'.tools(...))DefaultToolExecutor.findMethod(...)—langchain4j/.../service/tool/DefaultToolExecutor.java:72(so execution also resolves inherited methods)
Invocation of inherited non-public methods already works via the existing
setAccessible(true)fallback inDefaultToolExecutor.Tests added:
UtilsTest—getAllDeclaredMethodsincludes inherited/protected methods, returns overridden methods once using the subclass declarationToolSpecificationsTest— specs include inherited, overridden, and declared@ToolmethodsToolServiceTest—findToolsdiscovers inherited tools and executes them correctly (overridden tool dispatches to the subclass implementation)
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
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →