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:
Assistant
Let me start by exploring the repository structure to understand the codebase and find the relevant files.
Assistant
Let me explore the repository structure and the relevant file.
Assistant
Let me look at the
createAgenticSystemmethod specifically and the truncated middle part.Assistant
Let me look at the
createAgenticSystemmethods in detail (lines 280-340).Assistant
Now let me look at the
AgentBuilder,configureAgentinDeclarativeUtil, and the Skills/activate_skilltool.Assistant
Let me look at the AgentBuilder and DeclarativeUtil to understand how tools are registered.
Assistant
Now let me look at the AgentBuilder to understand how
toolProviderand tools work.Assistant
Let me look at the
createSubagentmethod which seems to have a similar pattern.Assistant
Let me look at the full
setupToolsmethod and check usages ofAgentBuilderconstructor.Assistant
Let me check all usages of
agentBuilder(to understand the direct usage path.Assistant
Let me look at the
UntypedAgentBuilderto understand the builder hierarchy.Assistant
Let me check the
MonitoredAgent.javato understand ifnew AgentBuilderis used directly there.Assistant
Let me look at how the project is built and check for an
@Internalannotation and existing test infrastructure.Assistant
Let me look at the
SingleAgentITtest and any existing skills tests that relate to this issue.Assistant
Let me look at the
langchain4j-skillsmodule to understand howSkillsandactivate_skillwork.Assistant
Now let me look at the
ToolService.javato understand how the duplicate detection happens.Assistant
Let me look at where
AgentBuilderis constructed directly and how the auto-configuration in the constructor works.Assistant
Let me understand the structure. The
AgentBuilderconstructor callsconfigureAgent(agentServiceClass, this).In
createAgenticSystem, the flow is:createComposedAgent(...)returns null (since FooAgent has no workflow annotations, just an @Agent)var agentBuilder = agentBuilder(agentServiceClass);→ constructor callsconfigureAgent(registers tools + chatModel)
Assistant
So no tests use
new AgentBuilderdirectly. They all useAgenticServices.agentBuilder(...).Let me look at the
AgentUtil.javaline 100 whereagent = AgenticServices.agentBuilder(c).build();is used.Assistant
Now I understand the root cause. Let me reproduce the issue first. Let me check the build system.
Assistant
Let me look at existing tests to understand the test infrastructure and how they use mock models.
Assistant
Let me look at the DeclarativeAgentIT and how tests use stub models.
Assistant
Let me look at
DefaultAiServices.invoketo understand whencreateContextis called.Assistant
Let me check how a stub ChatModel can be created and look at existing non-IT tests.
Assistant
Let me write a reproduction test. First, let me understand the
ChatModelinterface to create a stub.Assistant
Let me create a reproduction test. First, let me check the
ChatResponseandAiMessagebuilders.Assistant
Now let me create a reproduction test file.
Assistant
Now let me run the reproduction test. First, let me check if dependencies are available.
Assistant
Offline mode doesn't work. Let me try without offline mode to install dependencies.
Assistant
The build is downloading dependencies now. Let me run with the flag to ignore missing tests in other modules.
Assistant
I've reproduced the error. The root cause is confirmed:
createAgenticSystemcallsconfigureAgenttwice — once in theAgentBuilderconstructor and once explicitly. Let me examine the@Internalannotation and the constructor more closely.Assistant
Let me check all places that create an
AgentBuilderand then callconfigureAgent(the double-configuration pattern).Assistant
Now I have a clear picture. The double-configuration happens in two places:
createAgenticSystem(line 337-338) andcreateSubagent(line 597-598). Both callagentBuilder(class)(which auto-configures in the constructor) and thenconfigureAgent(...)again.Let me look at the
AgentBuilderconstructor to refactor it.Assistant
Let me check if
new AgentBuilderis used directly anywhere (including other modules and tests) to assess the impact of changing constructor behavior.Assistant
Let me look at the workflow builder methods to see if they also have double-configuration patterns.
Assistant
Let me look at the chat model configuration logic in
AgentBuilderto understand the chat model fallback.Assistant
I now have a clear understanding. Let me implement the fix using the "unconfigured builder" approach — the cleanest way to prevent double-configuration. First, let me refactor the
AgentBuilderconstructor and add an internal factory.Assistant
Let me look at how
DeclarativeAgentITcreates agents to understand the typical usage patterns and confirm my fix won't break them.Assistant
Let me look at the
CreativeWriteragent and theAgents.javato understand the test agents' declarations.Assistant
Now I'll implement the fix. The approach: add an internal "unconfigured" builder factory to
AgentBuilderso thatcreateAgenticSystemandcreateSubagentcan build an agent without the constructor's auto-configuration, then configure it exactly once.Let me first add the
Internalimport toAgentBuilder.Assistant
Now let me refactor the constructor to delegate to a boolean constructor, and add the unconfigured factory method.
Assistant
Let me open the file and use the
editcommand with line ranges.Assistant
Now let me add the public
@Internalstatic factory methodunconfigured. Let me add it right after the constructor.Assistant
I see an issue — the second edit removed the constructor's closing brace. Let me fix that.
Assistant
The
AgentBuilderchanges look good. Now let me updateAgenticServicesto use the unconfigured builder. Let me check the imports first.Assistant
Good,
AgentBuilderis imported. Now let me update thecreateAgenticSystemmethod.Assistant
Now let me update the
createSubagentmethod.Assistant
Now
createSubagentat line 597 usesagentBuilder(subgentClass). ThesubgentClassisClass<?>. TheAgentBuilder.unconfigured(Class<T>)is generic<T>. CallingAgentBuilder.unconfigured(subgentClass)where subgentClass isClass<?>would infer T as the capture of?. The return type would beAgentBuilder<CAP, AgentBuilder<CAP, ?>>. Assigning toAgentBuilder<?, ?>should work.Wait, actually there might be a compilation issue with wildcard capture. Let me think.
agentBuilder(subgentClass)currently works wheresubgentClassisClass<?>. The existingagentBuilder(Class<T> agentServiceClass)is<T> AgentBuilder<T, ...>. So it already handlesClass<?>via inference. Myunconfiguredhas the same signature, so it should work the same way.Let me make the edit.
Assistant
Now let me run the reproduction test to verify the fix compiles and resolves the error.
Assistant
The test passed (no error). Let me confirm explicitly with the build result.
Assistant
The fix works. Let me extend the reproduction test to cover more edge cases: the workflow/subagent path (which goes through
createSubagent), thecreateAgenticSystem(Class, ChatModel, AgentConfigurator)overload with no@ChatModelSupplier(chatModel fallback), and the directagentBuilder()path (regression check).Assistant
All 4 tests pass. Now let me run the existing non-IT tests in the agentic module to make sure I didn't break anything.
Assistant
All non-IT tests pass. Let me also run the skills module tests since the issue involves the
activate_skilltool from the Skills module.Assistant
All skills tests pass. Let me check if there are any other double-configure patterns in the related agentic modules (a2a, mcp, patterns).
Assistant
The other modules only use the public
agentBuilder(Class)factory (correct, auto-configures once) and have noconfigureAgentcalls. My fix covers the only two double-configure sites.Now let me remove the temporary test file before submitting (per the guidelines, I shouldn't add tests to the repo).
Assistant
Let me review the final diff of my changes.
Assistant
The diff looks clean. Let me do a final compile check to ensure the main source compiles cleanly after removing the temp test.
Assistant
Compilation succeeds. Let me verify there are no leftover temp files and confirm the git status.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.