Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging 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. GLM Assistant

    Let me explore the repository structure and understand the issue.

  3. GLM Assistant

    Now let me look at the configureAgent method and the agentBuilder to understand how tools are registered.

  4. GLM Assistant

    Now let me look at the agentBuilder method and the AgentBuilder class to understand how tools/toolProviders are aggregated.

  5. GLM Assistant

    Now let me look at the AgentBuilder class to understand how toolProvider and tools are aggregated.

  6. GLM Assistant

    Now let me find the Skills class to understand how activate_skill is added.

  7. GLM Assistant

    So the Skills toolProvider() returns a single dynamic ToolProvider. Let me understand how the duplicate activate_skill registration happens. The issue says "caused by multiple registrations of non-dynamic ToolProvider instances." Let me look at how the ToolService handles dynamic vs non-dynamic tool providers.

    Let me look at the ToolService.addTools and createContextFromStaticToolsAndProviders.

  8. GLM Assistant

    Let me look at how the Skills toolProvider is created and whether it's dynamic.

  9. GLM Assistant

    Now I understand the issue. Let me look at how configureAgent is being called twice. The AgentBuilder constructor calls configureAgent(agentServiceClass, this), and then createAgenticSystem calls configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator) again. Let me verify all callers of configureAgent.

  10. GLM Assistant

    Let me check the git history to understand the design intent.

  11. GLM Assistant

    Let me write a reproduction test first to confirm the issue. Let me check the test infrastructure for the agentic module.

  12. GLM Assistant

    Let me look at the declarative test patterns to understand how to write a reproduction test that doesn't need a real LLM.

  13. GLM Assistant

    Let me look at the Agents.CreativeWriter to understand the declarative single-agent pattern with @ToolProviderSupplier or @ToolsSupplier.

  14. GLM Assistant

    Let me look at DefaultAiServices to understand when createContext is called relative to the model.

  15. GLM Assistant

    The createContext is called before the model. So I can reproduce with a stub ChatModel. Let me check the ChatModel interface to create a minimal stub.

  16. GLM Assistant

    There's a throwingModel() helper. Now let me create a reproduction test that doesn't require a real LLM. Let me write it as a temporary test.

  17. GLM Assistant

    I've reproduced the issue. The error is Duplicated definition for tool: activate_skill. Now let me confirm the root cause — configureAgent is called twice. Let me check the 2-arg public configureAgent callers and understand the double-call.

  18. GLM Assistant

    Let me also check the public 2-arg configureAgent is used elsewhere (maybe in other modules or tests).

  19. GLM Assistant

    Let me check whether any standalone agentBuilder(cls).build() usage relies on the constructor's auto-configuration picking up declarative suppliers.

  20. GLM Assistant

    Let me check the WorkflowAgentsIT and the agent classes to see if standalone usage relies on declarative suppliers picked up by the constructor.

  21. GLM Assistant

    Here AgenticServices.agentBuilder(CreativeWriterWithModel.class).outputKey("story").build() — the CreativeWriterWithModel likely has a @ChatModelSupplier. Let me check.

  22. GLM Assistant

    I confirmed standalone usage (CreativeWriterWithModel) relies on the constructor's auto-config picking up @ChatModelSupplier. So the constructor must keep auto-configuring. The fix is to make the override path (in createAgenticSystem and createSubagent) NOT re-run the full configureAgent, only applying the chat-model fallback and configurator. Let me check UntypedAgentBuilder for the same pattern first.

  23. GLM Assistant

    UntypedAgentBuilder extends AgentBuilder, so it inherits the constructor behavior. Now let me implement the fix. First, let me add a helper method to DeclarativeUtil that applies only the chat-model fallback and configurator (without re-registering declarative suppliers).

  24. GLM Assistant

    Now let me open DeclarativeUtil and add the helper method after the configureAgent methods.

  25. GLM Assistant

    Now let me add the new helper method after the private configureAgent method.

  26. GLM Assistant

    Now let me add the new helper method after line 149 (the closing brace of the private configureAgent).

  27. GLM Assistant

    Now let me verify the AgentBuilder import is present in DeclarativeUtil.

  28. GLM Assistant

    Now let me update AgenticServices.java to use the new helper in both the override paths. First, update the import.

  29. GLM Assistant

    Now let me update the two override call sites. First, the createAgenticSystem fallback path (line 338).

  30. GLM Assistant

    I need to navigate to the line first, or use the --file option. Let me use the goto command then edit. Actually, the edit command edits the currently open file. The current file is AgenticServices.java. The issue is that the text isn't in "displayed lines". Let me goto line 338 first.

  31. GLM Assistant

    Now let me update the createSubagent override path (line ~599).

  32. GLM Assistant

    Now configureAgent is no longer used in AgenticServices. Let me check if the import is still needed.

  33. GLM Assistant

    Let me check whether the public 4-arg configureAgent is still used anywhere now.

  34. GLM Assistant

    The public 4-arg configureAgent is now only referenced in my javadoc. I'll keep it for backward compatibility (it's public API). Let me remove the now-unused import in AgenticServices.

  35. GLM Assistant

    My edit created a duplicate invokeStatic import. Let me fix lines 5-7.

  36. GLM Assistant

    There's now a duplicate checkReturnType import. Let me rewrite the import block cleanly.

  37. GLM Assistant

    Imports are clean now. Let me compile the module to verify there are no errors.

  38. GLM Assistant

    Compilation succeeds. Now let me run the reproduction test.

  39. GLM Assistant

    The duplicate tool error is gone. Now the error is the expected RuntimeException: ERROR from my throwingModel() — meaning createContext succeeded (no duplicate) and it proceeded to call the model. The fix works.

    Let me write a more comprehensive reproduction that mimics the actual issue using the real Skills API and verifies the configurator and chat-model fallback paths. First, let me check if langchain4j-agentic depends on langchain4j-skills.

  40. GLM Assistant

    langchain4j-agentic doesn't depend on langchain4j-skills, so my non-dynamic ToolProvider repro is equivalent. Let me write a more comprehensive reproduction using a fake ChatModel that returns a real response, to verify the configurator, chat-model fallback, and composed-agent paths. Let me check existing fake model helpers.

  41. GLM Assistant

    Let me check the AgentConfigurator API to build a comprehensive test.

  42. GLM Assistant

    Now let me write a comprehensive reproduction test that verifies multiple paths: single agent, configurator application, chat-model fallback, and composed sequence with a subagent using @ToolProviderSupplier.

  43. GLM Assistant

    Let me fix the configurator test — I referenced a non-existent overload. Let me rewrite the test file cleanly.

  44. GLM Assistant

    Let me check the test result summary explicitly.

  45. GLM Assistant

    All 5 tests pass, including the exact issue scenario. Now let me make sure I didn't break existing tests. Let me identify non-gated unit tests in the agentic module and run them.

  46. GLM Assistant

    Let me run the full test suite offline — gated IT tests will be skipped, and unit tests will run to confirm nothing breaks.

  47. GLM Assistant

    All 45 tests pass with BUILD SUCCESS. Let me also check if other agentic modules use the changed APIs, to ensure broader safety.

  48. GLM Assistant

    All 45 tests pass. My fix preserves backward compatibility (the public configureAgent methods remain). Now let me remove the temporary reproduction test before submitting, as required.

  49. GLM Assistant

    Removed. Let me verify the final state of my changes with git diff.

  50. GLM Assistant

    The diff is clean. Let me do a final compile and test run to confirm everything works after removing the repro test.

  51. GLM Assistant

    All 45 existing tests pass (BUILD SUCCESS). Note: my repro test wasn't picked up by the default mvn test suite because it lacked a *Test/*IT suffix — that's why the count stayed 45; it's now removed anyway.

    Let me verify the standalone path (no model) still throws appropriately via validateChatModel, to ensure no regression there.

  52. GLM Assistant

    Everything checks out. The standalone path behavior is unchanged (the constructor still auto-configures and validateChatModel still guards standalone usage).

    Let me do a final review of the complete change set.

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