mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-11-03 12:33:15 +00:00
NewBodyPair collects the indices of ToolCall parts with a nil FunctionCall into partsToDelete, then deletes them in a forward loop using those pre-collected ascending indices. Each deletion shifts every later element left by one, so with two or more collected indices the second and subsequent deletions remove the wrong elements: a valid TextContent can be dropped while an invalid nil-FunctionCall tool call survives into the message chain (feeding malformed messages downstream). Iterate the collected indices in reverse so earlier indices stay valid during deletion. Adds a regression test covering two leading nil-FunctionCall tool calls followed by a text part.