Parameter Types in Tool Use
Cohere’s tool use feature is available in the chat endpoint via the API and all of our SDKs (Python, Typescript, Java, Go). The functionality relies on Python type notation to define parameters. Parameters are the inputs that a tool or function needs to operate. With this approach there is flexibility to use any Python type as a definition for these parameters. This includes basic types like integers, floats, and strings, as well as more complex types such as lists, dictionaries, and dataclasses.
Additionally, the default value for optional parameters can be provided, which will be used if no value is specified when the function is called. It is also possible to define enumerations (enums) to specify a set of valid values for a parameter, restricting the input to a predefined list of options.
Below are some examples that illustrate how to define parameters using Python types, defaults, and enums.
Example - JSON Schema Type Conversion
Example – Simple types
Example – Arrays
With specific element types
Without specific element types
Example – Enumerated values (enums)
To make sure a tool only accepts certain values you can list those values in the parameter’s description. For example, you can say “Possible enum values: customer, supplier.”
Example - Defaults
To ensure a tool is called with a default value it’s recommended to specify the default on the tool’s implementation and use required: False whenever possible. When this is not possible you can specify the default in the parameter’s description (with required: True). For example:
Example – Dictionaries
We recommend using individual parameters whenever possible. However, when that’s not possible, to make sure a tool is called with a specific array or dictionary structure you can specify the keys in the parameter’s description. For example:
Example - Python objects (including dataclass)
It’s possible to call a tool that accepts custom Python objects, for example a data class.