CAMEL-23951: Expose agent Result sources and tool executions as headers#24917
CAMEL-23951: Expose agent Result sources and tool executions as headers#24917atiaomar1978-hub wants to merge 3 commits into
Conversation
Populate CamelLangChain4jAgentSources and CamelLangChain4jAgentToolExecutions from LangChain4j Result metadata alongside existing token usage headers. Co-Authored-By: Cursor <cursoragent@cursor.com>
gnodet
left a comment
There was a problem hiding this comment.
Clean, well-structured change that completes the agent Result metadata exposure started in CAMEL-23860.
What's good:
- Follows the established pattern: The null/empty guards (
result.sources() != null && !result.sources().isEmpty()) are exactly consistent with the existingfinishReasonandtokenUsageguards — no surprises for anyone who's read this code before. - Good method rename:
populateTokenUsageHeaders→populateResultHeaderscorrectly reflects the broader scope now that it handles finish reason, token usage, sources, and tool executions. - Proper
@Metadataannotations: Both constants includejavaTypewith the full generic signature (java.util.List<dev.langchain4j.rag.content.Content>) — this drives correct catalog and endpoint DSL generation. - Native objects, not serialized strings: Storing
ContentandToolExecutiondirectly on headers (same approach asFinishReason) lets downstream processors inspect the rich object model without parsing. - Thorough test coverage: 5 test cases cover the full matrix — all present, both empty, both absent, sources-only, tools-only. The
assertSamechecks confirm objects are passed through directly, not defensively copied (correct for immutable LangChain4j types). - Upgrade guide: Concise note in the right section.
No issues found. LGTM.
Claude Code on behalf of gnodet — AI-generated review
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
There are uncommitted changes |
|
@davsclaus I will fix. and will resolve conflicts. |
Fix uncommitted generated changes in LangChain4jAgentEndpointBuilderFactory detected by CI sourcecheck. Co-Authored-By: Cursor <cursoragent@cursor.com>
gnodet
left a comment
There was a problem hiding this comment.
Commit 29f3dd624bd8 — regenerated endpoint DSL Javadoc formatting (line wrapping). No behavioral change; prior review still applies.
Claude Code on behalf of gnodet — AI-generated review
|
@davsclaus conflicts have been resolved , Please run the CI build and tests when you have chance. |
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 13 tested, 26 compile-only — current: 10 all testedMaveniverse Scalpel detected 39 affected modules (current approach: 10).
|
|
@davsclaus Please re-run the CI/build and tests again. I have merged main into this branch. |
Branch:
CAMEL-23951-agent-sources-tool-headersCommit:
f09c3fd4dc17PR link: https://github.com/atiaomar1978-hub/camel/pull/new/CAMEL-23951-agent-sources-tool-headers
Summary (for PR description)
CAMEL-23951: Expose agent
Result.sources()andResult.toolExecutions()as message headersThe langchain4j-agent producer already mapped
Result.content(), finish reason, and token usage to exchange headers (CAMEL-23860). RAG sources and tool execution details from the LangChain4jResultwere dropped, which limited observability, auditing, and downstream routing.This change adds two new output headers, following the same null/empty guard pattern as the existing metadata headers:
CamelLangChain4jAgentSourcesList<dev.langchain4j.rag.content.Content>Result.sources()CamelLangChain4jAgentToolExecutionsList<dev.langchain4j.service.tool.ToolExecution>Native LangChain4j objects are stored on the exchange (same approach as
FinishReasonand chat’s RAG input header), not JSON-serialized strings.Changes
Headers.java— newSOURCESandTOOL_EXECUTIONSconstants with@MetadataLangChain4jAgentProducer.java—populateTokenUsageHeadersrenamed topopulateResultHeaders; sources and tool executions populated when presentLangChain4jAgentResultHeadersTest.java— 5 unit tests covering full metadata, empty lists, absent fields, sources-only, and tools-onlycamel-langchain4j-agentincamel-4x-upgrade-guide-4_22.adocTest plan
LangChain4jAgentResultHeadersTest— 5/5 passedcamel-langchain4j-agentmodule tests in CI