Implementation:Cohere ai Cohere python ToolCall Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Function Calling |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
ToolCall is a Pydantic model representing a model-generated tool call request, containing the tool name and the parameters to invoke it with.
Description
The ToolCall model encapsulates a function call generated by the Cohere chat model during the function calling workflow. When tools are provided to the Chat API and the model determines that a tool should be invoked, it returns one or more ToolCall objects.
Each ToolCall contains:
name-- The name of the tool to invoke, matching one of the tool definitions provided in the request.parameters-- A dictionary of parameter name-value pairs to pass to the tool function.
The model extends UncheckedBaseModel and allows extra fields.
Usage
Use ToolCall when processing chat responses that include function calling. After receiving tool calls from the model, use the name to dispatch to the appropriate function and pass the parameters as arguments. Then submit the tool results back to the model to continue the conversation.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/tool_call.py
Signature
class ToolCall(UncheckedBaseModel):
name: str = pydantic.Field()
parameters: typing.Dict[str, typing.Any] = pydantic.Field()
Import
from cohere.types import ToolCall
I/O Contract
Fields
| Field | Type | Required | Description |
|---|---|---|---|
name |
str |
Yes | Name of the tool to call. Matches a tool name from the tool definitions provided in the request. |
parameters |
Dict[str, Any] |
Yes | The name-value pairs of parameters to use when invoking the tool. |
Usage Examples
from cohere.types import ToolCall, Tool
# Define tools and make a chat request
tools = [
Tool(
name="search_database",
description="Search a product database by query.",
parameter_definitions={
"query": {"description": "Search query", "type": "str", "required": True}
}
)
]
response = client.chat(
message="Find me running shoes",
tools=tools
)
# Process tool calls from the response
if response.tool_calls:
for tool_call in response.tool_calls:
print(f"Tool: {tool_call.name}")
print(f"Parameters: {tool_call.parameters}")
# Dispatch to the appropriate function
if tool_call.name == "search_database":
result = search_database(**tool_call.parameters)
# Submit tool results back to the model
response = client.chat(
message="Find me running shoes",
tools=tools,
tool_results=[{
"call": tool_call,
"outputs": [result]
}]
)