Quanlong Huang has uploaded this change for review. ( 
https://gerrit.cloudera.org/25448


Change subject: IMPALA-15804: Keep tool_calls when AI response also has text 
content
......................................................................

IMPALA-15804: Keep tool_calls when AI response also has text content

The "Generate AI Analysis" WebUI page runs a tool-calling loop in
RunAiAgentWithToolExecutor(). Each round sends the conversation to the
AI engine and continues only if the assistant message has a non-empty
"tool_calls" array.

AiFunctions::AiGenerateTextParseOpenAiResponse() returned the message
"content" whenever it was a string, and only returned the whole message
(including "tool_calls") when "content" was not a string. That works for
models that set content=null on tool-calling turns. Other models, e.g.
Claude through an OpenAI-compatible gateway such as LiteLLM, return a
short text preamble together with tool_calls, which is valid in the
OpenAI Chat Completions format. For those responses the parser returned
only the preamble and dropped the tool_calls. The agent loop then could
not parse a message, treated the preamble as the final answer and
stopped after the first round. The page showed only text like "I'll
start with the timeline, the fragment overview and the scan summary."

This patch checks for a non-empty "tool_calls" array first and returns
the serialized message in that case, so both the text and the tool_calls
reach the agent loop, which already handles a bare message object. All
other cases work as before, so ai_generate_text() is unchanged for
requests without tools.

Testing:
- Added a test case in expr-test for a response with both content and
  tool_calls.
- Manually verified that "Generate AI Analysis" completes a multi-round
  analysis using Claude through a LiteLLM gateway.

Assisted-by: Claude Opus 5.5 (Claude Code)
Change-Id: Ib11531d7130bd718da1b2093a8ffbc06f2a84759
---
M be/src/exprs/ai-functions-ir.cc
M be/src/exprs/expr-test.cc
2 files changed, 39 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/48/25448/1
-- 
To view, visit https://gerrit.cloudera.org/25448
To unsubscribe, visit https://gerrit.cloudera.org/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib11531d7130bd718da1b2093a8ffbc06f2a84759
Gerrit-Change-Number: 25448
Gerrit-PatchSet: 1
Gerrit-Owner: Quanlong Huang <[email protected]>

Reply via email to