huggingface/smolagents · error · ValueError

Tool call index is not provided in tool delta: {tool_call_de

Error message

Tool call index is not provided in tool delta: {tool_call_delta}

What it means

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.

Source

Thrown at src/smolagents/models.py:258

                    if tool_call_delta.index not in accumulated_tool_calls:
                        accumulated_tool_calls[tool_call_delta.index] = ChatMessageToolCallStreamDelta(
                            id=tool_call_delta.id,
                            type=tool_call_delta.type,
                            function=ChatMessageToolCallFunction(name="", arguments=""),
                        )
                    # Update the tool call at the specific index
                    tool_call = accumulated_tool_calls[tool_call_delta.index]
                    if tool_call_delta.id:
                        tool_call.id = tool_call_delta.id
                    if tool_call_delta.type:
                        tool_call.type = tool_call_delta.type
                    if tool_call_delta.function:
                        if tool_call_delta.function.name and len(tool_call_delta.function.name) > 0:
                            tool_call.function.name = tool_call_delta.function.name
                        if tool_call_delta.function.arguments:
                            tool_call.function.arguments += tool_call_delta.function.arguments
                else:
                    raise ValueError(f"Tool call index is not provided in tool delta: {tool_call_delta}")

    return ChatMessage(
        role=role,
        content=accumulated_content,
        tool_calls=[
            ChatMessageToolCall(
                function=ChatMessageToolCallFunction(
                    name=tool_call_stream_delta.function.name,
                    arguments=tool_call_stream_delta.function.arguments,
                ),
                id=tool_call_stream_delta.id or "",
                type="function",
            )
            for tool_call_stream_delta in accumulated_tool_calls.values()
            if tool_call_stream_delta.function
        ],
        token_usage=TokenUsage(
            input_tokens=total_input_tokens,

View on GitHub (pinned to 30bb116109)

Solutions

  1. Disable streaming for that model (use non-streaming mode, e.g. stream=False / non-stream run) where deltas are not aggregated
  2. Switch to a provider/model whose streaming tool-call deltas include index (OpenAI-conformant)
  3. Update smolagents in case a newer release tolerates missing index
  4. Report the provider's delta payload shape to smolagents maintainers

Example fix

# before
agent = CodeAgent(tools=[], model=MyOpenAICompatibleModel(stream=True))
agent.run(task, stream=True)

# after
agent = CodeAgent(tools=[], model=MyOpenAICompatibleModel())
agent.run(task)  # non-streaming path avoids delta aggregation
Defensive patterns

Strategy: fallback

Validate before calling

def deltas_have_index(deltas) -> bool:
    return all(getattr(tc, 'index', None) is not None for d in deltas for tc in (d.tool_calls or []))

Type guard

def is_conformant_tool_delta(delta) -> bool:
    tc = getattr(delta, 'tool_calls', None)
    return tc is None or all(t.index is not None or t.id for t in tc)

Try / catch

from smolagents.models import agglomerate_stream_deltas
try:
    message = agglomerate_stream_deltas(deltas)
except ValueError as e:
    if 'Tool call index is not provided' in str(e):
        message = model.non_stream_completion(...)  # fall back to non-streaming

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/947b832390c85cf5. Report an issue: GitHub.