Basic Tool Use
Tool use allows customers to connect their large language models to external tools, such as search engines, APIs, functions, and databases.
This allows the customer to unlock a richer set of model behaviors by, for instance, leveraging data stored in tools, taking actions through APIs, interacting with a vector database, or querying a search engine.
Below, we illustrate tool use in four steps:
- Step 1: the user configures the request to the model
- Step 2: the model uses context to determine which tool(s) to use and how
- Step 3: the tool calls are executed
- Step 4: the model generates a final answer with precise citations based on the tool results
Step 0: Create a mock database
Before we can illustrate tool use, we first need to do some setup. Here, we’ll define the mock data that our tools will query. This data represents sales reports and a product catalog.
Now, we’ll define the tools that simulate querying this database.
For example, you could use the API of an enterprise sales platform.
Step 1 - User configures the request to the model
The developer provides a few things to the model:
- A preamble containing instructions about the task and the desired style for the output.
- The user request.
- A list of tools to the model.
- (Optionally) a chat history for the model to work with.
You can specify one or many tools to the model. Every tool needs to be described with a JSON schema, indicating the tool name, description, and parameters (code snippets below).
In our example, we provide two tools to the model: daily_sales_report
and product_catalog
.
Now let’s define the user request.
In our example we’ll use: “Can you provide a sales summary for 29th September 2023, and also give me the details of all products in the ‘Electronics’ category that were sold that day, including their prices and stock levels?”
Only a langage model with Tool Use can answer this request: it requires looking up information in the right external tools (step 2), and then providing a final answer based on the tool results (step 4).
Step 2 – The model smartly decides which tool(s) to use and how
The model intelligently selects the right tool(s) to call — and the right parameters for each tool call — based on the content of the user message.
Step 3 – The tool calls are executed
You can now execute the appropriate calls, using the tool calls and tool parameters generated by the model.
These tool calls return tool results that will be fed to the model in Step 4.
Step 4 - The model generates a final answer based on the tool results
Finally, the developer calls the Cohere model, providing the tools results, in order to generate the model’s final answer.
Bonus: Citations come for free with Cohere! 🎉
At Cohere, model generations come with… precise citations! 🎉
The model cites which groups of words, in the tool results, were used to generate the final answer.
These citations make it easy to check where the model’s generated response claims are coming from.
They help users gain visibility into the model reasoning, and sanity check the final model generation.
These citations are optional — you can decide to ignore them.
Now, you’ve used Cohere for Tool Use. Tool use opens up a wide range of new use cases. Here are a few examples:
-
Function calling: It’s now possible to ask the model to output a JSON object with specific function parameters.
For instance, this allows your chatbot to interact with your CRM to change the status of a deal, or to engage with a Python interpreter to conduct data science analyses. -
Query transformation: You can transform a user message into a search query for a vector database or any search engine.
For instance, this enables your work assistant to automatically retrieve the appropriate data from your company’s documentation by creating the right query for your vector database. -
Advanced searches: You can transform a user message into one-or-many queries, to do multiple subtasks based on the content of the message.
For instance, this allows your chatbot to search across different databases and platforms to retrieve relevant information or to conduct comparative analysis.