{"record":{"id":"947b832390c85cf5","repo":"huggingface/smolagents","slug":"tool-call-index-is-not-provided-in-tool-delta-to","errorCode":null,"errorMessage":"Tool call index is not provided in tool delta: {tool_call_delta}","messagePattern":"Tool call index is not provided in tool delta: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/models.py","lineNumber":258,"sourceCode":"                    if tool_call_delta.index not in accumulated_tool_calls:\n                        accumulated_tool_calls[tool_call_delta.index] = ChatMessageToolCallStreamDelta(\n                            id=tool_call_delta.id,\n                            type=tool_call_delta.type,\n                            function=ChatMessageToolCallFunction(name=\"\", arguments=\"\"),\n                        )\n                    # Update the tool call at the specific index\n                    tool_call = accumulated_tool_calls[tool_call_delta.index]\n                    if tool_call_delta.id:\n                        tool_call.id = tool_call_delta.id\n                    if tool_call_delta.type:\n                        tool_call.type = tool_call_delta.type\n                    if tool_call_delta.function:\n                        if tool_call_delta.function.name and len(tool_call_delta.function.name) > 0:\n                            tool_call.function.name = tool_call_delta.function.name\n                        if tool_call_delta.function.arguments:\n                            tool_call.function.arguments += tool_call_delta.function.arguments\n                else:\n                    raise ValueError(f\"Tool call index is not provided in tool delta: {tool_call_delta}\")\n\n    return ChatMessage(\n        role=role,\n        content=accumulated_content,\n        tool_calls=[\n            ChatMessageToolCall(\n                function=ChatMessageToolCallFunction(\n                    name=tool_call_stream_delta.function.name,\n                    arguments=tool_call_stream_delta.function.arguments,\n                ),\n                id=tool_call_stream_delta.id or \"\",\n                type=\"function\",\n            )\n            for tool_call_stream_delta in accumulated_tool_calls.values()\n            if tool_call_stream_delta.function\n        ],\n        token_usage=TokenUsage(\n            input_tokens=total_input_tokens,","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/models.py#L240-L276","documentation":"agglomerate_stream_deltas merges incremental streaming chunks from chat models into one ChatMessage; tool-call deltas are matched to accumulated tool calls by their index field. If a provider emits a tool_call delta with no index (and no id, which would start a new tool call), the function cannot know which call to append to and raises ValueError showing the offending delta. This indicates a non-conformant streaming payload.","triggerScenarios":"Streaming responses from a model/provider whose tool_call chunks omit the index field (only id and index are recognized as call-start/new-call markers in models.py:258's logic).","commonSituations":"Switching a CodeAgent to a third-party OpenAI-compatible endpoint that streams tool calls slightly non-conformantly; proxies or gateways stripping fields from deltas; newer/older provider API versions changing the delta shape.","solutions":["Disable streaming for that model (use non-streaming mode, e.g. stream=False / non-stream run) where deltas are not aggregated","Switch to a provider/model whose streaming tool-call deltas include index (OpenAI-conformant)","Update smolagents in case a newer release tolerates missing index","Report the provider's delta payload shape to smolagents maintainers"],"exampleFix":"# before\nagent = CodeAgent(tools=[], model=MyOpenAICompatibleModel(stream=True))\nagent.run(task, stream=True)\n\n# after\nagent = CodeAgent(tools=[], model=MyOpenAICompatibleModel())\nagent.run(task)  # non-streaming path avoids delta aggregation","handlingStrategy":"fallback","validationCode":"def deltas_have_index(deltas) -> bool:\n    return all(getattr(tc, 'index', None) is not None for d in deltas for tc in (d.tool_calls or []))","typeGuard":"def is_conformant_tool_delta(delta) -> bool:\n    tc = getattr(delta, 'tool_calls', None)\n    return tc is None or all(t.index is not None or t.id for t in tc)","tryCatchPattern":"from smolagents.models import agglomerate_stream_deltas\ntry:\n    message = agglomerate_stream_deltas(deltas)\nexcept ValueError as e:\n    if 'Tool call index is not provided' in str(e):\n        message = model.non_stream_completion(...)  # fall back to non-streaming","preventionTips":["Use non-streaming mode with providers whose deltas omit index","Test streaming tool-calls against a new provider before enabling it in production","Pin provider API versions you've verified conform"],"tags":["smolagents","streaming","tool-calls","provider-compatibility"],"backgroundTag":"malformed-streaming-delta","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}