Implementation:Cohere ai Cohere python Tool Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Function Calling |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Tool is a Pydantic model representing a tool definition schema that the Cohere chat model can invoke during function calling.
Description
The Tool model defines a callable tool that can be provided to the Cohere Chat API. The model uses the tool's name and description to determine when and how to call the function. The parameter_definitions field specifies the input parameters the tool accepts.
Key details:
- name -- Must contain only characters
a-z,A-Z,0-9,_and must not begin with a digit. - description -- Used by the model to decide when to invoke the tool, so it should clearly describe the tool's purpose.
- parameter_definitions -- A dictionary mapping parameter names to
ToolParameterDefinitionsValueobjects, each specifying a description, type (any Python data type string such as'str','bool'), and whether the parameter is required. Parameter names follow the same naming rules as tool names.
The model extends UncheckedBaseModel and allows extra fields.
Usage
Use Tool when defining tools for the Cohere Chat API's function calling feature. Provide a list of Tool objects to enable the model to generate ToolCall requests that your application can execute.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/tool.py
Signature
class Tool(UncheckedBaseModel):
name: str = pydantic.Field()
description: str = pydantic.Field()
parameter_definitions: typing.Optional[
typing.Dict[str, ToolParameterDefinitionsValue]
] = pydantic.Field(default=None)
Import
from cohere.types import Tool
I/O Contract
Fields
| Field | Type | Required | Description |
|---|---|---|---|
name |
str |
Yes | The name of the tool. Valid names contain only a-z, A-Z, 0-9, _ and must not begin with a digit.
|
description |
str |
Yes | Description of what the tool does. The model uses this to decide when and how to call the function. |
parameter_definitions |
Optional[Dict[str, ToolParameterDefinitionsValue]] |
No | Input parameters for the tool. Keys are parameter names; values define the parameter spec (description, type, required). |
ToolParameterDefinitionsValue Structure
| Key | Type | Description |
|---|---|---|
description |
str |
Description of the parameter. |
type |
str |
Any Python data type as a string (e.g., 'str', 'bool', 'int').
|
required |
bool |
Whether the parameter is required. |
Usage Examples
from cohere.types import Tool
# Define a tool for looking up weather data
weather_tool = Tool(
name="get_weather",
description="Gets the current weather for a given city.",
parameter_definitions={
"city": {
"description": "The city to get weather for",
"type": "str",
"required": True
},
"units": {
"description": "Temperature units: 'celsius' or 'fahrenheit'",
"type": "str",
"required": False
}
}
)
# Use the tool in a chat request
response = client.chat(
message="What is the weather in San Francisco?",
tools=[weather_tool]
)
# Check if the model generated tool calls
if response.tool_calls:
for call in response.tool_calls:
print(f"Call: {call.name}({call.parameters})")