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
Let me start by exploring the repository structure and understanding the codebase.
Assistant
Let me look at how tools are registered. Let me search for
ToolProviderSupplierand how tools are added to the agent builder.Assistant
Now let me look at the Skills system and how
activate_skillis added.Assistant
So
Skills.toolProvider()is a dynamic ToolProvider. Let me checkisDynamic. Let me look at the createToolProvider.Assistant
Now let me look at how
configureAgentis called in AgenticServices and whether tools/toolProviders are added multiple times.Assistant
Let me look at the rest of
configureAgentin DeclarativeUtil, especially how the agentConfigurator is applied.Assistant
Let me look at the AgentBuilder.build() method to see how toolProviders are processed.
Assistant
Let me look at the AgentBuilder.build() method.
Assistant
Let me look at the ToolService to understand the duplicate detection.
Assistant
Let me look at the
agentBuildermethod in AgenticServices.Assistant
Let me look at the AgentBuilder constructor to see what it does by default.
Assistant
Let me look at how subagents are configured (line 598 area) and compare.
Assistant
I found the root cause. The
AgentBuilderconstructor callsconfigureAgent(agentServiceClass, this)(line ~144), and thencreateAgenticSystemcallsconfigureAgent(...)AGAIN (line 338), causing tools/toolProviders to be registered twice. Let me verify the constructor call and check git history.Assistant
Let me look at the full
addToolsmethod and surrounding context in ToolService.Assistant
Let me check existing tests around duplicate tool detection.
Assistant
No tests check the "Duplicated definition" exception directly. Let me look at how the duplicate detection is used elsewhere — maybe there are tests in the agentic module.
Assistant
Assistant
Let me look at existing agentic tests to understand the test setup and how to reproduce.
Assistant
These IT tests require API keys. Let me find a non-IT test (unit test) that uses a mock model with createAgenticSystem.
Assistant
Let me look at
ChatSupplierParameterResolverTestwhich is a non-IT test using createAgenticSystem, to understand how to mock the model.Assistant
Let me check the build system and whether I can compile the agentic module with skills dependency.
Assistant
The agentic module doesn't depend on skills, but the bug occurs with ANY non-dynamic ToolProvider since
configureAgentis called twice. Let me create a reproducer test.Assistant
I've reproduced the bug. Now let me examine the tools/toolProvider setter methods in AgentBuilder to understand which ones append vs overwrite.
Assistant
The duplicate comes specifically from
toolProvider/toolProvidersappending to a list (whiletoolsoverwrite). Let me check what tests exist for ToolService / addTools to see if any rely on the throw behavior.Assistant
Let me check the
ToolProviderinterface defaultisDynamicand understand that test.Assistant
Let me check which AgentBuilder setters append vs overwrite (contentRetriever, retrievalAugmentor, chatMemory, chatMemoryProvider, listener).
Assistant
Let me check where
buildAgentFeaturesis called and whether the listener is processed multiple times.Assistant
Let me look at the full chatModel handling block in configureAgent to understand the structure.
Assistant
Let me search for all callers of
configureAgent(the full and simple overloads) to understand usage.Assistant
I now understand the structure well. Let me check the imports and the agentConfigurator application line in DeclarativeUtil.
Assistant
Now let me look at the end of the private configureAgent (the agentConfigurator application) and the lines 137-142.
Assistant
I now have a complete understanding. Let me view the exact lines to replace (the two public overloads + private method, lines 46-142).
Assistant
Let me get the exact line numbers of the block to replace.
Assistant
So the block to replace is lines 46-149 (the two public overloads + private method, ending at the agentConfigurator line + the closing). Let me check line 149.
Assistant
Now let me open the file and replace the block (lines 46-149) with the fixed version.
Assistant
Now I'll replace lines 46-149 with the fixed version that prevents double registration of suppliers while still resolving the chat model and applying the configurator.
Assistant
Now let me apply the replacement using Python for precision.
Assistant
No python3. Let me use the
editcommand with heredoc.Assistant
Let me re-confirm the line numbers. Let me re-grep.
Assistant
Now let me apply the edit replacing lines 46-149 with the fixed version.
Assistant
Let me view the rest of the
resolveChatModelmethod to verify.Assistant
The fix looks good. Now let me compile and run the reproducer test.
Assistant
The reproducer passes now. Let me expand the test to cover edge cases: the standalone
agentBuilder().build()path, a composed (sequence) agent with subagents using@ToolProviderSupplier, and the explicit-ChatModel fallback (no supplier).Assistant
3 of 4 pass. The sequence test fails on the assertion (returns
nullinstead of "ok") but crucially does NOT throw the duplicate error — so the subagent path is fixed. Thenullis a test-setup issue with how sequence agents map output. Let me check how declarative sequence agents return values.Assistant
Let me check the
SequenceAgentannotation fields to understand output mapping for my test.Assistant
The sequence test correctly runs without the duplicate error (the
nullis just output-mapping setup). Let me adjust that test to assert no-throw instead of the value, since its purpose is to verify the subagent dedup path.Assistant
I need to add the
assertThatCodeimport.Assistant
All 4 tests pass. Now let me run the existing non-IT unit tests in the agentic module to ensure I didn't break anything.
Assistant
All non-IT agentic tests pass. Now let me also run the core langchain4j tool tests to be safe (I didn't change core, but verifying nothing is indirectly affected), then clean up the temporary test.
Assistant
Let me review the full diff of DeclarativeUtil.java to confirm correctness.
Assistant
The diff is clean and correct. Now let me remove the temporary test file before submitting.
Assistant
Only DeclarativeUtil.java is modified. Let me do a final compile check to ensure everything is still good.
Assistant
The fix compiles cleanly. Let me run the agentic non-IT tests one more time to confirm nothing regressed after removing the temp test.
Assistant
All tests pass. Let me verify the final state of changes before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.