ISSUE DESCRIPTION [BUG] Duplicate activate_skill tool definition error when using…
- User
ISSUE DESCRIPTION
[BUG] Duplicate
activate_skilltool definition error when usingAgenticServices.createAgenticSystem()Describe the bug When creating an agentic system withAgenticServices.createAgenticSystem(), even with a single agent, the application throws anIllegalConfigurationException: Duplicated definition for tool: activate_skillduring execution, caused by multiple registrations of non-dynamicToolProviderinstances.Log and Stack trace
Caused by: dev.langchain4j.service.IllegalConfigurationException: Duplicated definition for tool: activate_skill at dev.langchain4j.service.tool.ToolService.addTools(ToolService.java:398) at dev.langchain4j.service.tool.ToolService.lambda$createContextFromStaticToolsAndProviders$0(ToolService.java:378) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at dev.langchain4j.service.tool.ToolService.createContextFromStaticToolsAndProviders(ToolService.java:371) at dev.langchain4j.service.tool.ToolService.createContext(ToolService.java:338) at dev.langchain4j.service.DefaultAiServices$1.invoke(DefaultAiServices.java:260) at dev.langchain4j.service.DefaultAiServices$1.invoke(DefaultAiServices.java:154) at jdk.proxy2/jdk.proxy2.$Proxy5.test(Unknown Source) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ... 5 moreTo Reproduce
public class Main { public static void main(String[] args) { var result=AgenticServices.createAgenticSystem(FooAgent.class).test(); // var result=AgenticServices.agentBuilder(FooAgent.class).build().test(); System.out.println(result); } public interface FooAgent { @Agent @UserMessage("Hello") String test(); @ToolProviderSupplier static ToolProvider testTool() { return Skills.builder() .skills(Skill.builder().name("test").description("test").content("test").build()) .build().toolProvider(); } @ChatModelSupplier static ChatModel chatModel() { return OpenAiChatModel.builder() .baseUrl("http://192.168.31.32:8000/v1") .apiKey("none") .modelName("qwen3.6") .logRequests(true) .logResponses(true) .build(); } } }Expected behavior The agentic system should run successfully, properly deduplicating tools (including the built-in
activate_skilltool) when registering non-dynamicToolProviderinstances.Please complete the following information:
- LangChain4j version: latest agentic snapshot
- LLM(s) used: Qwen 3.6 (via OpenAiChatModel)
- Java version: 25
- Spring Boot version (if applicable): N/A
Additional context The bug is caused by
createAgenticSystemregistering non-dynamicToolProviderinstances multiple times. Theactivate_skilltool is automatically added for everySkillProviderinstance, leading to duplicate registration even with a single agent.Interface
Type: Function Name: createAgenticSystem Path: langchain4j-agentic/src/main/java/dev/langchain4j/agentic/AgenticServices.java Input: Class agentServiceClass, AgentConfigurator agentConfigurator Output: T (the created agentic system instance of the requested type) Description: Creates an agentic system from a declarative agent service class, applying the provided configurator to each agent. This overload resolves the default chat model from the agent class and deduplicates tool registrations across the system.
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
I’ll inspect
AgenticServices, related builder/tool-provider flows, and existing agentic tests to identify where static providers are registered more than once. Then I’ll reproduce with the narrowest relevant test or temporary fixture, patch the deduplication at the system-construction boundary, and run focused tests plus broader module tests if feasible. - Assistant
The declarative utility already adds a supplier directly to each
AgentBuilder, so the duplication likely comes fromcreateAgenticSystemconfiguring the same builder/type through multiple passes. I’ll now isolate all overloads and recursive declarative construction, then inspectconfigureAgentand tool storage semantics to determine whether identity-based or definition-based deduplication is intended. - Assistant
The issue’s specified interface is the overload taking
(Class<T>, AgentConfigurator), but all overloads converge on the three-argument implementation. I’ll inspect that implementation and recursivecreateAgentmethod in full, including configurator behavior, because the likely defect is that root-agent declarative configuration is applied both before and during recursive creation. - Assistant
The duplication is confirmed structurally:
new AgentBuilder<>(class)invokesconfigureAgent(class, this)in its constructor, andcreateAgenticSystemimmediately invokesconfigureAgent(...)again. Thus a supplier is invoked twice and both providers reachAiServices. I’ll inspect the remainder ofconfigureAgentand configurator API so the fix preserves default-model resolution and callback ordering without suppressing legitimate providers explicitly added by users. - Assistant
A safe fix is to separate one-time annotation processing from system-level completion. The constructor should continue processing all declarative suppliers (preserving standalone
agentBuilder(...).build()), whilecreateAgenticSystemshould only (1) supply the inherited/default model when the class has no model supplier and (2) run the external configurator. This avoids duplicate invocation not just for tools but for all stateful suppliers/listeners. I’ll check history around the current double-configuration and existing configurator test expectations before implementing that split. - Assistant
History confirms the double pass predates tool-provider support; adding providers exposed it because unlike scalar settings they accumulate. I’ll implement a focused
completeAgentConfigurationpath inDeclarativeUtiland route both root and subagent construction through it after the constructor’s one-time supplier pass. This keeps declarative model suppliers authoritative, validates a missing inherited model, and invokes each external configurator exactly once. - Assistant
Python is unavailable in this environment, so no files were changed. I’ll apply the same small refactor with the repository editor commands instead.
- Assistant
The editor retained the original private-method declaration in addition to the replacement, and the subagent replacement did not apply. I’ll remove that duplicate and update the remaining call, then compile to catch formatting/API issues.
- Assistant
Compilation was blocked only because the wrapper requires
HOME; source edits and whitespace checks succeeded. Before compiling withHOMEset, I’ll verify module dependencies and available mock chat models so I can run a temporary regression harness that actually invokes an agent with a static provider defining a fixed tool name, reproducing the sameToolServicepath without an external LLM. - Assistant
The module compiles with the refactor. For a faithful runtime regression check, I’ll build the module’s test classpath and inspect the tool-provider API, then compile a temporary Java program under
/tmp(not in the repository). Its supplier will count invocations and return a static tool definition; the model will return a plain response, forcingToolServicecontext creation where the original duplicate exception occurred. - Assistant
The static-provider semantics match the reported stack: each registered provider contributes its tools into one context, and duplicate names throw. I’ll now execute the temporary harness and assert both successful invocation and exactly one supplier call. This specifically distinguishes the fix from merely hiding duplicate definitions downstream.
- Assistant
The harness reached declarative discovery but Java reflection rejected its package-private nested interface; that is a harness visibility issue, not the product path. I’ll make the temporary interface public and rerun unchanged otherwise.
- Assistant
The regression harness now succeeds and confirms the supplier is called once; the full unit-test phase for
langchain4j-agenticalso passes. I’ll run Spotless formatting/checks, inspect the resulting diff for unintended changes, and run the focused declarative tests that exercise default model propagation and configurator callbacks. - Assistant
Spotless could not run because this checkout lacks its configured
origin/mainratchet reference;git diff --checkstill passes, and the focused chat-supplier/configurator-related tests passed. I’ll inspect formatter configuration for a ratchet override, run formatting if possible without changing repository configuration, then perform final module verification and status review. - Assistant
The formatter configuration hardcodes
origin/main, while the uploaded repository has no remote refs. I can safely create a local metadata-onlyorigin/mainref atHEAD(not a source change), allowing Spotless to identify and format exactly our modified files. Then I’ll rerun tests and inspect the final diff. - Assistant
Spotless formats whole changed files rather than only changed lines, producing 300+ lines of unrelated churn. I’ll revert those formatting-only changes and reapply the functional patch narrowly, following the surrounding style manually. Then I’ll rerun compilation/tests without
spotless:apply; this keeps the submission reviewable whilediff --checkvalidates whitespace. - Assistant
The editor’s preview was emitted before the subsequent duplicate-line removal; the final diff size is narrow again. I’ll verify the actual file around that boundary, compile and rerun all module tests, then rerun the
/tmpduplicate-provider harness against the newly compiled classes. - Assistant
Final review shows only two source files changed, with no repository tests added. The fix preserves these edge cases: inherited/default models are applied only when no chat or streaming supplier exists; declarative suppliers remain authoritative; external configurators still run after model setup; and both root agents and recursively built subagents use the one-time completion path.
Checklist:
- Reproduced the reported error: The code path was reproduced structurally and with a temporary
/tmpharness defining the same fixedactivate_skilltool; before the fix, construction registered the supplier twice, which is exactly theToolServiceduplicate-definition condition. - Confirmed the fix resolves it: The harness now invokes successfully and asserts the
@ToolProviderSupplieris called exactly once (supplier calls=1). - Considered edge cases: Checked root/subagent creation, inherited models, static and parameterized chat suppliers, streaming suppliers, and configurator ordering.
- Ran affected existing tests: The complete
langchain4j-agenticunit-test suite passes; compilation/package also succeeded. Spotless’s normal ratchet setup was unavailable initially due the missing remote ref; an attempted whole-file format created unrelated churn and was reverted, whilegit diff --checkpasses.
I’ll submit the narrow functional change now.
- Reproduced the reported error: The code path was reproduced structurally and with a temporary
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →