Skip to content

feat(tools): add optional LangChain4j tool interoperability - #4214

Draft
CryoThrust wants to merge 2 commits into
agentscope-ai:mainfrom
CryoThrust:feat/langchain4j-tool-interop
Draft

CryoThrust wants to merge 2 commits into
agentscope-ai:mainfrom
CryoThrust:feat/langchain4j-tool-interop

Conversation

@CryoThrust

Copy link
Copy Markdown
Contributor

Refs #3542.

Applications with existing LangChain4j tools currently need to rewrite their tool bindings to use them with an AgentScope agent. This adds an optional agentscope-extensions-langchain4j module that registers the original bound executors in a Toolkit. Core stays independent of LangChain4j, and the extension is BOM-managed without being added to agentscope-all.

The adapter preserves published names, parameter schemas, call IDs, invocation context and structured text-result states. Synchronous calls run on a caller-owned scheduler. The tools extend ToolBase, so the agent's permission engine gates execution; foreign annotations do not grant read-only permissions or parallel-execution safety. EN/ZH guides explain registration, scheduler ownership and session mapping.

Only TO_LLM return behavior is supported. Both immediate modes and non-text results fail explicitly because silently mapping them would change execution semantics. Annotated discovery uses ToolService.findTools, marked Internal in LangChain4j 1.22.0. This draft pins that tested version and also offers explicit AiServiceTool registration; the discovery/version policy remains a review decision.

Validation:

  • 22 provider-free tests pass, including actual annotated execution, schema validation, cancellation, overlapping invocation contexts, ReAct permission denial, model round trips and streaming error-state propagation.
  • Core's test reactor passes (3,449 cases, 11 skips); documentation tests, strict build validation, broken-link checks and extension/BOM synchronization pass.
  • Full clean verify encountered truncated Tika/Node downloads; its other executed modules passed. After recovering those downloads, verification passes for RAG Simple, Paw, agentscope-all and the documentation examples. This is split recovery evidence, not a single successful full-reactor invocation.
mvn -B -T1C -pl agentscope-extensions/agentscope-extensions-langchain4j -am test spotless:check
bash .github/scripts/check-shade-and-bom-sync.sh
cd docs
npm test
npm run validate
npm run broken-links

@mintlify

mintlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 5929769.

Approve preview

@CryoThrust

Copy link
Copy Markdown
Contributor Author

CI on d5afe9e has finished. Windows, the license/CLA checks, module sync and documentation validation passed. The new LangChain4j extension also passed in the Linux reactor.

Linux failed in the existing ProcessRecoveryTest.replacementCollectsOriginalResultWithoutRepeatingEffect("during-tool"): line 254 expected two model calls and observed three. The durable adapter module reported 60 tests with one failure. Failing job.

This PR does not change that recovery path, but I have not reproduced the Linux failure on the base branch, so I cannot yet classify it as an unrelated flake. GitHub denied my attempt to rerun the failed job because I lack repository admin rights. Could a maintainer rerun that job on the unchanged commit? I will keep this draft until the remaining checks and the discovery API question are resolved.

@CryoThrust

CryoThrust commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I tried a base/head comparison in an isolated Linux ARM64 container (Ubuntu 26.04, Temurin 17, Maven 3.9.9, 2 CPUs/4 GB, Python 3 installed). This is not the same environment as GitHub's amd64 runner.

On base 30dc84b59, both ProcessRecoveryTest cases pass with no skips. On unchanged PR head d5afe9e, during-tool passes, while after-accept times out waiting for the first child process at line 235. That is a different failure from CI's extra-model-call assertion at line 254; I have not reproduced the original failure or established its cause.

I retained the test reports, child logs and SQLite fixtures. No durable implementation, assertions or timeouts were changed. The draft and request for a maintainer rerun of the original failed job remain in place.

Additional baseline observation: the Linux job for the docs-only PR #4216, based on 5525ac1aa, ran both ProcessRecoveryTest cases with 2 tests, 0 failures/errors/skips. This confirms they executed rather than being excluded in that successful run. It does not explain the earlier failure on this PR or establish that it is resolved.

Hosted Linux comparison

The unchanged PR head now passes the full upstream Linux PR build on ubuntu-latest / Temurin 17: the downloaded XML reports contain 13,118 tests, zero failures/errors and 196 skips. LangChain4jToolsTest passes all 19 cases. ProcessRecoveryTest passes both cases in that build and in five subsequent focused runs, with no skips (12 executions including the full build). Head reports.

The exact original base, 30dc84b59, also passes those 12 process-recovery executions, but its full reactor fails in RocketMqExecutionTest.agentScopeResumesThroughSeparateLedgersDespitePublicationAndAckFailures: WAITING, one model call, three command ACKs, seven event ACKs and an empty event queue. That baseline already includes #4176; I reported this distinct post-fix timeout at #4175 (comment) . The overall comparison run therefore correctly remains failed, despite the successful head job.

No production or test source, assertions, lease durations or wait budgets changed. Failed JUnit temporary directories were retained for diagnosis. This is new fork-run evidence on the same feature commit, not a successful rerun of the original upstream job. Its extra-model-call failure is still unexplained; the maintainer rerun request and draft/API-placement question remain open.

xzxiaoshan added a commit that referenced this pull request Nov 20, 2026
…#4274)

## Background

