Implementation:Cohere ai Cohere python ToolCallDelta Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Streaming, Function Calling |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
ToolCallDelta is a Pydantic model representing a streaming chunk of a tool call being generated, containing partial data for the tool name, index, parameters, and plan text.
Description
The ToolCallDelta model encapsulates an incremental chunk of a tool call during streaming chat responses. When the Cohere Chat API is used with stream=True and the model generates tool calls, the tool call data arrives in pieces via ToolCallDelta objects embedded within ToolCallsChunkStreamedChatResponse events.
Each delta may contain partial data for:
name-- A chunk of the tool call name (typically sent in the first delta).index-- The index of the tool call being generated (identifies which tool call in a multi-call scenario).parameters-- A chunk of the tool parameters as a string (JSON fragments that must be concatenated).text-- A chunk of the tool plan text the model is generating alongside the tool call.
All fields are optional since each streaming chunk contains only the data that has changed.
Usage
Use ToolCallDelta when consuming streaming chat responses that involve function calling. Accumulate the chunks by index to reconstruct the complete tool call name, parameters, and plan text.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/tool_call_delta.py
Signature
class ToolCallDelta(UncheckedBaseModel):
name: typing.Optional[str] = pydantic.Field(default=None)
index: typing.Optional[float] = pydantic.Field(default=None)
parameters: typing.Optional[str] = pydantic.Field(default=None)
text: typing.Optional[str] = pydantic.Field(default=None)
Import
from cohere.types import ToolCallDelta
I/O Contract
Fields
| Field | Type | Required | Description |
|---|---|---|---|
name |
Optional[str] |
No | Chunk of the tool call name. |
index |
Optional[float] |
No | Index of the tool call being generated (for multi-call scenarios). |
parameters |
Optional[str] |
No | Chunk of the tool parameters as a JSON string fragment. |
text |
Optional[str] |
No | Chunk of the tool plan text. |
Usage Examples
import json
from cohere.types import ToolCallDelta
# Accumulate tool call deltas during streaming
stream = client.chat_stream(
message="What is the weather in London and Paris?",
tools=[weather_tool]
)
tool_calls = {} # index -> {name, parameters_str, text}
for event in stream:
if event.event_type == "tool-calls-chunk":
delta = event.tool_call_delta
idx = delta.index
if idx is not None:
if idx not in tool_calls:
tool_calls[idx] = {"name": "", "parameters_str": "", "text": ""}
if delta.name:
tool_calls[idx]["name"] += delta.name
if delta.parameters:
tool_calls[idx]["parameters_str"] += delta.parameters
if delta.text:
tool_calls[idx]["text"] += delta.text
elif event.event_type == "stream-end":
break
# Parse the accumulated tool calls
for idx, call_data in tool_calls.items():
name = call_data["name"]
parameters = json.loads(call_data["parameters_str"])
print(f"Tool call {idx}: {name}({parameters})")