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 when usingAgenticServices.createAgenticSystem(). Let me explore the repository structure first.Let me look at the relevant files mentioned in the issue:
AgenticServices.java- the main file with the bugToolService.java- where the error occursSkills.java- the skills builder
Let me start by exploring the repository structure and understanding the codebase.
Assistant
Let me make a single command call.
Assistant
Let me explore the key files.
Assistant
Let me open the key files to understand the issue
Assistant
Let me look at the
createAgenticSystemmethod.Assistant
Let me look at the
createAgenticSystemmethods starting from line 298 and also theconfigureAgentmethod.Assistant
Now let me look at
DeclarativeUtil.configureAgentwhich is called at line 338.Assistant
Let me look at both the configureAgent method in DeclarativeUtil.java and the agentBuilder method in AgenticServices.java.
Assistant
Let me look at the
configureAgentmethod inDeclarativeUtil.java.Assistant
Let me continue reading
DeclarativeUtil.javaand also look at theToolService.javaerror locationAssistant
Let me look at the
agentBuildermethod and how tool providers are added during the build processAssistant
Let me look at the
AgentBuilderclass to understand how tool providers are handled during buildAssistant
Let me look at the AgentBuilder class to understand how tool providers are handled during
Assistant
Let me see the build method and how tool providers are passed to AiServices
Assistant
Let me look at the
setupToolsmethodAssistant
Let me look at the
setupToolsmethod and surrounding code.Assistant
Let me look at AiServices.toolProviders to understand how tool providers are handled
Assistant
Let me look at the
toolProvidersmethod in AiServices.java and understand how tool providers map to the ToolService.Assistant
Let me look at
ToolService.toolProvidersandToolService.toolProvidermethodsAssistant
Let me look at the AgentBuilder constructor more carefully - specifically line 141 that calls `configureAgent
Assistant
Let me look at the Skills class to understand the
activate_skilltoolAssistant
Let me look at the
createToolProvidermethodAssistant
Let me see the
createToolProvidermethod to check if it's dynamic or notAssistant
Let me see the rest of the
createToolProvidermethodAssistant
Let me read the full
configureAgentmethod to understand the `allowNullChatModelAssistant
Let me see the rest of
configureAgentAssistant
Now I have a clear understanding of the issue. Let me verify by looking at the
createAgenticSystemmethod one more time and theAgentBuilderconstructor.Assistant
Let me search for all places that create AgentBuilder or call configureAgent to understand the full impact
Assistant
No results. Let me try a broader search.
Assistant
Let me check UntypedAgentBuilder to see if it also has this
Assistant
Let me look at the build methods for composed agents to see if they also call configureAgent
Assistant
Let me look at
buildSequentialAgentto see if it also calls configureAgentAssistant
Let me look at
createSubagentandcreateSubagentsmethodsAssistant
Let me look at
createSubagentandcreateSubagentsAssistant
Now I understand the issue completely. Let me trace through the code to confirm the double-registration:
AgentBuilderconstructor at line 141 callsconfigureAgent(agentServiceClass, this)which adds ToolProviderscreateAgenticSystemat line 338 callsconfigureAgentagain - adding ToolProviders a second time- Same issue exists in
createSubagentat line 597-598
The fix: remove
configureAgentfrom the constructor, move it toagentBuilder(Class<T>), and increateAgenticSystem/createSubagent, only apply chatModel and configurator without re-scanning annotations.Let me first check if
hasChatModelSupplier-like methods exist:Assistant
Now I have a clear understanding. Let me implement the fix. The root cause is:
AgentBuilderconstructor callsconfigureAgent(agentServiceClass, this)which adds ToolProviderscreateAgenticSystemcallsconfigureAgentagain, adding ToolProviders a second time- Same issue in
createSubagentat line 597-598
The fix: Remove
configureAgentfrom the constructor, call it once fromagentBuilder(Class<T>), and increateAgenticSystem/createSubagent, only apply chatModel and configurator without re-scanning annotations.Let me start implementing
Assistant
Now let me implement the fix. First, let me check the imports in AgenticServices.java and DeclarativeUtil.java properly
Assistant
Let me check the imports of Declarative
Assistant
Now let me implement the fix. I'll:
- Remove
configureAgentfrom AgentBuilder constructor - Move it to
agentBuilder(Class<T>)method - Add a new method in DeclarativeUtil for applying only chatModel+configurator
- Use the new method in
createAgenticSystemandcreateSubagent
Let me start with step 1 - removing the configureAgent call from the AgentBuilder constructor:
- Remove
Assistant
Let me clean up the blank line and check for unused import.
Assistant
Let me remove the unused import and the blank
Assistant
Let me also clean up the blank line left from removing the configureAgent call:
Assistant
Let me remove the extra blank line
Assistant
Now let me update
AgenticServices.agentBuilder(Class<T>)to callconfigureAgentafter construction. Then I need to handlecreateAgenticSystemandcreateSubagentto not double-conAssistant
Now let me add a new method in DeclarativeUtil.java for applying only chatModel and configurator without re-scanning annotations. Let me first check what's already imported:
Assistant
Let me check if
ChatModelSupplierandStreamingChatModelSupplierare imported in DeclarativeUtil.javaAssistant
Good, they're in the same package so no imports needed. Let me add the new method in DeclarativeUtil.java after the existing
configureAgentmethod:Assistant
Now let me add the new method in DeclarativeUtil.java after the
configureAgentAssistant
There's a duplicate line. Let me fix it
Assistant
Now let me update
AgenticServices.javato import and use the new method. First, let me check the current import for `configureAssistant
I need to add the import for
applyAgentConfigurator. Let me update the imports in AgenticServices.java.Assistant
Let me open AgenticServices.java first
Assistant
Now let me add the import and update the method calls
Assistant
Now let me update the
createAgenticSystemmethod to useapplyAgentConfiguratorinstead ofconfigureAgent.Assistant
Now let me update
createAgenticSystemto useapplyAgentConfiguratorinstead of `Assistant
Now let me update
createSubagentsimilarlyAssistant
Now let me update
createSubagentto useapplyAgentConfiguratorinstead of `configureAgentAssistant
Let me verify there are no remaining
configureAgentcalls in AgenticServices.java that need updatingAssistant
Good - only one
configureAgentcall remains in AgenticServices.java (in theagentBuilderfactory method). Let me check for any other places in the codebase that might be affectedAssistant
Let me also check for any external callers of
configureAgentor directAgentBuilderconstructor usageAssistant
Let me now try to compile to make sure everything is correct
Assistant
Compilation succeeded. Let me run the tests for the agentic and skills modules to make sure nothing is broken
Assistant
Let me check the test results more
Assistant
All tests pass. Let me also run the skills module tests
Assistant
All tests pass. Let me verify the final state of all the
Assistant
Let me check how
configureChatModelhandles the missing chatModel case:Assistant
Let me look at the
configureChatModelmethodAssistant
I should add validation to
applyAgentConfiguratorto match the original error behavior when no chatModel is configured. Let me update it:Assistant
Let me recompile to make sure everything still works
Assistant
Let me run the tests one more
Assistant
All tests pass. Let me now view the final diff to confirm everything is clean
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.