Swept the last 125 PRs (#4272→#4075) for single-OS CI failures under
`mvn -B -T1C clean verify` (one build OS red, the other green on the
same commit = flake suspect). Cross-PR repeats and main's own red run on
2026-11-19 (ubuntu, run 44516464414) pinpoints four still-broken test
classes; all fixes are test-side only (no `src/main` changes).

## Fixes and evidence

| Test class | Victims | Signature | Fix |
|---|---|---|---|
| `RocketMqExecutionTest` | #4182, #4192, #4103 + main run 44516464414
(2026-11-19, ubuntu) | `turn reaches SUCCEEDED did not become true
within 10s` while the turn kept progressing (modelCalls complete, acks
climbing, lastFailure=none) — deadline breakthrough under starvation,
not a lost turn | shared `waitUntil` deadline 10s→30s (repo tier
#3726/#3774) |
| `AgentScopeAdapterTest` | #4204 (same-commit re-run green = confirmed
flake), #4191, #4246 | `Timed out observing Turn` at 6.7–8.5s elapsed;
resume/recovery one step from terminal | `turn.await(5s)`→30s at all 3
sibling sites via `TURN_DEADLINE`, outer `get` budgets +5s margin |
| `WorkerRuntimeTest` | #4219, #4224, #4255 (windows) | (a) `Worker
lease lost` after 2.4s — 1s claim leases expired between claim and
release; (b) `renewed.await(5s)` missed at 6.5s while the recovery lane
was healthy; (c) `Interrupted sleep interrupted` —
`WorkerRuntime.process()` interrupts the calling thread on lease-renewal
failure and manual `tick()` runs it on the test thread | (a) claim
leases 1s→30s (staleness under test still comes from `release(ZERO)` +
re-claim); (b) latches 5s→30s; (c) raw `Thread.sleep`→interrupt-proof
`pause()` at 5 sites, mirroring the #4176 fix for the same signature in
`ProcessRecoveryTest` |
| `ChatSessionsTest.await` (shared with `ChatControllerTest`) | #4233,
#4182 (stuck-RUNNING at 40.8s/46.4s), #4268, #4163 (poll threw `Durable
database transaction failed`) | two surfaces of one cause: every
snapshot poll opens a writing sqlite transaction contending with the
runtime's own writes, and windows runners starve turns past 30s (same
file already measured 56.6s starvation and uses 120s elsewhere, #3726) |
deadline 30s→120s (aligned tier) + tolerate transient `UNAVAILABLE`
store exceptions while polling; persistent failure rethrows at the
deadline, FAILED-turn fast-fail unchanged |
| `CommandExecutorTest.missingExitCodeIsUnknown` | local -T2C full-repo
stress (2026-11-19; pristine-main baseline of the same class green) |
the 2s network budget fired on scheduler starvation before the instant
fake response was processed, misclassifying the failure as a deadline
miss instead of a missing exit code (2.97s elapsed) | budget 2s→30s for
this non-deadline-semantics test; the two deadline-semantics tests keep
their tight budgets |

## Constraint compliance

- Happy path zero cost: every change only extends failure-path deadlines
or hardens helpers; no new sleeps, no weakened assertions.
- Minimal widening anchored to measured data (each comment cites victims
+ measured values); 30s follows the repo's established deflake tier,
120s follows this file's own previously measured starvation tier.
- Structural hardening preferred: `pause()` helper, transient-lock
retry, lease decoupling from the tested invariant.
- No `src/main` changes.

## Observed but deliberately not fixed here

-
`ProcessRecoveryTest.replacementCollectsOriginalResultWithoutRepeatingEffect`
(#4214: `expected: 2 but was: 3`): recovery-semantics race (model re-run
without effect re-run after abrupt halt) — a product question for the
durable recovery work, not a deadline flake.
-
`JevEvidenceProcessorTest.filterFailureIsWithheldButRankFailureFollowsScoredEvidence`
(#4265: delivered `[]` on a 25×-slowed runner): root cause not
established; single occurrence.
- Already fixed upstream, victims predate the fix:
`AgentScopeAgentExecutorInputRequiredTest` (#4157/#4187/#4152 all
predate #4176's `BaseReActAgentRunner` change), `InboxMiddlewareTest`
(#4093 predates #3738), `HarnessAgentSubagentStreamEventsTest` (#4183
predates #2917).
- `SkillBoxTest$UploadContainment` quartet (#4201/#4202/#4212/#4229):
test does not exist on main (fork stack only); deterministic cross-drive
path bug, not load flakiness.
- #4184/#4185: both-OS compile breaks from dependency major bumps
(dependabot), out of scope.

Also applied during review: sibling sites with the identical measured
mechanism were widened in the same pass — the remaining 1s fixture claim
leases in `WorkerRuntimeTest` (fenced begin/update/release sequences,
same #4219 signature), the start/PAUSED 5s budgets in the same
`AgentScopeAdapterTest` method as the victims, and the 5s/4s observe
budgets in
`completeLocalBackendRunsNativeAgentWhileManagedObserverIsBlocked`.

## Test plan

- [x] Full local `mvn -B -T2C clean verify` green (stricter than CI's
-T1C). Locally excluded, each verified to fail identically on pristine
main on this machine (Windows/git-bash) while passing on CI:
`JsonFileAgentStateStoreTest` (symlink permissions), the
`agentscope-extensions-durable-sandbox` trio plus
`ToolInSandboxExampleTest`/`SandboxRoundTripTest` (sandbox shell heredoc
incompatible with local git-bash python3), and the
`AgentScopeAdapterTest`/`ProcessRecoveryTest`/`HarnessExternalToolProcessRecoveryTest`
trio (durable-adapter classes whose Windows runs are skipped on CI; the
same named tests fail on pristine main locally).
- [ ] CI green on both OS.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants