Claus Ibsen created CAMEL-26202:
-----------------------------------
Summary: camel-langchain4j-agent - a file, bytes or stream body
without a user message header sends the content twice, and JSON files are
rejected
Key: CAMEL-26202
URL: https://issues.apache.org/jira/browse/CAMEL-26202
Project: Camel
Issue Type: Bug
Components: camel-langchain4j-agent
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while adding the catalog body types of langchain4j-agent (CAMEL-24961, PR
#28401).
h4. 1. A file, bytes or stream body without CamelLangChain4jAgentUserMessage
puts the content in the user message twice
{{LangChain4jAgentConverter.buildAiAgentBody}} (main 2a465aa4814c, line 469)
uses {{""}} as the default user message for a {{WrappedFile}}, {{byte[]}} or
{{InputStream}} body (lines 105 and 179). {{AgentWithoutMemory.chat}} (line 51)
then calls the AI service with an empty {{@UserMessage}} text plus the content,
and the user message the model receives holds the content twice, so the tokens
are doubled. Checked on 4.24.0-SNAPSHOT with a fake {{ChatModel}}
({{AgentWithoutMemory}}) and a text file body.
Proposed: when no user message is given, send only the content (no empty text
part), or use the content as the only user message.
h4. 2. An AiAgentBody with a blank user message and a content fails
An {{AiAgentBody}} with user message {{" "}} and a content fails in LangChain4j
with "template cannot be null or blank", while an empty user message is
accepted (see 1). Checked on 4.24.0-SNAPSHOT with a fake {{ChatModel}}.
Proposed: treat a blank user message like a missing one when a content is
present.
h4. 3. A .json file or JSON bytes fail with Unsupported MIME type
{{detectMimeTypeFromExtension}} (line 429) maps {{.json}} to
{{application/json}}, but {{createContent}} (line 254) accepts only
{{image/*}}, {{audio/*}}, {{video/*}}, {{application/pdf}} and {{text/*}}, so a
{{.json}} file (or bytes with {{Content-Type: application/json}}) fails with
"Unsupported MIME type: application/json". Checked on 4.24.0-SNAPSHOT with a
fake {{ChatModel}}.
Proposed: send {{application/json}} (and other textual types such as
{{application/xml}}) as {{TextContent}}.
h4. 4. No converter for java.io.File or java.nio.file.Path
{{LangChain4jAgentProducer}} (line 180) reads the body with
{{getMandatoryBody(AiAgentBody.class)}}; the converters cover {{WrappedFile}},
{{byte[]}}, {{InputStream}} and {{String}} but not a plain {{File}} or {{Path}}
body, so those fail with a no type conversion error. Checked on 4.24.0-SNAPSHOT
with a fake {{ChatModel}}.
Proposed: add {{File}} and {{Path}} converters that work like the
{{WrappedFile}} one (MIME type from the file name).
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)