[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's add the two new methods after these chat model setters.
Assistant
Good. Now update DeclarativeUtil.java to modify the 4-arg configureAgent.
Assistant
Now let's build the module to check compilation errors.
Assistant
Compiles fine. Now let's write a reproduction test to confirm the fix resolves the duplicate tool issue.
Assistant
Good, langchain4j-skills module exists. Let's check if langchain4j-agentic can depend on it for testing, or write a simpler reproduction using a fake ToolProvider that isn't dynamic and produces an activate_skill-named tool, or better, just use two ToolProviderSupplier-like scenario to simulate duplicate registration directly by counting invocation.
Assistant
Now let's write a temporary reproduction test.
Assistant
Now let's confirm the bug reproduces on the pre-fix code first (stash the fix), then confirm it's fixed.
Assistant
Reproduced exactly the reported error. Now restore the fix and re-run.
Assistant
The fix works — no error, and the test passed (no failure output). Let's confirm explicitly.
Assistant
The fix resolves the issue. Now let's remove the temporary test and run the full existing test suite for langchain4j-agentic module (skipping IT tests that need real API keys, focusing on unit tests).
Assistant
All 45 unit tests pass. Now let's also check the IT tests that don't require network (they are annotated with @EnabledIfEnvironmentVariable), so they'll be skipped. Let's verify by attempting to run the whole test module including ITs (they should just get skipped without keys, not fail).
Assistant
Good, IT tests require API keys and would be skipped automatically without them (not run by default via surefire since named *IT and typically run via failsafe, not surefire). Let's just double check compilation of the whole module (including test sources) still fine, and run a broader mvn test for the whole module.
Assistant
All good. Let's view final diff.
Assistant
Let's build and test these dependent modules too, to be safe.
Assistant
All modules build and pass. Now let's do a final review of the diff and clean up.
Assistant
Good, no leftover temp test files. Let's do a final sanity check of the diff content once more.
Assistant
The changes look good and minimal. Let me review the checklist one more time before submitting.
Assistant
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.
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 using git reset --hard command.
Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later.
Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands.
However you don't need to use git add or git commit before submitting your changes. In fact,
submit only submits currently unstaged changes because it uses git diff to 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-$
Checklist Review
[x] If an error was reported in the issue description, I have successfully reproduced it.
I wrote a temporary test (TmpDuplicateToolProviderReproTest) mimicking the issue's FooAgent example (a single @Agent interface with @ToolProviderSupplier returning a non-dynamic ToolProvider producing an activate_skill tool, plus @ChatModelSupplier). Running it against the original code reproduced the exact reported stack trace: IllegalConfigurationException: Duplicated definition for tool: activate_skill.
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error.
After applying the fix, the same reproduction test passed with no exception, and the tool was registered exactly once.
[x] I have thought about edge cases and made sure my fix handles them as well.
Root cause: AgenticServices.createAgenticSystem/createSubagent constructed an AgentBuilder (whose constructor already runs full declarative configuration once, with a no-op AgentConfigurator and allowNullChatModel=true), and then called DeclarativeUtil.configureAgent(...) a second time with the real chat model/configurator — fully re-running the same declarative annotation processing (tools, tool providers, content retriever, retrieval augmentor, chat memory, chat memory provider, chat model, and listener) a second time.
Fixed by making the second (public 4-arg) configureAgent only do the two things that actually differ between the two invocations: (1) set a fallback chat model only if none is already configured (new AgentBuilder.chatModelIfAbsent/hasChatModelConfigured helpers), and (2) apply the real AgentConfigurator exactly once.
This also incidentally fixes a latent duplicate-listener bug (the same AgentListener instance was previously being wrapped twice in a ComposedAgentListener), and duplicate-tools/duplicate-contentRetriever/etc. issues that would have surfaced with any declarative agent participating in createAgenticSystem with tools/providers configured declaratively — not just for Skills/activate_skill.
Verified the "no chat model configured" failure path still throws a clear, though now generic, AgenticSystemConfigurationException from AgentBuilder.build() (previously a more specific IllegalArgumentException message existed in the now-bypassed code path, but no test relies on that particular message).
Confirmed the direct/non-composed usage pattern (AgenticServices.agentBuilder(Class).build()) is untouched, since it only ever goes through the 2-arg configureAgent in the constructor.
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
Ran the full test suites (unit tests, since ITs require external API keys) for langchain4j-agentic, langchain4j-agentic-mcp, langchain4j-agentic-patterns, and langchain4j-agentic-a2a (plus their dependency modules) via Maven — all builds succeeded with 0 failures/errors across hundreds of tests.
The temporary reproduction test file was removed before submission (only the actual source fix remains in the diff).