CAMEL-23704: Use isolated exchange copy per tool in langchain4j-tools#24062
Open
k-krawczyk wants to merge 1 commit into
Open
CAMEL-23704: Use isolated exchange copy per tool in langchain4j-tools#24062k-krawczyk wants to merge 1 commit into
k-krawczyk wants to merge 1 commit into
Conversation
Contributor
Author
|
cc @Croway @davsclaus for review — you're the most active committers on Reported by Claude Code on behalf of Karol Krawczyk |
1d19432 to
f4f5433
Compare
When the LLM requests multiple tool invocations within a single request, each tool is now invoked on its own independent copy of the original incoming exchange (a baseline snapshot reused across all iterations), instead of sharing a single exchange across all tools. This prevents the message body, argument headers and exceptions produced by one tool from leaking into sibling tool invocations. Each tool's outcome is copied back onto the parent exchange so the producer output still reflects the (last) tool result together with its declared argument headers.
f4f5433 to
0b2955e
Compare
Contributor
Author
|
Rebased onto current Reported by Claude Code on behalf of Karol Krawczyk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CAMEL-23704
LangChain4jToolsProducer.invokeTools()reused a singleExchangeacross all tool invocations within a request. As a result, one tool's message body, accumulated argument headers, and exceptions leaked into subsequent tool invocations.Changes
toolsChat) and reuse it as a clean baseline across all LLM iterations.ExchangeHelper.createCopy), mirroring the multicast/splitter isolation pattern.ExchangeHelper.copyResults, so the producer output still reflects the (last) tool's result body and declared argument headers — no accumulation across tools ("last tool wins").Behavior change
A tool route no longer receives the previous tool's output as its body, nor the previous tool's argument headers. Documented in the 4.21 upgrade guide.
Note on the test
LangChain4jToolMultipleCallsTestpreviously asserted that the second tool's body contained the first tool's output — i.e. it codified the exact leak this ticket reports (the loop and the test both landed in050af78ca). It has been updated to assert isolation: each tool sees its own argument headers, does not inherit the previous tool'snameheader, and receives the original incoming body.Relation to CAMEL-21937
This change was rebased on top of CAMEL-21937 (Reset route stop flag between tool invocations). The per-tool exchange isolation introduced here subsumes the per-iteration
ROUTE_STOPreset from that fix — since every tool now runs on its own copy of the baseline exchange, astop()in one tool route can no longer reach sibling tools, so that per-iteration reset was removed as dead code. The post-loopexchange.setRouteStop(false)is kept, becauseExchangeHelper.copyResultspropagates the last tool'srouteStoponto the parent exchange and it must not leak into the calling route.LangChain4jToolStopEipTestcontinues to pass.Testing
mvn test -pl components/camel-ai/camel-langchain4j-tools— all green (39 tests, includingLangChain4jToolStopEipTest).Reported by Claude Code on behalf of Karol Krawczyk