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 codebase.Let me start by:
- Understanding the repository structure
- Finding the relevant files
- Reproducing the issue
- Fixing it
Assistant
Let me look at the relevant files. First, the main file mentioned in the issue:
langchain4j-agentic/src/main/java/dev/langchain4j/agentic/AgenticServices.java.Assistant
Let's look at the AgenticServices.java file:
Assistant
Let me try to read the file using cat:
Assistant
Let me search for the
createAgenticSystemmethod and the surrounding contextAssistant
Let me look at the
createAgenticSystemmethods starting around line 298Assistant
Now let me look at the
configureAgentmethod andAgentBuilder:Assistant
Let's look at
DeclarativeUtil.javato findconfigureAgent:Assistant
Now let's look at the `AgentBuilder.java
Assistant
Now let me look at the ToolService class where the error originates
Assistant
Let me look at this file:
Assistant
Let me see the relevant sections around the
addToolsmethod andcreateContextFromStaticToolsAndProvidersAssistant
Let me look at the relevant methods around lines 346-400
Assistant
Let me look at the
AiServicesclass to understand how toolProviders are handledAssistant
Let me look at how
toolProvidersis set up in AiServicesAssistant
Let me look at the
Skillsclass to understand howactivate_skilltool is registeredAssistant
Let's look at this file
Assistant
Let me look at the
AgentBuilderconstructor flow more carefully:Assistant
Let me look at the AgentBuilder constructor to see where
configureAgentis called:Assistant
Let me trace through the problem more carefully. Let me check if there are other places that call
new AgentBuilder:Assistant
Let me look at
validateChatModeland the rest of `AgentAssistant
So
configureChatModelcallsvalidateChatModel()and then uses whichever model is set. If no model is set, it throws an exception.Now let me look at
validateChatModel:Assistant
Let me see it:
Assistant
Now I understand the issue. Let me look at how
configureAgentis called:In
createAgenticSystem:agentBuilder(agentServiceClass)→new AgentBuilder<>(agentServiceClass)→ constructor callsconfigureAgent(agentServiceClass, this)(first call)configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator)(second call)
Both calls invoke
@ToolProviderSuppliermethod and add theToolProviderto the builder's list. Since the@ToolProviderSupplierreturns a newSkillsinstance each time, two differentToolProviderobjects end up in the list, both providingactivate_skill→ duplicate error.Let me also verify the tool providers handling in `ToolService
Assistant
Let me see the rest of `setupTools
Assistant
Now I have a clear understanding of the issue. Let me implement the fix. The problem is that
configureAgentis called twice:- In
AgentBuilderconstructor (viaagentBuilder(agentServiceClass)) - Explicitly in
createAgenticSystem(viaconfigureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator))
Both calls invoke the
@ToolProviderSuppliermethod and add theToolProviderto the list, causing duplicates.The fix: Remove
configureAgentfromAgentBuilderconstructor, call it explicitly where needed (inagentBuilder()and once increateAgenticSystem).Let me first understand the exact lines:
- In
Assistant
Let me look at the
AgentConfiguratorclass:Assistant
Let me look at the
AgentConfiguratorrecord and `DeclarativeAgentCreationAssistant
Now I have a clear plan. Let me implement the fix:
- Remove
configureAgentfromAgentBuilderconstructor - Add
configureAgentcall inagentBuilder(Class<T>)method inAgenticServices - In
createAgenticSystem, usenew AgentBuilder<>(agentServiceClass)directly instead ofagentBuilder(), then callconfigureAgentonce
Let me start:
- Remove
Assistant
Let me first remove the
configureAgentcall from theAgentBuilderAssistant
I need to open the file first:
Assistant
Now let me remove the
configureAgentcall from theAssistant
Now remove the
configureAgentcall from the constructorAssistant
Now let me also remove the unused import of
configureAgentfrom AgentAssistant
Now let me update
AgenticServices.java. Let me open it:Assistant
Let me find the
agentBuilder()method:Assistant
Let me see lines 115-125
Assistant
Now let me update
agentBuilder()to callconfigureAgentafter constructionAssistant
Now let me update
createAgenticSystem. Let me find the method that takesChatModelandAgentConfiguratorAssistant
Now let me update the
createAgenticSystemmethod to not callagentBuilder()followed by anotherconfigureAgent. Instead, create the builder directly and call `configureAgentAssistant
Now let me check if
UntypedAgentBuilderalso needs similarAssistant
Let me check if there are other places in the codebase that might be affected by this change:
Assistant
Let me try to compile the changes to verify
Assistant
The code compiles. Let me find and run the relevant tests:
Assistant
Let me look for tests that use
createAgenticSystemoragentBuilderAssistant
Let me also compile the test sources to make sure everything is correct:
Assistant
Good, compilation succeeded. Let me also check if there are any other callers of
configureAgentthat might be affectedAssistant
Let me check line 600 where
configureAgentisAssistant
This is another place with the same issue! Let me see the full context
Assistant
I need to fix this too. Let me update
Assistant
Let me recompile to verify
Assistant
Let me compile tests too
Assistant
All compiles fine. Let me review the final diff of my
Assistant
Let me verify there are no other places where the same
configureAgentpattern could cause issuesAssistant
Let me check line 100 in `
Assistant
Let me check the
DeclarativeAgentCreationContextinterface to understand its usage:Assistant
Let me verify the
UntypedAgentBuilderusage is fine by checking theUntypedAgentclass:Assistant
Let me also search for any remaining patterns where
agentBuilder()is followed by another `Assistant
The fix looks complete. Let me now submit the changes. But first, let me verify the change one more time by running a quick unit test
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 →