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 to understand the codebase and find the relevant files.
Assistant
Let me start by finding the relevant file.
Assistant
Let me search for the
createAgenticSystemmethod.Assistant
Let me look at the
agentBuildermethod and theconfigureAgentrelated code.Assistant
Now let me look at the
configureAgentmethod in DeclarativeUtil, and the AgentBuilder class to understand how tools are registered.Assistant
I need to make only one tool call at a time. Let me find both files.
Assistant
Now let me look at the AgentBuilder class to understand how
toolProviderandtoolswork.Assistant
Now let me look at the Skills class and the
activate_skilltool to understand how it's added.Assistant
Now let me look at the ToolService class that throws the error.
Assistant
Let me look at the
createComposedAgentmethod more closely.Assistant
I can see the issue now. Let me verify by looking at the
AgentBuilderconstructor again, which callsconfigureAgentinternally.Assistant
I've found the root cause. The
AgentBuilderconstructor (line 141) callsconfigureAgent(agentServiceClass, this)which adds tool providers, and thencreateAgenticSystem(line 338) callsconfigureAgentAGAIN, re-adding the same tool providers. Let me look at howconfigureAgentis used elsewhere to understand the design intent.Assistant
Let me look at line 590-605 in AgenticServices.java.
Assistant
Let me reproduce the issue first. Let me look at the existing tests related to skills and agentic systems.
Assistant
Let me look at the SingleAgentIT test to understand how single agents are tested.
Assistant
Let me search for tests that use
createAgenticSystemwithToolProviderSupplier.Assistant
Let me look at the DeclarativeAgentIT test.
Assistant
Let me look at the
CreativeWriteragent in theAgents.javafile.Assistant
Let me look for
ToolsSupplierusage in tests.Assistant
Let me check the
listenermethod in AgentBuilder to see if it appends or assigns.Assistant
Let me check all usages of the 4-arg
configureAgentand the 2-arg version across the codebase.Assistant
Let me look for existing unit tests (non-integration) that use fake/mock chat models in the agentic package.
Assistant
Let me look for existing fake/stub chat models I can use for reproduction.
Assistant
Let me check the build system and whether the agentic module can be built/tested independently.
Assistant
Let me look at a simple fake ChatModel implementation to use for reproduction.
Assistant
Now let me create a reproduction test to confirm the issue. Let me create a temporary test file.
Assistant
Let me fix the imports in the test file.
Assistant
Now let me run this test to confirm the issue.
Assistant
I've reproduced the issue. The error confirms the duplicate
activate_skilltool registration.Now let me understand the root cause clearly and look at the full
configureAgentmethod to plan the fix.Assistant
I now fully understand the root cause. The
AgentBuilderconstructor callsconfigureAgent(2-arg version) which applies ALL declarative suppliers (includingToolProviderSupplierwhich appends to a list). ThencreateAgenticSystem/createSubagentcall the 4-argconfigureAgentwhich re-runs ALL suppliers, adding the tool provider a second time, causing the duplicateactivate_skillregistration.Let me implement the fix. The 4-arg
configureAgent(always called after the constructor) should NOT re-run the declarative suppliers; it should only resolve the fallback chat model and apply the configurator.Assistant
Now let me add the
resolveFallbackChatModelhelper method after the privateconfigureAgentmethod ends. Let me view the end of the private method.Assistant
Now let me add the
resolveFallbackChatModelhelper method right after the privateconfigureAgentmethod ends (after line 158).Assistant
I see the closing brace of the
configureAgentmethod was removed. Let me fix that.Assistant
The structure looks correct now. Let me run the reproduction test to confirm the fix works.
Assistant
The test no longer throws the error. Let me verify the test passed explicitly.
Assistant
The fix works. Now let me run the existing unit tests in the agentic module to make sure I haven't broken anything.
Assistant
All unit tests pass. Let me also run the skills module tests to make sure the Skills tool provider behavior is intact.
Assistant
Let me add a more targeted edge-case test that directly inspects the
toolProviderslist via reflection to verify deduplication for both the single-agent path and the subagent path (which also calls the 4-argconfigureAgent).Assistant
All 3 tests pass. Let me also add a test for the case where there's NO chat model supplier (so the fallback chat model is applied), to ensure that path still works correctly.
Assistant
Let me update the test file to add an agent without a
ChatModelSupplierto test the fallback path.Assistant
All tests pass, including the fallback chat model path. Now I need to remove my temporary reproduction test file since the instructions say not to add new tests to the repository.
Assistant
The temporary test is removed. Let me run the full agentic unit test suite once more to confirm everything passes after removing the temp test.
Assistant
All tests pass. Let me verify the imports in DeclarativeUtil are complete (especially
StreamingChatModelSupplierused in the new method).Assistant
The grep returned non-zero exit (no matches) because the imports might not have explicit import statements (they're in the same package
dev.langchain4j.agentic.declarative). Let me check the package of these supplier annotations.Assistant
The annotations are in the same package, so no imports needed. The code compiles successfully (tests passed). Let me review the complete diff of my changes.
Assistant
The diff looks clean and focused. Let me verify there are no other stray files left from my testing.
Assistant
Only the one source file is modified, and the temporary test files are cleaned up. Let me do a final compile check of the main source to be safe.
Assistant
The main source compiles cleanly. Let me do a final review of the complete fix to ensure correctness.
Let me verify the final state of the modified method:
Assistant
The fix is complete and correct. Let me run one final comprehensive check across both affected modules to be fully confident.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.