[BUG] Duplicate activate_skill tool definition error when using AgenticServices.createAgenticSystem()Describe the bug
When creating an agentic system with AgenticServices.createAgenticSystem(), even with a single agent, the application throws an IllegalConfigurationException: Duplicated definition for tool: activate_skill during execution, caused by multiple registrations of non-dynamic ToolProvider instances.
Log and Stack trace
code
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 more
To Reproduce
java
Assistant
Now let me check all callers of configureAgent across the repo, including other modules:
Assistant
Now fix the body of the constructor-path configureAgent (it still references the removed chatModel/allowNullChatModel/agentConfigurator parameters):
Assistant
Both public signatures are preserved; only behavior changed. Now compile and run the module's tests:
Assistant
Compiles. Now let me look at existing tests for the declarative API and tool providers to add a regression test:
Assistant
Test passes. Let me verify the test actually catches the bug by temporarily reverting the fix:
Assistant
All 47 unit tests pass. Let me verify formatting compliance since the build enforces spotless:
Assistant
All 47 tests pass. The fix is complete.
Summary
Root cause: The declarative configuration of an agent was applied twice:
The AgentBuilder constructor (AgentBuilder.java:141) calls , which processes all declarative annotations — including , which the provider to the builder's list.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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_skill tool) when registering non-dynamic ToolProvider instances.
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 createAgenticSystem registering non-dynamic ToolProvider instances multiple times. The activate_skill tool is automatically added for every SkillProvider instance, 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.
configureAgent(agentServiceClass, this)
@ToolProviderSupplier
appends
toolProviders
AgenticServices.createAgenticSystem (AgenticServices.java:337-338) and createAgentExecutor (AgenticServices.java:597-598) create the builder (first application) and then called the 4-arg configureAgent(...) again, re-running the entire declarative configuration. The @ToolProviderSupplier method was invoked a second time and its provider appended again.
While single-valued settings (chat model, memory, retriever, etc.) are just overwritten by the second pass, tool providers and @AgentListenerSupplier listeners are additive — so the Skills tool provider ended up registered twice, and at invocation time ToolService.addTools threw IllegalConfigurationException: Duplicated definition for tool: activate_skill.
The 4-arg configureAgent(agentType, chatModel, agentBuilder, agentConfigurator) no longer re-runs the full declarative configuration. It now only does what the builder constructor couldn't: applies the default/parent chat model when the agent class declares no @ChatModelSupplier/@StreamingChatModelSupplier (throwing the same descriptive error when none is available), and invokes the AgentConfigurator callback.
The full annotation processing lives solely in the 2-arg configureAgent, called once from the AgentBuilder constructor. This also fixes the latent duplicate-listener composition from @AgentListenerSupplier.
Both public method signatures are unchanged, so no callers needed updating.
Regression test (langchain4j-agentic/src/test/java/dev/langchain4j/agentic/DeclarativeToolProviderTest.java): an agent with a @ToolProviderSupplier is built via both createAgenticSystem and agentBuilder(...).build(), asserting the invocation succeeds, the supplier is invoked exactly once, and the chat request contains exactly one instance of the provided tool. Verified the test fails with Duplicated definition for tool on the pre-fix code and passes with the fix.