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 in the codebase and whether superclass methods are included in that scan. - Assistant
Confirmed: tool discovery uses
getDeclaredMethods()only, so superclass@Toolmethods are skipped. I'll add hierarchy traversal and tests. - Assistant
Duplicate detection was broken by
putIfAbsentsilently dropping same-class overloads. I'll validate duplicates before deduplicating for inheritance. - Assistant
You were right — this was a bug.
@Tooldiscovery only scannedgetDeclaredMethods()on the concrete class, so tools defined in a superclass were never registered or executed.Root cause
Three places only looked at methods declared on the runtime class:
ToolSpecifications.toolSpecificationsFrom()— tool specs sent to the LLMToolService.findTools()— tool registration in AI ServicesDefaultToolExecutor.findMethod()— tool execution lookup
Fix
Added
ToolSpecifications.toolMethodsFrom()which walks the class hierarchy (subclass → superclass) and collects all@Tool-annotated methods. Subclass methods take precedence when they override a superclass tool with the same name. Same-class duplicate tool names still fail validation as before.Updated all three call sites to use this shared logic.
Tests added
- Inherited tools are included in
ToolSpecifications - Subclass overrides of superclass tools deduplicate correctly
ToolService.findTools()picks up inherited toolsDefaultToolExecutorcan execute inherited tools
This applies to both core LangChain4j and AI Services (and agentic, which builds on the same
ToolService). You can now define@Toolmethods in a base class and use them from subclasses without re-declaring them.
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 →
- 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 →