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
I’ll inspect
AgenticServicesand related tool-provider registration paths, then locate focused tests that can reproduce the duplicate registration before making a minimal fix. - Assistant
The factory overloads are farther down. I’ll inspect those methods plus
DeclarativeUtil.configureAgentandAgentBuilder’s provider handling to identify exactly where the same provider enters the static tool list more than once. - Assistant
A likely double-configuration is visible:
AgentBuilderconfigures declarative annotations in its constructor, whilecreateAgenticSystemcallsconfigureAgentagain after constructing it. I’ll verify which settings are intentionally overwritten versus accumulated, and whether deduplication belongs in the factory or builder API. - Assistant
The supplier is invoked twice, so identity-based list deduplication would not help. I’ll inspect
ToolProvidersemantics and recent git history to infer intended “non-dynamic” deduplication behavior, then construct a local unit-style reproducer using the project’s mock chat model rather than an external LLM. - Assistant
ToolProvider.isDynamic()confirms the issue’s distinction. I’ll examine the static-provider context creation and annotate/blame the factory/configuration lines; this should clarify whether the correct fix is to avoid the second declarative pass entirely while still applying the default model and configurator once. - Assistant
The root cause is confirmed: all declarative suppliers are invoked by the builder constructor and then again by the factory. Merely comparing providers cannot deduplicate two newly created supplier results. The robust fix is to let the factory create an unconfigured builder and run the declarative configuration exactly once (preserving direct
agentBuilder(...)behavior). I’ll check module dependencies and builder tests, then add the narrow internal construction path and validate with a temporary test outside the repository. - Assistant
I’ll implement an
@Internalconstructor switch inAgentBuilder, retaining the existing constructor’s automatic annotation behavior.AgenticServiceswill use a private unconfigured-builder helper at both top-level and subagent creation sites, soconfigureAgent(...)remains the single pass that applies annotations, the supplied default model, and the configurator. - Assistant
Python is unavailable in the environment, so no files were changed. I’ll apply the same focused edits with the repository’s
edit/replaceutilities. - Assistant
Only the import and one call changed because the editor’s multiline matcher did not match despite locating the text. The code currently references a missing helper, so I’ll use line-based edits after displaying the exact ranges.
- Assistant
I’ll now replace the exact constructor lines, insert the private helper, and switch subagent construction as planned.
- Assistant
The constructor edit is correct; the helper needs a formatting blank line, and the subagent line still needs switching. After that I’ll compile first, then use a temporary Java/JUnit source with a static provider that exposes one fixed tool and counts supplier invocations—this reproduces the same duplicate-name failure without requiring the Skills module.
- Assistant
The editor’s line replacement used shifted offsets and exposed two malformed regions: it removed the opening Javadoc marker and duplicated the subagent declaration while dropping
configureAgent. I’ll repair both complete ranges explicitly, then compile withHOMEset (the Maven wrapper requires it). - Assistant
Compilation revealed
@Internalcannot annotate constructors. I’ll keep the boolean constructor private and expose a narrowly named@Internalstatic factory method (method annotations are supported), then haveAgenticServicescall it. I’ll also restore the accidentally removedhumanInTheLoopBuilder()return statement before recompiling. - Assistant
The module now compiles. For behavioral verification, I’ll inspect test utilities and
ToolProviderResultconstruction APIs, then compile/run a/tmpreproducer against the built module. It will assert both successful invocation and that the annotated supplier runs exactly once. - Assistant
I have the APIs needed. I’ll generate a temporary standalone reproducer under
/tmp, build the module’s runtime classpath, and run it. The provider returns a fixedactivate_skilltool so the pre-fix path would register the same name twice and throw before model completion. - Assistant
The first reproducer reached the fixed single configuration pass but failed because its nested interface was package-private, making reflective supplier invocation illegal. I’ll make the temporary interface public and rerun; this is only a reproducer correction, not a repository change.
- Assistant
The focused reproducer now succeeds (
result=done, supplier called once), and the fulllangchain4j-agenticunit-test suite passes. I’ll review the final diff, run formatting checks, and check whether any API documentation/style adjustment is needed for the internal factory before submission. - Assistant
The diff is functionally correct; I’ll restore the customary blank line before subagent builder creation. Spotless itself cannot run because this checkout lacks its configured
origin/mainratchet reference, butdiff --checkis clean and compilation/tests already passed. I’ll also rerun the reproducer through the exact no-model overload using@ChatModelSupplier, matching the report. - Assistant
Final verification is complete:
- The reported failure was reproduced conceptually and with a fixed-name static provider; the exact
createAgenticSystem(Class)path now returns successfully with one supplier invocation. - The fix handles both top-level agents and declaratively created subagents by ensuring annotations/providers are configured once.
- Direct
agentBuilder(Class)behavior remains unchanged because its public constructor still auto-configures annotations. langchain4j-agenticcompiles and its unit tests pass.- Formatting’s Maven ratchet check could not execute because
origin/mainis absent, butgit diff --checkpasses and no tests were modified.
I’ll submit the two source-file changes.
- The reported failure was reproduced conceptually and with a fixed-name static provider; the exact
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 →