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
AgenticServicesand nearby tests/build structure first, then trace how tool providers are collected so the fix deduplicates registrations at the correct layer rather than special-casingactivate_skill. - Assistant
The factory has several overloads, so I’ll locate their implementations and the configurator/tool-provider path, including
AgentBuilder, to compare the working direct-builder behavior with the failing system factory behavior. - Assistant
I found the relevant overload at lines 318–333. I’ll read that section plus recursive agent creation and declarative configuration to identify exactly where the same provider list is applied more than once.
- Assistant
The likely duplication is in
DeclarativeUtil.configureAgent, which the factory calls after creating a builder. I’ll inspect it and relevant unit tests, then use a local mock chat model/tool provider to reproduce without external LLM access. - Assistant
configureAgentadds the declarative provider once, so duplication must involve the builder’s initialization/build pipeline (or configurator application). I’ll inspect the complete constructor/build flow and recent git history/status for clues about partially implemented changes. - Assistant
The root cause is now clear:
AgentBuilder’s constructor already calls declarative configuration, thencreateAgenticSystemcalls it again to supply the inherited/default model and configurator. Additive settings—especially tool providers—are therefore duplicated, while scalar settings are merely overwritten. I’ll inspectToolProvidersemantics and allconfigureAgentcall sites before choosing whether to prevent the second declarative pass or safely deduplicate builder registrations. - Assistant
A generic
ToolProvidermay be dynamic, so deduplicating by calling it early or by generated tool names would alter semantics. The robust fix is to ensure declarative suppliers run once while still applying the inherited model and user configurator. I’ll inspect model setter behavior and supplier tests to preserve precedence, then implement a focused “finish configuration” path rather than rerunning every supplier. - Assistant
The current two-phase behavior can be corrected without changing public builder semantics: phase one (the constructor) resolves all declarative suppliers; phase two should only inject a fallback model when no model supplier annotation exists and invoke the external configurator. This preserves supplier precedence, dynamic model suppliers, and one configurator invocation. I’ll implement that refactor and then create a temporary regression test outside the repository test tree that counts supplier/provider calls and triggers an invocation.
- Assistant
The environment lacks Python, so the edit did not apply (the subsequent compile was only a clean baseline check). I’ll apply the same focused change with the provided editor command and compile again.
- Assistant
Compilation passes. To reproduce the exact failure mechanics without relying on the optional Skills module, I’ll use a static provider returning one named tool and a deterministic mock model that requests/accepts tool execution. First I’ll identify the project’s existing mock model helpers and test execution conventions.
- Assistant
There is already a
SingleAgentIThelper for provider-backed tools. I’ll inspect that test and, if it is suitable, run it alongside declarative unit tests. I’ll also review formatter output because this project enforces style. - Assistant
The relevant unit suite passes; Spotless itself cannot run because this checkout has no
origin/mainreference, not because of a formatting violation. The duplicate exception occurs before the model response whenever static providers are materialized, so a minimal temporary Java program can reproduce it with a provider returning a single tool and a dummy model. I’ll compile/run that against the built module and assert both successful invocation and exactly one supplier call. - Assistant
The temporary reproducer now passes and confirms the provider supplier executes once. Before finalizing, I’ll run the formatter by supplying the missing local ratchet reference, then execute the broader non-IT agentic test suite and inspect the final diff for unintended changes.
- Assistant
The full test suite passes, but
spotless:applyreformatted unrelated pre-existing code throughout the file because the recent source was not formatted relative to the artificial ratchet. I’ll revert that formatting-only noise and reapply only the functional method change in formatter-compliant form, keeping the patch minimal. - Assistant
The patch is minimal again. I’ll do one final compile/test run on the exact final source, verify only the intended file is modified, and inspect the concise diff. Then I’ll submit with the requested checklist assessment.
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 →