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
codeCaused 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
java - Assistant
I’ll first inspect
AgenticServicesand related tool-provider registration paths, then locate focused tests for declarative agent creation so I can reproduce the duplicate registration with the repository’s existing test infrastructure. - Assistant
The factory overloads are farther down the file. I’ll inspect those implementations plus the declarative configuration helper and
AgentBuildertool-provider handling to identify exactly where the same provider list is applied twice. - Assistant
The plain path calls
configureAgentonly once, so duplication likely occurs inside that helper through method discovery and inherited/reflected supplier methods, or through configurator application. I’ll inspect the complete overload boundary,DeclarativeUtil.configureAgent, and the builder’s static-provider collection semantics. - Assistant
A single
ToolProviderSupplieris added once in this visible path. The issue’s distinction betweenagentBuilder(...).build()andcreateAgenticSystem(...)suggests a second registration happens via agent lifecycle/rebuild logic rather than initial configuration. I’ll trace where agent builders are rebuilt for scope-dependent execution and inspectSkills/SkillProviderbehavior. - Assistant
The key clue is the static import of
configureAgentinAgentBuilder; its constructor likely auto-applies declarative suppliers. IfcreateAgenticSystemthen explicitly configures the same builder, providers are duplicated, while scalar settings overwrite harmlessly. I’ll confirm the constructor and compare intended use sites before making the narrow factory fix. - Assistant
Confirmed:
AgentBuilder(Class)already calls declarative configuration, and both root and subagent paths call it again. Each supplier invocation can return a distinct provider instance, so identity-based list deduplication would be insufficient and tool-name deduplication would incorrectly mask genuinely conflicting providers. I’ll prevent the duplicate at its source by adding an internal constructor that performs one declarative configuration with the resolved fallback model/configurator, then use it in both factory paths. - Assistant
Python is unavailable, so no edits were applied (the subsequent compile only verified the unchanged tree). I’ll use the repository editor commands instead, first opening the exact constructor lines and then replacing them directly.
- Assistant
I’ll now add the internal one-pass constructor and the required imports, preserving the current public constructor behavior for direct
agentBuilder(...)callers. - Assistant
The imports are correct. I’ll replace the constructor block with delegated initialization so final fields remain assigned exactly once and declarative annotations are still processed before annotation metadata defaults, matching existing ordering.
- Assistant
The root path is fixed; the subagent block still has the old two-pass logic. I’ll switch it too and remove the now-unused static
configureAgentimport fromAgenticServices, then format and compile. - Assistant
The source edit succeeded; only the formatting plugin alias was unavailable. I’ll remove the unused import, inspect the project’s formatting convention/plugin, and run compilation independently.
- Assistant
@Internaldoes not target constructors. Rather than exposing an undocumented constructor, I’ll use an@Internalstatic factory method (a supported annotation target) backed by the private constructor. This keeps the one-pass creation mechanism explicitly internal while allowing the cross-package factory to call it. - Assistant
The static factory compiles in isolation, but the two call-site replacements did not apply because the editor’s literal replacement did not match the full line context. I’ll replace those exact lines directly and recompile.
- Assistant
Compilation now passes. To reproduce without adding repository tests, I’ll build a temporary JUnit source outside the repository tree that defines a declarative agent whose
@ToolProviderSupplierincrements a counter and returns a static provider. The old implementation invokes it twice; the fixed implementation should invoke it once and execute without duplicate tool definitions. I’ll inspect available test model utilities and module dependencies to choose the simplest runnable setup. - Assistant
A full skills reproduction would require adding the skills module dependency, but the root defect is directly observable as supplier invocation count. I’ll run a temporary standalone Java program from
/tmpagainst the built module: it will assert one supplier invocation duringcreateAgenticSystem, then invoke the agent so static tool context creation is exercised. - Assistant
I found the needed APIs. I’ll create and run the
/tmpreproducer with a fixed chat response and a provider exposing one named tool. The assertion on supplier count specifically distinguishes the old two-pass behavior (2) from the fix (1), while invocation validates provider registration and execution setup. - Assistant
The temporary reproducer reached the fixed constructor path but failed because its nested interface was package-private, making reflective supplier invocation illegal; this is a reproducer visibility issue, not the reported bug. I’ll make the temporary interface public and rerun unchanged otherwise.
- Assistant
The reproducer now passes: the supplier is invoked exactly once and agent invocation succeeds with
activate_skillregistered. Next I’ll run the focused declarative supplier/configurator unit tests and the module’s full non-integration test suite, then apply/check the repository formatter and review the final diff. - Assistant
Both the focused test and full module unit tests completed successfully; the chained command failed only at Maven’s plugin-prefix resolution. I’ll invoke Spotless by full coordinates (using the configured version), then inspect whether formatting changed anything and review the complete diff for API/behavioral correctness.
- Assistant
The root-level formatter traversed an internal module that explicitly lacks Spotless and failed before processing our target. I’ll scope the same full-coordinate formatter invocation to
langchain4j-agentic, then review the diff. - Assistant
The final diff is narrow and preserves direct builder behavior. Spotless could not run because this checkout lacks the configured
origin/mainratchet reference, butgit diff --checkpasses and the edited code follows surrounding formatting. I’ll perform one final compile/test/status check and verify no temporary files or unintended changes remain before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.