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
Let me start by understanding the repository structure and the issue. The bug is about duplicate
activate_skilltool definition error when usingAgenticServices.createAgenticSystem(). Let me explore the relevant files.Let me first look at the repository structure and find the relevant files.
Assistant
Let me look at the key files mentioned in the issue:
AgenticServices.java- the main file with the bugToolService.java- where the error is thrown- The Skills/ToolProvider related files
Let me start by examining the AgenticServices.java file.
Assistant
Let me open and read the file.
Assistant
Let me see the full file, particularly the
createAgenticSystemmethod and surrounding code.Assistant
Let me read the createAgenticSystem method.
Assistant
Let me read the
createAgenticSystemmethods and theToolServicewhere the error occursAssistant
Now let me look at the
configureAgentmethod inDeclarativeUtil.javaand theToolService.javawhere the error occursAssistant
Let me read the DeclarativeUtil.java file.
Assistant
Let me look at the AgentBuilder and understand how tool providers are handled, and also look at the Skills class.
Assistant
Now let me look at the ToolService.java where the error occurs, and also the AgentBuilder to see how tool providers are handled
Assistant
Let me read around line 398 of ToolService.java where the error is thrown
Assistant
Let me read more of ToolService.java to understand the full flow:
Assistant
Let me look at the AgentBuilder to see how tool providers are accumulated.
Assistant
Let me read the AgentBuilder.java file.
Assistant
Let me look at the
setupToolsmethod in the AgentBuilder:Assistant
Let me look at the setupTools
Assistant
Let me check all places where
AgentBuilderis constructed:Assistant
Let me check all callers of
configureAgent:Assistant
Let me check line 598 of AgenticServices
Assistant
Let me check what uses
AgentBuilder(including tests):Assistant
Let me search for patterns where
agentBuilderis used with.build()directlyAssistant
Let me look at AgentUtil.java line
Assistant
Let me look at the
UntypedAgentBuilderto understand the pattern betterAssistant
Let me look at the
validateChatModelmethod in AgentBuilder:Assistant
Let me read the validateChatModel method
Assistant
Now let me look at the two key places where the duplication happens. Let me also check if there are tests that validate this behavior
Assistant
Let me check if there are any tests that directly construct
AgentBuilderor useagentBuilder().build():Assistant
Now I have a clear understanding of the problem. Let me reproduce it first and then fix it.
The Problem:
AgentBuilderconstructor callsconfigureAgent(agentServiceClass, this)(line 141)createAgenticSystemandcreateSubagentcallconfigureAgentAGAIN after constructing viaagentBuilder()- This results in duplicate tool provider registrations, causing the
activate_skillduplicate error
The Fix Plan:
- Remove
configureAgentcall fromAgentBuilderconstructor - Add it to the
agentBuilder(Class)factory method (so direct builder usage still works) - In
createAgenticSystemandcreateSubagent, createAgentBuilderdirectly (not via factory) and callconfigureAgentonly once with the proper parameters
Let me first look at the Skills class to understand the tool provider structure
Assistant
Now I have a clear understanding of the bug. Let me implement the fix.
The root cause:
AgentBuilderconstructor callsconfigureAgent(), thencreateAgenticSystemandcreateSubagentcallconfigureAgent()again, resulting in duplicate tool provider registration.My fix:
- Remove
configureAgentcall fromAgentBuilderconstructor - Add
configureAgentcall to theagentBuilder(Class)factory method - In
createAgenticSystem, constructAgentBuilderdirectly (not via factory) to avoid doubleconfigureAgent - In
createSubagent, constructAgentBuilderdirectly (not via factory)
Let me start:
- Remove
Assistant
First, remove
configureAgentfrom AgentAssistant
Now let me also clean up the extra blank line. Then update the factory method:
Assistant
I accidentally broke the code. Let me fix the edit properly.
Assistant
I lost the
this.name =line. Let me restoreAssistant
Let me restore the file and try a different approach.
Assistant
Now let me use the
replacecommand with heredoc to safely handle the!Assistant
Good, the constructor is clean. Now I need to:
- Remove the unused
configureAgentimport from AgentBuilder.java - Add
configureAgentto theagentBuilder(Class)factory method - Fix
createAgenticSystemandcreateSubagent
Let me first remove the unused import:
- Remove the unused
Assistant
Let me scroll to the top of the
Assistant
Now remove the unused import
Assistant
Good. Now let me update the factory method
agentBuilder(Class)in AgenticServices.java to addconfigureAgentcall:Assistant
Now update the factory method to call
configureAgent:Assistant
Now let me update
createAgenticSystemto NOT go through the factory method. Let me find the relevant code:Assistant
Now let me fix
createAgenticSystem. Replace theagentBuilderfactory call with direct construction:Assistant
Let me try again with explicit file path:
Assistant
Let me view the exact text at that location:
Assistant
Let me try the replace with the exact indentation:
Assistant
Let me go to the line first
Assistant
Now use edit to replace the specific lines:
Assistant
Now let me fix
createSubagent. Let me find and view it:Assistant
Let me view the createSubagent method:
Assistant
Now fix the
createSubagentmethod:Assistant
Now fix the createSubagent method:
Assistant
Let me verify the imports are in order. Let me check that
AgentBuilderis imported:Assistant
Good. Now let me also check if there are any other places that might need similar fixing. Let me look at the
AgentUtil.agentToExecutormethod:Assistant
Let me verify the AgentBuilder constructor looks clean now:
Assistant
Good. Now let me compile and run the relevant tests. Let me first try to compile the changed files:
Assistant
Compilation succeeded. Now let me run the tests:
Assistant
Let me get the summary of the test results:
Assistant
All 45 tests in langchain4j-agentic pass, plus 322 from dependencies. BUILD SUCCESS. Let me also check if there are tests in other modules that test the Skills/agentic interaction:
Assistant
Let me rerun with more output:
Assistant
Let me also run the agentic-patterns tests since they use `createAgentic
Assistant
All tests pass. Let me also run the Skills tests:
Assistant
All tests pass! Let me do a final review of all my changes:
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 →