You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature]: support LangChain4j Tool Interoperability #3542
It would be useful to improve interoperability with other Java LLM frameworks, especially LangChain4j, by allowing AgentScope Java to reuse existing LangChain4j tool definitions without rewriting them. One possible solution is to provide a LangChain4jUtils utility or an integration module to automatically convert LangChain4j tools into AgentScope-compatible tools.
Expected usage:
Toolkit toolkit = new Toolkit();
LangChain4jUtils.registerTools(toolkit, myLangChain4jTools);
I can work on a small interoperability extension if this scope fits the maintainers' plans.
After checking both current APIs, I would keep LangChain4j out of agentscope-core and put the adapter in an optional extension. Toolkit.registerAgentTool(AgentTool) already provides the registration boundary. For annotated objects, LangChain4j's ToolService.findTools(...) returns the specification, bound executor and return behavior together; using it would preserve published names and inherited annotations without implementing a second reflection scanner. An overload accepting explicit AiServiceTool entries could support callers that already provide executors.
For the first slice, I suggest:
Convert the parameter schema explicitly, retaining required fields, nested objects, arrays, enums and references. Reject unsupported schema constructs instead of silently weakening validation.
Execute through the registered AgentTool so AgentScope's permission/group/middleware path remains in charge. Keep read-only false by default; a LangChain4j annotation alone should not grant permissions.
Preserve the call ID and distinguish tool error results from thrown execution failures. Define IMMEDIATE/return-direct mapping and document differences for mixed tool batches. Run synchronous executors on a bounded worker, not Reactor's event loop.
Add provider-free controls for renamed/inherited tools, argument conversion, duplicate names, error propagation and concurrent calls. Keep session/context mapping explicit; do not store a caller's RuntimeContext in a shared adapter.
This is an API/source-level proposal, not a tested adapter yet. I would leave automatic credential/context sharing, compensating actions and cross-framework agent orchestration out of the first PR. Would an optional extension focused on tool reuse be the preferred starting point?
It uses released LangChain4j 1.22.0 and AgentScope Core built from current main. All 19 tests pass, including real inherited/renamed annotated methods, nested record/enum/array execution through Toolkit, cancellation, worker offload and overlapping invocation contexts. The README includes reproduction commands and the compatibility limits.
Two decisions seem worth settling before an extension PR:
ToolService.findTools provides the bound discovery result, but is marked Internal in 1.22.0. Explicit AiServiceTool adaptation avoids that dependency; annotation discovery needs a supported entry point or a version policy.
IMMEDIATE can map to the tool's returnDirect flag, but IMMEDIATE_IF_LAST needs batch/order semantics that one boolean cannot express. The prototype rejects that mode, and unsupported multimodal results, rather than silently changing behavior.
Schema conversion uses ToolSpecification.toJson() and the existing AgentScope JSON codec, preserving strictness, raw constraints and references. Read-only remains false, execution/context mapping is explicit, and registration uses normal AgentTool entries. This is adapter/Toolkit verification; full ReAct permission/middleware and provider behavior still need integration coverage.
Would you prefer the first extension to accept explicit tools only, or include annotation discovery with a pinned LangChain4j compatibility policy?
I think this approach should align well with AgentScope's design philosophy. In my opinion, this API should provide clear and predictable semantics for users. We should avoid implicit conversions or silently changing behavior, and explicitly reject unsupported cases instea
I have moved the prototype into an optional extension in draft PR #4214.
The adapter now extends ToolBase: that matters on current main because legacy AgentTool objects bypass ReAct permission evaluation. The 22 provider-free tests include a denied call that never reaches the foreign executor, an allowed annotated tool returning the current session and call ID to the model, and structured error results reaching streaming events.
Following the predictable-semantics feedback, the first slice rejects both immediate return modes and non-text results. It keeps scheduler ownership and invocation-context mapping explicit. Core and agentscope-all do not acquire the LangChain4j dependency.
The draft exposes the remaining compatibility decision: annotated discovery uses the InternalToolService.findTools API from tested LangChain4j 1.22.0; applications can instead register bound AiServiceTool entries directly. EN/ZH user guides cover this boundary and the lifecycle limits.
Activity
CryoThrust commentedon Oct 14, 2026
I can work on a small interoperability extension if this scope fits the maintainers' plans.
After checking both current APIs, I would keep LangChain4j out of
agentscope-coreand put the adapter in an optional extension.Toolkit.registerAgentTool(AgentTool)already provides the registration boundary. For annotated objects, LangChain4j'sToolService.findTools(...)returns the specification, bound executor and return behavior together; using it would preserve published names and inherited annotations without implementing a second reflection scanner. An overload accepting explicitAiServiceToolentries could support callers that already provide executors.For the first slice, I suggest:
This is an API/source-level proposal, not a tested adapter yet. I would leave automatic credential/context sharing, compensating actions and cross-framework agent orchestration out of the first PR. Would an optional extension focused on tool reuse be the preferred starting point?
CryoThrust commentedon Oct 14, 2026
I put together a standalone, provider-free prototype to check the proposed tool boundary:
https://github.com/CryoThrust/agentscope-java/tree/bb451bf7ed995665e99ad69b044669300fd27588/prototypes/langchain4j-tool-interop
It uses released LangChain4j 1.22.0 and AgentScope Core built from current main. All 19 tests pass, including real inherited/renamed annotated methods, nested record/enum/array execution through Toolkit, cancellation, worker offload and overlapping invocation contexts. The README includes reproduction commands and the compatibility limits.
Two decisions seem worth settling before an extension PR:
ToolService.findToolsprovides the bound discovery result, but is markedInternalin 1.22.0. ExplicitAiServiceTooladaptation avoids that dependency; annotation discovery needs a supported entry point or a version policy.IMMEDIATEcan map to the tool's returnDirect flag, butIMMEDIATE_IF_LASTneeds batch/order semantics that one boolean cannot express. The prototype rejects that mode, and unsupported multimodal results, rather than silently changing behavior.Schema conversion uses
ToolSpecification.toJson()and the existing AgentScope JSON codec, preserving strictness, raw constraints and references. Read-only remains false, execution/context mapping is explicit, and registration uses normal AgentTool entries. This is adapter/Toolkit verification; full ReAct permission/middleware and provider behavior still need integration coverage.Would you prefer the first extension to accept explicit tools only, or include annotation discovery with a pinned LangChain4j compatibility policy?
wangx1nyi commentedon Oct 14, 2026
I think this approach should align well with AgentScope's design philosophy. In my opinion, this API should provide clear and predictable semantics for users. We should avoid implicit conversions or silently changing behavior, and explicitly reject unsupported cases instea
CryoThrust commentedon Nov 16, 2026
I have moved the prototype into an optional extension in draft PR #4214.
The adapter now extends
ToolBase: that matters on current main because legacyAgentToolobjects bypass ReAct permission evaluation. The 22 provider-free tests include a denied call that never reaches the foreign executor, an allowed annotated tool returning the current session and call ID to the model, and structured error results reaching streaming events.Following the predictable-semantics feedback, the first slice rejects both immediate return modes and non-text results. It keeps scheduler ownership and invocation-context mapping explicit. Core and
agentscope-alldo not acquire the LangChain4j dependency.The draft exposes the remaining compatibility decision: annotated discovery uses the
InternalToolService.findToolsAPI from tested LangChain4j 1.22.0; applications can instead register boundAiServiceToolentries directly. EN/ZH user guides cover this boundary and the lifecycle limits.