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:
Assistant
Now let's implement the change:
Assistant
I'll use the
replacespecial command instead.Assistant
Now let's update
AgenticServices.javato use the new constructor overload for the two problematic call sites.Assistant
Now let's fix
createSubagent:Assistant
Good, only these two call sites in AgenticServices.java needed the fix, and both are now updated. Now let's compile the module to make sure everything builds correctly.
Assistant
Network is available. Let's try building without offline mode.
Assistant
Now let's rebuild.
Assistant
Compiles successfully. Now let's write a reproduction test to confirm the fix resolves the duplicate tool issue, using a mocked ChatModel to avoid needing a real LLM endpoint.
Assistant
Great, this is exactly the pattern to reuse for a reproduction test. Let's write a temp test that mimics the reported issue with a dummy chat model and a fixed ToolProvider.
Assistant
Test passes. Let's confirm it would have failed before the fix by reverting temporarily and re-running.
Assistant
Good, the fix changes are stashed but the test file remains. Now let's run the test against the original (buggy) code to confirm it reproduces the issue.
Assistant
Confirmed: the reproduction test fails with the exact reported error on the unfixed code. Now let's restore the fix.
Assistant
Now let's rerun the whole existing test suite for langchain4j-agentic module (excluding integration tests requiring API keys) to make sure nothing broke.
Assistant
Now let's double-check other modules that depend on
langchain4j-agentic(e.g.,langchain4j-agentic-a2a,langchain4j-agentic-mcp,langchain4j-agentic-patterns,langchain4j-skills) still compile with the modifiedAgentBuilderconstructor.Assistant
All dependent modules compile fine. Let's also run their tests quickly to be safe (excluding IT tests, which are skipped by default anyway).
Assistant
All builds succeed. Now let's review the final diff.
Assistant
This is a minimal, targeted fix. Let's also verify
git statusis clean of the temp test file, and do a final full compile of the whole repository's relevant modules to be extra safe.Assistant
Clean. Now let me go through the checklist explicitly.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.