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:
- LangChain4j version: latest agentic snapshot
- LLM(s) used: Qwen 3.6 (via OpenAiChatModel)
- Java version: 25
- Spring Boot version (if applicable): N/A
Additional context The bug is caused by
createAgenticSystemregistering non-dynamicToolProviderinstances multiple times. Theactivate_skilltool is automatically added for everySkillProviderinstance, leading to duplicate registration even with a single agent.Interface
Type: Function Name: createAgenticSystem Path: langchain4j-agentic/src/main/java/dev/langchain4j/agentic/AgenticServices.java Input: Class agentServiceClass, AgentConfigurator agentConfigurator Output: T (the created agentic system instance of the requested type) Description: Creates an agentic system from a declarative agent service class, applying the provided configurator to each agent. This overload resolves the default chat model from the agent class and deduplicates tool registrations across the system.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /langchain4j, current file: none) bash-$
Assistant
Let me explore the repository structure and understand the issue.
Assistant
Now let me look at the
configureAgentmethod and theagentBuilderto understand how tools are registered.Assistant
Now let me look at the
agentBuildermethod and theAgentBuilderclass to understand how tools/toolProviders are aggregated.Assistant
Now let me look at the AgentBuilder class to understand how
toolProviderandtoolsare aggregated.Assistant
Now let me find the
Skillsclass to understand howactivate_skillis added.Assistant
So the Skills
toolProvider()returns a single dynamicToolProvider. Let me understand how the duplicateactivate_skillregistration happens. The issue says "caused by multiple registrations of non-dynamicToolProviderinstances." Let me look at how the ToolService handles dynamic vs non-dynamic tool providers.Let me look at the ToolService.addTools and createContextFromStaticToolsAndProviders.
Assistant
Let me look at how the Skills toolProvider is created and whether it's dynamic.
Assistant
Now I understand the issue. Let me look at how
configureAgentis being called twice. TheAgentBuilderconstructor callsconfigureAgent(agentServiceClass, this), and thencreateAgenticSystemcallsconfigureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator)again. Let me verify all callers ofconfigureAgent.Assistant
Let me check the git history to understand the design intent.
Assistant
Let me write a reproduction test first to confirm the issue. Let me check the test infrastructure for the agentic module.
Assistant
Let me look at the declarative test patterns to understand how to write a reproduction test that doesn't need a real LLM.
Assistant
Let me look at the Agents.CreativeWriter to understand the declarative single-agent pattern with
@ToolProviderSupplieror@ToolsSupplier.Assistant
Let me look at DefaultAiServices to understand when createContext is called relative to the model.
Assistant
The
createContextis called before the model. So I can reproduce with a stub ChatModel. Let me check the ChatModel interface to create a minimal stub.Assistant
There's a
throwingModel()helper. Now let me create a reproduction test that doesn't require a real LLM. Let me write it as a temporary test.Assistant
I've reproduced the issue. The error is
Duplicated definition for tool: activate_skill. Now let me confirm the root cause —configureAgentis called twice. Let me check the 2-arg publicconfigureAgentcallers and understand the double-call.Assistant
Let me also check the public 2-arg
configureAgentis used elsewhere (maybe in other modules or tests).Assistant
Let me check whether any standalone
agentBuilder(cls).build()usage relies on the constructor's auto-configuration picking up declarative suppliers.Assistant
Let me check the WorkflowAgentsIT and the agent classes to see if standalone usage relies on declarative suppliers picked up by the constructor.
Assistant
Here
AgenticServices.agentBuilder(CreativeWriterWithModel.class).outputKey("story").build()— theCreativeWriterWithModellikely has a@ChatModelSupplier. Let me check.Assistant
I confirmed standalone usage (
CreativeWriterWithModel) relies on the constructor's auto-config picking up@ChatModelSupplier. So the constructor must keep auto-configuring. The fix is to make the override path (increateAgenticSystemandcreateSubagent) NOT re-run the fullconfigureAgent, only applying the chat-model fallback and configurator. Let me checkUntypedAgentBuilderfor the same pattern first.Assistant
UntypedAgentBuilder extends AgentBuilder, so it inherits the constructor behavior. Now let me implement the fix. First, let me add a helper method toDeclarativeUtilthat applies only the chat-model fallback and configurator (without re-registering declarative suppliers).Assistant
Now let me open DeclarativeUtil and add the helper method after the
configureAgentmethods.Assistant
Now let me add the new helper method after the private
configureAgentmethod.Assistant
Now let me add the new helper method after line 149 (the closing brace of the private
configureAgent).Assistant
Now let me verify the
AgentBuilderimport is present in DeclarativeUtil.Assistant
Now let me update
AgenticServices.javato use the new helper in both the override paths. First, update the import.Assistant
Now let me update the two override call sites. First, the
createAgenticSystemfallback path (line 338).Assistant
I need to navigate to the line first, or use the --file option. Let me use the goto command then edit. Actually, the edit command edits the currently open file. The current file is AgenticServices.java. The issue is that the text isn't in "displayed lines". Let me goto line 338 first.
Assistant
Now let me update the
createSubagentoverride path (line ~599).Assistant
Now
configureAgentis no longer used in AgenticServices. Let me check if the import is still needed.Assistant
Let me check whether the public 4-arg
configureAgentis still used anywhere now.Assistant
The public 4-arg
configureAgentis now only referenced in my javadoc. I'll keep it for backward compatibility (it's public API). Let me remove the now-unused import in AgenticServices.Assistant
My edit created a duplicate
invokeStaticimport. Let me fix lines 5-7.Assistant
There's now a duplicate
checkReturnTypeimport. Let me rewrite the import block cleanly.Assistant
Imports are clean now. Let me compile the module to verify there are no errors.
Assistant
Compilation succeeds. Now let me run the reproduction test.
Assistant
The duplicate tool error is gone. Now the error is the expected
RuntimeException: ERRORfrom mythrowingModel()— meaningcreateContextsucceeded (no duplicate) and it proceeded to call the model. The fix works.Let me write a more comprehensive reproduction that mimics the actual issue using the real
SkillsAPI and verifies the configurator and chat-model fallback paths. First, let me check iflangchain4j-agenticdepends onlangchain4j-skills.Assistant
langchain4j-agenticdoesn't depend onlangchain4j-skills, so my non-dynamic ToolProvider repro is equivalent. Let me write a more comprehensive reproduction using a fake ChatModel that returns a real response, to verify the configurator, chat-model fallback, and composed-agent paths. Let me check existing fake model helpers.Assistant
Let me check the
AgentConfiguratorAPI to build a comprehensive test.Assistant
Now let me write a comprehensive reproduction test that verifies multiple paths: single agent, configurator application, chat-model fallback, and composed sequence with a subagent using
@ToolProviderSupplier.Assistant
Let me fix the configurator test — I referenced a non-existent overload. Let me rewrite the test file cleanly.
Assistant
Let me check the test result summary explicitly.
Assistant
All 5 tests pass, including the exact issue scenario. Now let me make sure I didn't break existing tests. Let me identify non-gated unit tests in the agentic module and run them.
Assistant
Let me run the full test suite offline — gated IT tests will be skipped, and unit tests will run to confirm nothing breaks.
Assistant
All 45 tests pass with BUILD SUCCESS. Let me also check if other agentic modules use the changed APIs, to ensure broader safety.
Assistant
All 45 tests pass. My fix preserves backward compatibility (the public
configureAgentmethods remain). Now let me remove the temporary reproduction test before submitting, as required.Assistant
Removed. Let me verify the final state of my changes with git diff.
Assistant
The diff is clean. Let me do a final compile and test run to confirm everything works after removing the repro test.
Assistant
All 45 existing tests pass (BUILD SUCCESS). Note: my repro test wasn't picked up by the default
mvn testsuite because it lacked a*Test/*ITsuffix — that's why the count stayed 45; it's now removed anyway.Let me verify the standalone path (no model) still throws appropriately via
validateChatModel, to ensure no regression there.Assistant
Everything checks out. The standalone path behavior is unchanged (the constructor still auto-configures and
validateChatModelstill guards standalone usage).Let me do a final review of the complete change set.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →