Skip to content

Conversation

yxfengforever
Copy link

@yxfengforever yxfengforever commented Oct 10, 2025

Signed-off-by: Feng Xie[email protected]

Overview

The PR is to add a private method safelyMergeAssistantMessageIfEmptyToolCallPresent processes and merges tool calls in an AssistantMessage, particularly handling cases where tool calls might have empty name or fragmented arguments due to streaming or other processing issues.

Key Logic of safelyMergeAssistantMessageIfEmptyToolCallPresent

  • Reverses tool calls to process from last to first
  • Accumulates arguments in StringBuilder
  • Critical: StringUtils.hasText(toolCall.name()) check prevents invalid tool call exceptions
  • Only creates ToolCall objects when name has valid text content
  • Reverses processed tool calls back to original order

Safety Mechanism

StringUtils.hasText(toolCall.name()) serves as a guard to:

  • Prevent creating tool calls with null/empty names
  • Avoid downstream execution exceptions
  • Filter out malformed streaming data

Result

Returns new AssistantMessage with merged tool calls, preserving original content, media, and metadata.

Signed-off-by: Feng Xie<[email protected]>

Signed-off-by: yxloveforever <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants