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
I'll investigate how
@Toolmethods are discovered and whether superclass methods are included in that scan. - Assistant
Found the issue: tool discovery uses
getDeclaredMethods(), which skips inherited methods. Reading the relevant files to fix it. - Assistant
Implementing a hierarchy walk for tool discovery:
getDeclaredMethods()only returns methods declared on the class itself, not inherited ones. - Assistant
Adding tests for inherited
@Toolmethods: - Assistant
The test failed due to JaCoCo's synthetic
$jacocoInitmethod. Updating the assertion to be less strict. - Assistant
Fixed.
@Toolmethods declared on a superclass were missed because tool discovery usedgetDeclaredMethods(), which only returns methods declared on the concrete class — not inherited ones.Root cause
Three places scanned only the concrete class:
ToolSpecifications.toolSpecificationsFrom()— builds tool specs for the LLMToolService.findTools()— registers tools with AI ServicesDefaultToolExecutor.findMethod()— resolves methods at execution time
Fix
Added
Utils.getAllDeclaredMethods(Class<?>), which walks the class hierarchy (subclass → superclass, stopping beforeObject) and collects declared methods, with subclass overrides taking precedence.Updated all three call sites to use it.
Tests added
ToolSpecificationsTest— inherited tools and overridden toolsToolServiceTest—findTools()picks up superclass@ToolmethodsDefaultToolExecutorTest— inherited tool executionUtilsTest— hierarchy walk utility
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.