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 start by exploring the repository structure and locating the relevant code for
createAgenticSystemand the duplicate tool registration issue. - Assistant
Next I'll inspect
AgenticServices.javaand the skills/tool-provider related code. - Assistant
rg is not found, let me use grep instead.
- Assistant
I'll inspect the
createAgenticSystemimplementation and how tool providers get registered. - Assistant
Let me look at AgentBuilder and DeclarativeUtil for how tools are configured. Also look at skills package.
- Assistant
I'll examine AgentBuilder's tool provider handling and how Skills contributes
activate_skill. - Assistant
I'll look at
ToolServicefor how static vs dynamic tool providers are handled and where duplicates are introduced. - Assistant
Let me read the ToolService createContextFromStaticToolsAndProviders method fully.
- Assistant
Checking recent commits and AgentBuilder for double-registration of tool providers.
- Assistant
Checking whether
agentBuilderalready applies configuration, which could cause double registration. - Assistant
I've confirmed the double
configureAgentpath. Checking history and tests for the intended design. - Assistant
I'll check how listeners and chat model overrides behave under this double-configuration path.
- Assistant
Let me see the listener method fully and how ComposedAgentListener works.
- Assistant
For listeners if configureAgent runs twice with AgentListenerSupplier: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.I have reviewed the issue description and the provided code snippet. The root cause is that
AgenticServices.createAgenticSystem()callsconfigureAgenttwice—once in theAgentBuilderconstructor and once in the explicit call—resulting in duplicateToolProviderregistrations and theactivate_skilltool being added twice.To fix this, I will restructure the
AgentBuilder creationlogic so thatconfigureAgentis invoked only once for the full configuration (including tools, chat model, and configurator). This will prevent duplicate registrations while preserving the existingagentBuilder(Class).build()behavior.I will implement this by introducing a flag in
AgentBuilderto skip the auto-configuration in the constructor, and use a new factory methodunconfiguredforcreateAgenticSystem.Let me proceed with the changes. First, I'll check the current state of the file.
I need to modify
AgenticServices.javato use the skip-auto-configure path.Let me also check for the same pattern in
createBuiltInAgentExecutor.I will make the changes to prevent double configuration.
Let me implement the fix.
I will add a new constructor and factory method to
AgentBuilderto support unconfigured creation.Let me proceed with the code changes.
- Assistant
I'll implement a bare
AgentBuilderpath so configuration only happens once. - Assistant
Let me fix the grep.
- Assistant
Let me see line 590-605 of AgenticServices more carefully.
- Assistant
Confirming the double-
configureAgentpath. I'll check for an existing dummy model we can use to reproduce. - Assistant
I'll check module dependencies and then implement and verify the fix.
- Assistant
Implementing the fix: construct the builder without declarative configuration when
createAgenticSystemwill configure it explicitly. - Assistant
I'll check if Internal import already exists in AgentBuilder.
- Assistant
Need to open the file first or use exact content.
- Assistant
Let me apply the edit to AgentBuilder constructor.
- Assistant
Now replace the constructor.
- Assistant
I need to navigate to the constructor first.
- Assistant
Now try the replace again.
- Assistant
Now update AgenticServices to use the new constructor with false.
- Assistant
I need to check imports for AgentBuilder - already imported.
- Assistant
Now fix createSubagent as well.
- Assistant
Fix createSubagent.
- Assistant
I'll write a temporary reproduction script and compile to verify the fix.
- Assistant
Building the required modules, then adding a reproducer.
- Assistant
HOME is not set. Let me set it.
- Assistant
@Internal is not applicable to constructors. Let me check the Internal annotation.
- Assistant
@Internal only applies to TYPE, METHOD, PACKAGE —I'll switch to an
@Internalstatic factory method instead. - Assistant
Now update AgenticServices to use the factory method.
- Assistant
Also fix createSubagent.
- Assistant
Need to goto line first
- Assistant
Rebuilding, then writing a temporary reproducer to verify the fix.
- Assistant
Build succeeded. Next I'll create a temporary reproducer to confirm the fix.
- Assistant
Fix confirmed. Running unit tests that don't need API keys:
- Assistant
I'll also verify the subagent path and clean up the temporary reproducer.
- Assistant
Verifying the final diff looks correct.
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 →