Run streamed tool calls without an index or finished with stop on OpenAI-compatible

Closed
PC
23d ago
+95-3

Some OpenAI-compatible servers (non-OpenAI) stream tool call deltas without an index field, which made HandlesTextStreaming fail with Undefined array key "index". Others end a tool-calling turn with finish_reason: "stop" instead of "tool_calls", so the tool calls were never emitted and the agent returned empty text.

When index is missing, a delta starts a new tool call if it carries a new id, or a name when the previous call already had one.
Otherwise it continues the previous call.
Tool calls are now emitted on both tool_calls and stop, and the step finishes as ToolCalls. They are still discarded on length, since the arguments may be truncated.

I added three tests to OpenAiCompatibleTest: no index, ending in stop, and two parallel calls without index. The first two fail without this change.

šŸ¤– Generated with Claude Code