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.
Assistant
Let me explore the AgenticServices class which is mentioned in the issue.
Assistant
Let me see the middle of the file to understand the relevant methods like
createAgenticSystem.Assistant
Let me find and inspect the
configureAgentmethod.Assistant
Let me look at the Skills class to understand the
activate_skilltool.Assistant
Now let me look at the
AgentBuilderclass to see how it handlestoolProvider:Assistant
Let me check the AgentBuilder constructor to see when
configureAgentis called:Assistant
I see the issue now. Let me look at how
AgentBuilderis created and verify the duplication issue.Assistant
Let me look at the rest of
AgenticServices.javaand theWorkflowAgentsBuilder:Assistant
Let me check
WorkflowAgentsBuilder:Assistant
Let me look at existing tests for
createAgenticSystem:Assistant
Let me check tests with the Skills and
ToolProvider:Assistant
Let me run the existing tests to see if the bug is reproducible:
Assistant
Let me look at the test structure for the
agenticmodule:Assistant
Now let me look at the
ToolServiceto understand how duplicates are detected:Assistant
Let me check if
AgentBuilderis used directly anywhere:Assistant
Let me check the structure of the
Skillsclass more carefully to understand the toolProvider:Assistant
Let me now write a test to reproduce the issue:
Assistant
Let me check the relationship between
langchain4j-agenticandlangchain4j-skills:Assistant
Now let me check the
ToolProviderinterface:Assistant
Let me look at how the chat model is validated:
Assistant
Let me look at the AgentBuilder class for the
setupToolsmethod:Assistant
Now let me create a simple test case to reproduce the issue:
Assistant
Let me look at the test infrastructure:
Assistant
Let me look at
createComposedAgent:Assistant
Now I understand the structure better. Let me also look at the second use of
agentBuilderandconfigureAgentincreateSubagentto see if the same issue exists there:Assistant
Now let me see the existing tests for
DeclarativeUtil:Assistant
Let me look at the
AgentBuilder.buildmethod in full:Assistant
Let me also look at the entire
AgentBuilder.build()method and understand it:Assistant
Let me look at the full AgentBuilder.java file:
Assistant
Now I have a clear understanding. Let me implement the fix. The simplest and most targeted fix is to deduplicate tool provider registrations in the
createAgenticSystemandcreateSubagentmethods.Let me first look at what tests currently exist and create a test case to reproduce the issue:
Assistant
Let me check the build and see if the existing tests pass:
Assistant
We're in offline mode, so I can't download dependencies. Let me try without offline mode:
Assistant
Let me try to access the Maven repository without offline mode:
Assistant
The dependencies are now resolved. Let me check if the tests can be compiled:
Assistant
Now let me write a test case to reproduce the issue:
Assistant
Let me look at the structure of existing tests to write a test:
Assistant
Now let me write a small test class to reproduce the issue first:
Assistant
Let me update the test:
Assistant
Now let me run the test to see if the bug is reproduced:
Assistant
The bug is reproduced. Now let me implement the fix. The cleanest approach is to:
- Add a flag to
AgentBuilderto track ifconfigureAgenthas been called - In
DeclarativeUtil.configureAgent, check this flag to skip duplicate supplier registrations
- Add a flag to
Assistant
Now let me implement the fix. First, I'll modify the
AgentBuilderto track whetherconfigureAgenthas been called:Assistant
Let me look at the AgentBuilder constructor and see the current code:
Assistant
Now let me implement the fix. I'll modify
DeclarativeUtil.configureAgentto check a flag inAgentBuilderand skip already-registered supplier methods:Assistant
Let me try a different approach to do the replacement:
Assistant
Let me use a simpler approach with the
replacecommand:Assistant
Let me write the new content with sed:
Assistant
Now let me add a public getter for the flag so
DeclarativeUtilcan check it:Assistant
Now let me update the constructor to use the new method for consistency:
Assistant
Now let me modify
DeclarativeUtil.configureAgentto skip the supplier methods if the agent is already configured:Assistant
Now let me refactor
DeclarativeUtil.configureAgentto skip already-applied supplier methods:Assistant
Let me also check that the test passes by compiling:
Assistant
I need to make the methods public, or move them to be accessible from
DeclarativeUtil. Let me make them public:Assistant
Now let me run the test to see if the fix works:
Assistant
The test passes! Now let me run all the existing tests to make sure I didn't break anything:
Assistant
All existing tests pass! Let me also test the original user's case (Skills class) and some edge cases:
Assistant
Now let me also test with the actual
Skillsclass:Assistant
The
langchain4j-agenticmodule doesn't havelangchain4j-skillsas a dependency. Let me create a mock that mimics the Skills behavior:Assistant
Let me check if there are any existing tests that use
Skills:Assistant
Let me clean up and run all the tests to make sure everything still works:
Assistant
All 45 tests pass! Let me also test other related modules:
Assistant
All tests pass! Let me now also verify my fix is correct by examining the code:
Assistant
Let me also test the other related modules to make sure nothing is broken:
Assistant
Let me re-verify the fix works by creating a test case again:
Assistant
All tests pass. Let me also check if
createSubagentworks correctly:Assistant
The
createSubagentcase also works. Let me clean up the test files:Assistant
Let me also run all the tests one more time to confirm everything works:
Assistant
All 45 tests pass. Now let me view the final code changes:
Assistant
I notice there's a duplicate Javadoc comment. Let me fix that:
Assistant
Now let me run all the tests one more time to make sure everything still works:
Assistant
Let me also look at the final diff:
Assistant
Let me also run the related tests:
Assistant
Let me write a final test to confirm the bug is fixed:
Assistant
Let me also clean up the test:
Assistant
Let me also check
WorkflowAgentsBuilder:Assistant
Let me also check if there are any other places that call
configureAgent:Assistant
Let me also check
MonitoredAgent.java:Assistant
Let me run all the tests one final time:
Assistant
All tests pass. Let me also verify by running the related modules one final time:
Assistant
All tests pass. Let me view the final state of the code:
Assistant
Let me also check the integration tests to make sure they still pass:
Assistant
Let me also verify the most complex test (ChatSupplierParameterResolverTest) still works:
Assistant
Let me also write a more comprehensive test that better mimics the user's case:
Assistant
All 5 tests pass. Let me clean up the test file:
Assistant
Let me also do a final review of the changes:
Assistant
The fix looks complete and clean. Let me now run all the tests one final time to confirm everything works:
Assistant
All tests pass. The fix is complete and working.
Let me write a summary of the changes made:
Summary of the fix:
The issue was that
AgenticServices.createAgenticSystem()was throwingIllegalConfigurationException: Duplicated definition for tool: activate_skillwhen an agent had a@ToolProviderSupplierreturning a non-dynamicToolProvider(such as the one from theSkillsclass).Root cause: The
AgentBuilderconstructor callsDeclarativeUtil.configureAgent()to set up the agent from supplier methods (e.g., ). Then calls again on the same builder to apply the chat model and configurator. This second call was re-invoking the supplier methods, which added the same to the list twice. Since the is non-dynamic, its tools (including ) were evaluated twice, causing the duplicate tool definition error.Assistant
Let me run the tests one more time to confirm everything works:
Assistant
All 45 tests pass. Now let me also do the checklist review:
Checklist:
-
If an error was reported in the issue description, I have successfully reproduced it. I created a test case that reproduces the
IllegalConfigurationException: Duplicated definition for tool: activate_skillerror when usingAgenticServices.createAgenticSystem()with a@ToolProviderSupplierthat provides a non-dynamicToolProvider(mimicking the class behavior).
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.