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 understanding the repository structure and the issue. The bug is about duplicate
activate_skilltool definition error when usingAgenticServices.createAgenticSystem(). Let me explore the relevant files.Assistant
Let me try again with a single command.
Assistant
Let me open this file to examine it.
Assistant
Let me look at the
createAgenticSystemmethod and relevant code:Assistant
Let me look at the main
createAgenticSystemmethod starting around line 330.Assistant
Now let me look at the
ToolServiceclass where the error originates.Assistant
Let me open ToolService.java to look at the relevant methods.
Assistant
Let me look at the
addToolsandcreateContextFromStaticToolsAndProvidersmethodsAssistant
Now let me find where
activate_skillis defined and howSkills/SkillProviderwork.Assistant
Let me look at the Skills.java file and the ActivateSkillToolConfig.java.
Assistant
Let me look at how
configureAgentworks and how tools are registered.Assistant
Let me look at DeclarativeUtil.java, specifically the
configureAgentmethod.Assistant
Let me see the rest of this file.
Assistant
Let me look at the
agentBuildermethod in AgenticServices.Assistant
Let me look at the
AgentBuilderclassAssistant
Let me look at AgentBuilder.java.
Assistant
Let me look at the
buildmethod and tool-related methods in AgentAssistant
Let me look at the
AiServices.toolProvidersmethod.Assistant
Let me look at how
toolProvidersis handled in AiServices.Assistant
Let me look at
toolProvidersmethod in ToolService.Assistant
Let me read the AgentBuilder
buildmethod more thoroughlyAssistant
Let me look at all places where
AgentBuilderconstructor andconfigureAgentare called:Assistant
Now I understand the root cause. The
configureAgentis called twice:- In
AgentBuilderconstructor (line 141):configureAgent(agentServiceClass, this) - In
createAgenticSystem(line 338):configureAgent(agentServiceClass, chatModel, agentBuilder, agentConfigurator)- butagentBuilderwas already created viaagentBuilder()which called the constructor, soconfigureAgentwas already called.
The same double-call happens for sub-agents (lines 597-598).
The fix:
- Remove
configureAgentfrom theAgentBuilderconstructor - Add it to the
agentBuilder()public static method (maintaining backward compatibility) - In
createAgenticSystemand sub-agent creation, usenew AgentBuilder<>()directly to avoid theagentBuilder()path, then callconfigureAgentexactly once with the right parameters.
Let me implement this:
- In
Assistant
Now let me implement the fix. First, remove
configureAgentfrom theAgentBuilderconstructor.Assistant
Now let me update the
agentBuilder()method inAgenticServicesto callconfigureAgentAssistant
I need to add
configureAgent(agentServiceClass, builtAgentBuilder)to theagentBuilder()method.Assistant
Now let me change
createAgenticSystemto usenew AgentBuilder<>()instead of `agentBuilderAssistant
I need to change
var agentBuilder = agentBuilder(agentServiceClass);tovar agentBuilder = new AgentBuilder<>(agentServiceClass);since the explicitconfigureAgentcall on the next line is the one that should configure the agent with the right chatModel and agentConfigurator.Also, let me check the sub-agent creation at line 597.
Assistant
Now let me fix both locations. First, the
createAgenticSystemmethodAssistant
I see there are duplicate lines! Let me check the current state more
Assistant
Let me fix the duplicate
Assistant
Now let me fix the sub-agent creation. Let me find it again:
Assistant
Let me check the context around line 598
Assistant
I need to change
agentBuilder(subgentClass)tonew AgentBuilder<>(subgentClass)sinceconfigureAgentis already called explicitly on the nextAssistant
Let me also check
AgentUtil.javaline 100 whereagentBuilderis called to ensure it still works correctlyAssistant
Good. The
AgentUtilusage goes throughagentBuilder()which now callsconfigureAgent, so that still works correctly.Now let me check if there are tests related to this functionality that I can run to verify the fix.
Assistant
Let me check if the code compiles and if there are unit tests I can run.
Assistant
The code compiles. Let me run the unit tests for the agentic module.
Assistant
Let me check the test results more specifically.
Assistant
All tests pass with BUILD SUCCESS. Let me also verify by looking at the test files to understand what's being tested related to this.
Assistant
Now let me verify my changes are complete and correct by looking at the diff.
Assistant
Let me also check if
UntypedAgentBuilderhas a similar issue.Assistant
Let me also run the skills tests to make sure they pass
Assistant
All tests pass. Let me verify the fix is complete by reviewing the final changes one more time.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.