Hello Gokul Kolady, Yida Wu, Abhishek Rawat, Jason Fehr, Impala Public Jenkins,
I'd like you to reexamine a change. Please visit
https://gerrit.cloudera.org/25448
to look at the new patch set (#2).
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.
This patch changes the parser to return the whole serialized message
when "tool_calls" is an array and either it is non-empty or there is no
text "content". The agent loop already handles a bare message object, so
it now receives both the text and the tool_calls. When "tool_calls" is
missing or empty and "content" is text, the parser still returns only
the text, so ai_generate_text() behaves the same for requests without
tools.
Testing:
- Added unit tests in expr-test.
- 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, 55 insertions(+), 9 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/48/25448/2
--
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: newpatchset
Gerrit-Change-Id: Ib11531d7130bd718da1b2093a8ffbc06f2a84759
Gerrit-Change-Number: 25448
Gerrit-PatchSet: 2
Gerrit-Owner: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Abhishek Rawat <[email protected]>
Gerrit-Reviewer: Gokul Kolady <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Jason Fehr <[email protected]>
Gerrit-Reviewer: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Yida Wu <[email protected]>