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 check all places where
agentBuilder(agentServiceClass)oragentBuilder(subgentClass)is used before an explicitconfigureAgentcall (indicating the double-invocation bug), to fix them all consistently.Assistant
Now let's implement the fix. I'll add an internal constructor overload with an
autoConfigureflag and a package-visible static factory that AgenticServices can use via@Internal.Assistant
Now let's add the
Internalimport and modify the constructor to add the internal factory.Assistant
I'll use the
replacespecial command instead.Assistant
No hidden chars. Let's try goto and edit by line range directly instead.
Assistant
Now I'll use
editwith the line range directly.Assistant
Now let's update
AgenticServices.javato use the new constructor at the two problematic sites (lines ~337 and ~597, but line numbers shifted now since we only edited AgentBuilder.java, so AgenticServices.java line numbers are unchanged).Assistant
Now let's fix the other occurrence around line 597 (createSubagent).
Assistant
Good, those are the only two, and both are now fixed. Let's check other builder types (SequentialAgentServiceImpl, LoopAgentServiceImpl etc.) that may extend AgentBuilder and might have a similar double-config issue - since they build sub-agents via
createSubagentwhich we just fixed.Assistant
Good, all covered. Now let's build the project to verify compilation.
Assistant
Right,
@Internaldoesn't target constructors. I'll just remove the annotation and keep the doc comment noting it's for internal use.Assistant
Now let's remove the unused Internal import too (since it's no longer used).
Assistant
Now let's recompile.
Assistant
Compiles successfully. Now let's write a reproduction test to confirm the fix, using a mock ChatModel (avoiding network calls) similar to the issue's
Skillsusage.Assistant
Now let's write the reproduction test file inside the agentic test source, run it, then remove it after confirming.
Assistant
Let's fix the imports in the repro test.
Assistant
Uses a builder. Let's fix the test.
Assistant
Compiles. Now let's first confirm the bug exists by testing against the unfixed code (stash changes), then re-apply and confirm the fix.
Assistant
The test passes now with our fix. Let's confirm the bug existed before the fix by temporarily reverting the change and re-running.
Assistant
Reproduced exactly the reported error. Now let's restore our fix.
Assistant
Fix confirmed. Now let's run the full existing test suite for the
langchain4j-agenticmodule (excluding IT tests that need real network/API keys) to ensure nothing else broke.Assistant
All unit tests (default
testgoal, which by default excludes*IT.java) passed with no errors shown. Let's confirm test count/build success explicitly.Assistant
All pass. Now let's remove the temporary repro test file, then run tests once more to ensure everything is still fine.
Assistant
Now let's also check other modules that depend on
AgentBuilder(e.g.langchain4j-agentic-mcp,langchain4j-agentic-a2a,langchain4j-agentic-patterns) to make sure nothing else calls the constructor in a way affected by this change, and also double check the full diff.Assistant
That's just a docstring reference, not actual usage. Let's compile these other modules too to be safe.
Assistant
All good. Let's view the final diff.
Assistant
This looks clean and minimal. Let's also check
git statusto ensure no stray files remain.Assistant
Clean. Let's run the full
langchain4j-agentictest suite one final time to make sure everything is stable, and also do a broader sanity build of the whole reactor for modules touching AgentBuilder.Assistant
All tests across the reactor pass, and the overall build succeeded. Let's finalize by reviewing the diff one more time.
Assistant
This is a clean, minimal, and well-targeted fix. Let's go through the checklist:
Assistant
Checklist Review
-
[x] If an error was reported in the issue description, I have successfully reproduced it. I wrote a temporary reproduction test () mirroring the issue's example (a single method with a returning a non-dynamic that exposes an tool, and a ). Running it against the original code reproduced the exact stack trace from the issue (confirmed via to temporarily revert my fix).
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.