Untitled conversation
- User
[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.
- Assistant
Investigating duplicate
activate_skillregistration increateAgenticSystemby tracing tool provider setup in the agentic services code. - Assistant
Implementing the fix:
configureAgentruns twice—once inAgentBuilder's constructor and again increateAgenticSystem—which registers tool providers twice. Splitting supplier configuration so it only runs once. - Assistant
Now adding a unit test that reproduces the duplicate tool provider registration.
- Assistant
Fixed the duplicate
activate_skillregistration increateAgenticSystem().Root cause
configureAgent()was running twice for agents created viacreateAgenticSystem():- In the
AgentBuilderconstructor (declarative suppliers + chat model) - Again in
createAgenticSystem()/createSubagent()(same suppliers + chat model + configurator)
Each run invoked
@ToolProviderSupplieragain, so non-dynamic providers likeSkills.toolProvider()were registered twice.ToolServicethen calledprovideTools()on both and threwDuplicated definition for tool: activate_skill.agentBuilder().build()was unaffected because it only configured once.Fix
In
DeclarativeUtil, supplier configuration is split from chat-model configuration:- First call (
AgentBuilderconstructor): configures declarative suppliers (tools, tool providers, memory, listeners, etc.) and chat model - Second call (
createAgenticSystem): only applies the fallback chat model andAgentConfigurator— suppliers are not re-registered
private static void configureAgent( Class<?> agentType, ChatModel chatModel, boolean allowNullChatModel, AgentBuilder<?, ?> agentBuilder, AgenticServices.AgentConfigurator agentConfigurator, boolean configureSuppliers) { if (configureSuppliers) { configureDeclarativeSuppliers(agentType, agentBuilder); } configureDeclarativeChatModel(agentType, chatModel, allowNullChatModel, agentBuilder); agentConfigurator.configurator().accept(new DefaultDeclarativeAgentCreationContext(agentType, agentBuilder)); }Test
Added
CreateAgenticSystemToolProviderTest, which uses a non-dynamicToolProviderexposingactivate_skill(same pattern asSkills) and verifiescreateAgenticSystem()runs without duplicate-tool errors.Your reproduction case should work with both:
AgenticServices.createAgenticSystem(FooAgent.class).test();and:
AgenticServices.agentBuilder(FooAgent.class).build().test(); - In the
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
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →