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
codeCaused 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
java Assistant
Good, so no existing test uses ToolProviderSupplier with createAgenticSystem. Let's write a reproduction script.
Assistant
Good, this happens before actual network call, but after model resolution etc. So reproduction should be feasible even without a real chat model as long as we can call the proxy method and it throws before hitting network. Let's write a reproduction script/test using JUnit within the module using a simple ToolProvider similar to SingleAgentIT.
Assistant
Now let's find the classpath to compile and run this against the repo's built classes.
Assistant
Network available. Let's try compiling without offline mode.
Assistant
Compiled successfully. Now let's also compile langchain4j-agentic test classes and try running our reproduction script using its classpath.
Assistant
Reproduced the exact issue. Now let's implement the fix. The core issue is that
configureAgentgets called twice on the sameAgentBuilderinstance—once in the constructor and once explicitly. Let's fix this by adding a guard flag to prevent double-processing of the declarative suppliers, while still allowing chatModel fallback logic andagentConfiguratorto run properly.Assistant
Now let's implement the fix by wrapping lines 55-101 and 142-146 within
if (allowNullChatModel)blocks (i.e., only run during the initial construction-time configuration pass).Assistant
I'll use the
editcommand directly on the open file instead.Assistant
Now let's replace lines 54-101 with the guarded version.
Assistant
Good. Now let's find and update the AgentListenerSupplier block further down.
Assistant
Now let's recompile and rerun the reproduction script.
Assistant
The duplicate tool error is gone — the flow now proceeds all the way to actually invoking the (fake) chat model. Now let's run the existing test suite for the agentic module to make sure nothing broke.
Assistant
All non-IT tests pass. Now let's also check the IT tests (which require env vars, so they'll be skipped, but let's confirm they at least compile and are correctly skipped rather than failing).
Assistant
Good, test sources compile fine. Let's also run the full test suite (including ITs, which will mostly skip due to missing env vars) to be thorough, and check for any surprises.
Assistant
subAgents is just Class<?>[]. Let me fix Repro2.java.
Assistant
Sub-agent path (
createSubagent) also works correctly now, with exactly 1 tool spec (no duplicate). Let's now verify the AgentConfigurator is still properly applied on the second call by testing with a configurator that adds something.Assistant
AgentConfigurator still works fine. Now let's clean up the temporary reproduction files and do a final review of the diff.
Assistant
This is a clean, minimal, and targeted fix. Let's do a final full build/test run of the module to be extra sure.
Assistant
All 45 tests pass. Let's also verify related modules that depend on
langchain4j-agentic(likelangchain4j-agentic-mcp,langchain4j-agentic-a2a,langchain4j-agentic-patterns) still compile fine since they might useAgentBuilder/DeclarativeUtilinternals.Assistant
All good. Let's clean up any leftover temp files and view the final diff once more.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.