Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.6-27B· alibabaHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [BUG] Duplicate activate_skill tool definition error when using…

  1. User

    ISSUE DESCRIPTION

    [BUG] Duplicate activate_skill tool definition error when using AgenticServices.createAgenticSystem() Describe the bug When creating an agentic system with AgenticServices.createAgenticSystem(), even with a single agent, the application throws an IllegalConfigurationException: Duplicated definition for tool: activate_skill during execution, caused by multiple registrations of non-dynamic ToolProvider instances.

    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 more
    

    To 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_skill tool) when registering non-dynamic ToolProvider instances.

    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 createAgenticSystem registering non-dynamic ToolProvider instances multiple times. The activate_skill tool is automatically added for every SkillProvider instance, 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. Qwen Assistant

    Let me start by exploring the repository structure to understand the codebase and then locate the relevant files mentioned in the issue.

    The issue is about a duplicate activate_skill tool definition error when using AgenticServices.createAgenticSystem(). The bug is caused by registering non-dynamic ToolProvider instances multiple times.

    Let me first explore the repository structure and then look at the AgenticServices.java file.

  3. Qwen Assistant

    Let me explore the AgenticServices.java file first since that's where the createAgenticSystem method is located.

  4. Qwen Assistant

    Let me search for the createAgenticSystem method specifically:

  5. Qwen Assistant

    Now I need to understand the issue better. Looking at createAgenticSystem method around line 330, when the agent is not a composed agent, it falls through to creating the agent using agentBuilder. Let me look at the AgentBuilder class and how it handles tool providers:

  6. Qwen Assistant

    Now let me look at the DeclarativeUtil.configureAgent method to understand how tool providers are configured:

  7. Qwen Assistant

    Now I can see the issue. Looking at the configureAgent method in DeclarativeUtil.java, line 55 calls configureAgent(agentType, null, true, agentBuilder, AgenticServices.AgentConfigurator.empty()); which is called by the constructor of AgentBuilder. Then, when createAgenticSystem calls configureAgent again, it would register the ToolProvider again!

    Let me trace the flow:

    1. createAgenticSystem() is called
    2. It creates an AgentBuilder via agentBuilder(agentServiceClass)
    3. In AgentBuilder constructor, configureAgent(agentServiceClass, this) is called, which registers tool providers
    4. Then createAgenticSystem calls configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator) again!
    5. This causes the tool provider to be registered twice!

    Let me verify this:

  8. Qwen Assistant

    Now I see the issue clearly:

    1. In line 337, agentBuilder(agentServiceClass) creates a new AgentBuilder instance
    2. The AgentBuilder constructor (line 123 in AgentBuilder.java) calls configureAgent(agentServiceClass, this) which already registers the tool providers
    3. Then on line 338, configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator) is called again, which registers the same tool providers again!

    This causes duplicate registration of ToolProvider instances, leading to the activate_skill tool being registered multiple times.

    Let me look at the AgentBuilder constructor more closely:

  9. Qwen Assistant

    Now I understand the issue fully. The AgentBuilder constructor calls configureAgent(agentServiceClass, this) on line 141, which registers tool providers. Then in AgenticServices.createAgenticSystem(), line 338 calls configureAgent() again, causing duplicate registration.

    The fix should be in AgenticServices.createAgenticSystem() - we should NOT call configureAgent again after creating the AgentBuilder, since the constructor already calls it.

    Let me verify this understanding by checking if there are tests:

  10. Qwen Assistant

    Let me look at the test file to understand what kind of agents are being tested and see if any of them use @ToolProviderSupplier:

  11. Qwen Assistant

    Let me search more broadly for tests related to ToolProviderSupplier:

  12. Qwen Assistant

    Let me now look at how the fix should be applied. The issue is that configureAgent is called twice:

    1. Once in the AgentBuilder constructor
    2. Once in createAgenticSystem after creating the builder

    The fix should be to remove the redundant call to configureAgent in createAgenticSystem.

    Let me verify that the AgentBuilder constructor already sets up the chat model and configurator properly:

  13. Qwen Assistant

    Looking at the two configureAgent overloads:

    1. configureAgent(agentType, agentBuilder) - calls the private method with chatModel=null, allowNullChatModel=true, and agentConfigurator=empty()
    2. configureAgent(agentType, chatModel, agentBuilder, agentConfigurator) - calls the private method with the actual chatModel and agentConfigurator

    So when createAgenticSystem is called:

    1. First configureAgent is called in AgentBuilder constructor with chatModel=null and empty configurator
    2. Then configureAgent is called again with the actual chatModel and agentConfigurator

    The issue is that:

    • Tool providers are registered in BOTH calls
    • The ChatModel from the first call (null) is overridden by the second call, which is fine
    • But the ToolProvider is added twice, causing the duplicate error

    The fix should be to NOT call configureAgent again in createAgenticSystem since the AgentBuilder constructor already does it. But wait, we need to pass the chatModel and agentConfigurator somehow.

    Let me check if the AgentBuilder constructor version can be modified to accept these parameters, or if we should pass them differently:

  14. Qwen Assistant

    I see the same pattern in createBuiltInAgentExecutor at line 597-598. This would also have the duplicate registration issue.

    Let me think about the proper fix. The issue is:

    1. AgentBuilder constructor calls configureAgent(agentServiceClass, this)
    2. Then createAgenticSystem and createBuiltInAgentExecutor call configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator) again

    There are two approaches:

    1. Remove the configureAgent call from the AgentBuilder constructor - but this would break other usages
    2. Remove the configureAgent call from createAgenticSystem and createBuiltInAgentExecutor - but then we need to pass chatModel and agentConfigurator to the constructor

    Looking at it more carefully, I think the best approach is to create a new constructor or factory method for AgentBuilder that accepts chatModel and agentConfigurator, or to modify the existing configureAgent method to be idempotent.

    Actually, wait - let me re-read the AgentBuilder constructor. It calls configureAgent(agentServiceClass, this) which is the overload that uses chatModel=null and empty configurator. So the second call in createAgenticSystem would set the actual chatModel and apply the configurator. But it also re-registers the tool providers.

    The simplest fix would be to modify the AgentBuilder constructor to NOT call configureAgent, and let the caller configure the agent. But this might break other code paths.

    Let me check if there's a way to pass chatModel and agentConfigurator to AgentBuilder:

  15. Qwen Assistant

    The best fix is to modify the AgentBuilder constructor to accept chatModel and agentConfigurator parameters, so that configureAgent is only called once with the correct parameters. This way, createAgenticSystem and createBuiltInAgentExecutor can pass the correct values directly to the constructor.

    Let me look at how this would work:

  16. Qwen Assistant

    I think the cleanest fix is to modify the AgentBuilder class so that it doesn't call configureAgent in its constructor when it's being used from createAgenticSystem or createBuiltInAgentExecutor.

    But actually, looking at the code flow more carefully:

    1. agentBuilder(agentServiceClass) creates an AgentBuilder that already has tool providers registered (from constructor)
    2. configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator) is called again, which re-registers the same tool providers

    The fix should be to remove the duplicate configureAgent call from createAgenticSystem and createBuiltInAgentExecutor. But we still need to set the chatModel and apply the agentConfigurator.

    Wait, let me re-check what the constructor configureAgent call does vs what the second call does:

    The first call: configureAgent(agentType, null, true, agentBuilder, AgenticServices.AgentConfigurator.empty())

    • Registers ToolsSupplier
    • Registers ToolProviderSupplier
    • Registers ContentRetrieverSupplier
    • Registers RetrievalAugmentorSupplier
    • Registers ChatMemoryProviderSupplier
    • Registers ChatMemorySupplier
    • Registers ChatModelSupplier (with null as fallback)
    • Registers AgentListenerSupplier
    • Applies empty agentConfigurator

    The second call: configureAgent(agentType, chatModel, false, agentBuilder, agentConfigurator)

    • Registers ToolsSupplier again
    • Registers ToolProviderSupplier again (THIS IS THE BUG)
    • Registers ContentRetrieverSupplier again
    • Registers RetrievalAugmentorSupplier again
    • Registers ChatMemoryProviderSupplier again
    • Registers ChatMemorySupplier again
    • Registers ChatModelSupplier (or uses provided chatModel)
    • Registers AgentListenerSupplier again
    • Applies agentConfigurator

    The fix should be to not call configureAgent in the AgentBuilder constructor, and instead pass the chatModel and agentConfigurator when constructing the builder. But this would change the API significantly.

    A simpler approach: Add an overloaded constructor or factory method that takes chatModel and agentConfigurator, and don't call configureAgent in the original constructor. Instead, only configure in the new constructor/method.

    But wait, let me think about this differently. The issue is that createAgenticSystem and createBuiltInAgentExecutor call both the constructor (which calls configureAgent) AND then call configureAgent explicitly.

    The simplest fix is to remove the explicit configureAgent calls from createAgenticSystem and createBuiltInAgentExecutor, and instead have the AgentBuilder constructor accept the chatModel and agentConfigurator parameters.

    Let me implement this fix:

  17. Qwen Assistant

    Now I understand the issue clearly. The solution is to add a package-private constructor to AgentBuilder that accepts ChatModel and AgentConfigurator, and then use that constructor in createAgenticSystem and createBuiltInAgentExecutor. The public constructor will continue to work as before.

    Actually, let me think about this more carefully. The cleanest fix would be:

    1. Add a new package-private constructor in AgentBuilder that takes ChatModel and AgentConfigurator
    2. Use this new constructor in createAgenticSystem and createBuiltInAgentExecutor
    3. This new constructor will call configureAgent with the proper parameters instead of the default one

    Let me implement this fix:

  18. Qwen Assistant

    Now let me check the AgenticServices.AgentConfigurator type:

  19. Qwen Assistant

    Now I need to understand the fix better. The issue is that when createAgenticSystem is called:

    1. agentBuilder(agentServiceClass) is called, which creates an AgentBuilder
    2. The AgentBuilder constructor calls configureAgent(agentServiceClass, this) - this registers tool providers
    3. Then configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator) is called again - this registers the same tool providers again

    The fix is to add a new constructor to AgentBuilder that takes ChatModel and AgentConfigurator, and use it in createAgenticSystem and createBuiltInAgentExecutor.

    Let me implement this fix:

  20. Qwen Assistant

    Let me use sed instead:

  21. Qwen Assistant

    I'll use the edit command to make the changes. Let me first open the file and make the changes:

  22. Qwen Assistant

    Now I need to make two changes:

    1. In AgentBuilder.java: Add a new package-private constructor that accepts ChatModel and AgentConfigurator, and modify the public constructor to delegate to it with default values.

    2. In AgenticServices.java: Update createAgenticSystem and createBuiltInAgentExecutor to use the new constructor instead of calling configureAgent separately.

    Let me also add the necessary import for AgenticServices in AgentBuilder.java:

  23. Qwen Assistant

    I need to add the import for AgenticServices. Let me make the changes:

  24. Qwen Assistant

    Good, the import was added. Now let me update the constructor. Let me first check the current state of the constructor:

  25. Qwen Assistant

    The constructor is at lines 132-159. I need to:

    1. Replace the public constructor to delegate to a new package-private constructor
    2. Add the new package-private constructor that takes ChatModel and AgentConfigurator
  26. Qwen Assistant

    The AgentBuilder.java file has been updated. Now I need to update AgenticServices.java to use the new constructor and remove the redundant configureAgent calls.

    Let me check the current state of createAgenticSystem and createBuiltInAgentExecutor:

  27. Qwen Assistant

    Now I need to update AgenticServices.java to use the new constructor. I need to change:

    1. Line 337-338: Use the new constructor instead of calling configureAgent separately
    2. Line 597-598: Same change for createBuiltInAgentExecutor

    First, let me also check if the agentBuilder method needs to be updated:

  28. Qwen Assistant

    I need to add an overloaded agentBuilder method that accepts chatModel and agentConfigurator, or I can modify the code directly in createAgenticSystem to create the AgentBuilder with the new constructor.

    Let me update AgenticServices.java:

  29. Qwen Assistant

    Now I need to update createAgenticSystem to use the new constructor. Let me find the exact lines:

  30. Qwen Assistant

    Now I'll replace these lines to use the new constructor:

  31. Qwen Assistant

    I see there's a duplicate closing brace at line 339. Let me fix that:

  32. Qwen Assistant

    Good, that fixed the createAgenticSystem method. Now I need to also update the createBuiltInAgentExecutor method. Let me find it:

  33. Qwen Assistant

    Now I need to check if there are any unused imports in AgenticServices.java. Since we removed the configureAgent call from the main code path, I should check if the import is still needed:

  34. Qwen Assistant

    The configureAgent import is no longer used in AgenticServices.java, so I should remove it. Let me do that.

  35. Qwen Assistant

    Now let me verify the changes are correct by viewing the key parts of both files:

  36. Qwen Assistant

    Now let me check the DeclarativeUtil.java to verify the configureAgent method that handles allowNullChatModel:

  37. Qwen Assistant

    I see an issue. When the public AgentBuilder constructor is used (which now delegates to the new constructor with null chatModel), it calls configureAgent(agentServiceClass, null, this, agentConfigurator). Looking at the configureAgent method in DeclarativeUtil, the version with 4 parameters calls configureAgent(agentType, chatModel, false, agentBuilder, agentConfigurator) which passes allowNullChatModel=false.

    This means when the public constructor is used (without a chat model), it would fail if no chat model is provided via @ChatModelSupplier. But the original code used configureAgent(agentType, agentBuilder) which called with allowNullChatModel=true.

    I need to fix the public constructor to use the original behavior with allowNullChatModel=true:

  38. Qwen Assistant

    I need to fix the public constructor to use the original behavior. The public constructor should call configureAgent(agentServiceClass, this) which allows null chat model, while the new constructor calls configureAgent(agentServiceClass, chatModel, this, agentConfigurator) which doesn't allow null.

  39. Qwen Assistant

    I need to fix the public constructor to call the original configureAgent(agentServiceClass, this) which allows null chat model:

  40. Qwen Assistant

    Now I have both constructors:

    1. The public constructor that calls configureAgent(agentServiceClass, this) - allows null chat model
    2. The package-private constructor that calls configureAgent(agentServiceClass, chatModel, this, agentConfigurator) - requires chat model

    Now let me try to compile the code to verify the changes are correct:

  41. Qwen Assistant

    I need to fix the type inference issue. The compiler cannot infer the type arguments. Let me update the code to explicitly specify the type:

  42. Qwen Assistant

    The issue is that var can't infer the type when there are multiple constructors with different signatures. Let me explicitly specify the type parameter:

  43. Qwen Assistant

    I need to fix the type inference issue by replacing var with explicit type. Let me use the replace command:

  44. Qwen Assistant

    continue

  45. Qwen Assistant

    Now I can see line 335. Let me replace it:

  46. Qwen Assistant

    Now I need to fix the @SuppressWarnings annotation - it can't be placed like that inside an if block. Let me fix this properly:

  47. Qwen Assistant

    Now I need to add a helper method createAgentBuilder with the @SuppressWarnings annotation. Let me find a good place to add it:

  48. Qwen Assistant

    Let me add the helper method before declarativeChatModel:

  49. Qwen Assistant

    I see the replace didn't work as expected - line 335-336 still has the old code. Let me check again:

  50. Qwen Assistant

    The replace command didn't work because the search text didn't match exactly (there was whitespace difference). Let me try again:

  51. Qwen Assistant

    continue

    Let me verify the change and then add the helper method:

  52. Qwen Assistant

    The replace didn't work. Let me try a different approach - directly edit the specific lines:

  53. Qwen Assistant

    Now I need to add the helper method createAgentBuilder. Let me add it before declarativeChatModel:

  54. Qwen Assistant

    I see there's a missing blank line before private static <T> ChatModel declarativeChatModel. Let me fix that:

  55. Qwen Assistant

    Now I also need to update the createSubagent method that also has the same issue. Let me find it:

  56. Qwen Assistant

    I see line 602 still uses new AgentBuilder<>(subgentClass, chatModel, agentConfigurator). Let me check if this compiles:

  57. Qwen Assistant

    The compilation errors show that lines 351 and 602 have type inference issues. Let me fix both of them. Line 351 is in the createAgentBuilder helper method, and line 602 is in createSubagent. I need to explicitly specify the type parameters.

  58. Qwen Assistant

    The issue is that the new AgentBuilder<>(...) call cannot infer the type parameters when there are multiple constructors. I need to explicitly specify the type parameter T for the first type argument.

    Let me fix line 351 by specifying the type explicitly: return new AgentBuilder<T>(agentServiceClass, chatModel, agentConfigurator);

    And for line 602, I need to use @SuppressWarnings("unchecked") and cast appropriately.

  59. Qwen Assistant

    I see the indentation was lost. Let me fix that and also fix line 602:

  60. Qwen Assistant

    The previous command didn't work properly. Let me navigate to line 602 and fix it.

  61. Qwen Assistant

    I see the issue. Line 602 has Class<?> so we can't use a type parameter. Let me fix it by using Object as the type parameter with @SuppressWarnings:

  62. Qwen Assistant

    The previous command seemed to have worked but the response was not properly formatted. Let me now try to compile to see if there are any remaining issues.

  63. Qwen Assistant

    I see - AgentBuilder has 2 type parameters <T, B extends AgentBuilder<T, ?>>. I need to provide both or use raw types with proper casting. Let me fix this by using raw types with explicit casts.

  64. Qwen Assistant

    Now let me fix line 602 with the same pattern:

  65. Qwen Assistant

    The @SuppressWarnings annotation on line 602 doesn't work as a local variable annotation in this position. Let me try to compile and see what happens.

  66. Qwen Assistant

    I see the issue - the AgentBuilder constructor with 3 parameters is package-private, but AgenticServices is in a different package (dev.langchain4j.agentic vs dev.langchain4j.agentic.agent). I need to make the constructor public.

  67. Qwen Assistant

    I need to make the 3-parameter constructor public so it can be accessed from AgenticServices which is in a different package. Let me find and update it:

  68. Qwen Assistant

    I need to make the 3-parameter constructor public. Let me update line 161:

  69. Qwen Assistant

    Now let me try to compile again:

  70. Qwen Assistant

    The compilation succeeded. Now let me verify my changes by running the existing tests to make sure nothing is broken.

  71. Qwen Assistant

    The tests passed. Let me verify by checking if there were any test failures.

  72. Qwen Assistant

    All 45 tests passed. Let me also review the changes I made to ensure they are correct and summarize them:

  73. Qwen Assistant

    The previous command was executed successfully. Let me continue by reviewing the git diff to understand the changes made.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.