k-krawczyk opened a new pull request, #24062:
URL: https://github.com/apache/camel/pull/24062
### CAMEL-23704
`LangChain4jToolsProducer.invokeTools()` reused a single `Exchange` across
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
- Snapshot the original incoming exchange once (`toolsChat`) and reuse it as
a clean **baseline** across all LLM iterations.
- Invoke each tool on its **own independent copy** of that baseline
(`ExchangeHelper.createCopy`), mirroring the multicast/splitter isolation
pattern.
- Copy each tool's outcome back onto the parent exchange with
`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").
- Exceptions are kept on the tool's own exchange and propagated to the
parent without affecting sibling tools.
#### 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
`LangChain4jToolMultipleCallsTest` previously 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 in `050af78ca`). It has
been updated to assert isolation: each tool sees its own argument headers, does
**not** inherit the previous tool's `name` header, and receives the original
incoming body.
#### Testing
`mvn test -pl components/camel-ai/camel-langchain4j-tools` — all green (38
tests).
_Reported by Claude Code on behalf of Karol Krawczyk_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]