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
Now let me write a temporary reproduction test.
Assistant
Now let me restructure the method.
Assistant
Now split out the chat model block and the listener block.
Assistant
Now remove the leftover listener block and configurator line at lines 165-172.
Assistant
Final state is clean — only the source fix remains. Here is my checklist review:
-
[x] If an error was reported in the issue description, I have successfully reproduced it. I wrote a temporary test (
TmpDupToolProviderTest) inlangchain4j-agenticthat declares an agent with@ToolProviderSupplierreturning a new non-dynamicToolProviderinstance exposing anactivate_skilltool, and invoked it viaAgenticServices.createAgenticSystem(...). It failed exactly withIllegalConfigurationException: Duplicated definition for tool: activate_skill. Stack-trace instrumentation showed the supplier being invoked twice: once fromAgentBuilder's constructor (DeclarativeUtil.configureAgent(type, builder)) and once fromAgenticServices.createAgenticSystem/createSubagent(configureAgent(type, chatModel, builder, configurator)), registering two distinct providers that each contribute the same tool. -
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error. I split
DeclarativeUtil.configureAgentso the declarative features (tools, tool providers, content retriever, retrieval augmentor, chat memory/provider, listeners) are configured only once — when theAgentBuilderis created — while the 4-arg overload used byAgenticServicesnow only resolves/overrides the chat model and applies theAgentConfigurator. After the change the reproduction test passes and the request sent to the model contains exactly oneactivate_skilltool. -
[x] I have thought about edge cases and made sure my fix handles them as well. I verified: (1) the single-agent path
createAgenticSystem(FooAgent.class); (2) the sub-agent path (@SequenceAgentparent with a sub-agent declaring a tool provider), which suffered from the same double registration; (3)@AgentListenerSupplierlisteners are no longer registered twice (previously composed twice, causing duplicate callbacks) — verified a listener fires exactly once; (4) theAgentConfiguratoris still applied exactly once and last; (5) the chat-model resolution semantics are unchanged, including theIllegalArgumentExceptionwhen no model is available for a sub-agent, and the parameterized@ChatModelSupplierresolvers; (6) all call sites of the 4-argconfigureAgent(repo-wide grep, including other modules) always create the builder throughAgenticServices.agentBuilder(...), whose constructor performs the feature configuration, so nothing is lost. -
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
mvn -pl langchain4j-agentic test→ 45 tests, all green (includingChatSupplierParameterResolverTest, which exercises declarative agent creation). The remaining agentic tests are*ITintegration tests requiring live LLM endpoints and cannot run in this environment. I did not modify or add any repository tests — the reproduction test was temporary and has been deleted.
-
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 →