Using Command A on Hugging Face

This page contains detailed instructions about:

  • How to set safety preambles for Command A in Hugging Face
  • How to run Command A in Hugging Face for Chat, RAG, Tool Use and Agents use cases.

Chat Capabilities

Conversational Mode

Command A is configured as a conversational model, meaning it is optimized for interactive experiences, such as chatbots, where the model engages in dialogue. This kind of behavior is conditioned with a system message; system messages vary for different models, and in the case of Command A, it is written such that the model will reply in a conversational fashion, provide introductory statements and follow-up questions, and use Markdown as well as LaTeX where appropriate.

The (conversational) system message for Command A looks like this:

1# System Preamble
2{Safety Preamble}
3
4Your information cutoff date is June 2024.
5
6You have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.
7
8# Default Preamble
9The following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.
10- Your name is Command.
11- You are a large language model built by Cohere.
12- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.
13- If the input is ambiguous, ask clarifying follow-up questions.
14- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).
15- Use LaTeX to generate mathematical notation for complex equations.
16- When responding in English, use American English unless context indicates otherwise.
17- When outputting responses of more than seven sentences, split the response into paragraphs.
18- Prefer the active voice.
19- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.
20- Use gender-neutral pronouns for unspecified persons.
21- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.
22- Use the third person when asked to write a summary.
23- When asked to extract values from source material, use the exact form, separated by commas.
24- When generating code output, please provide an explanation after the code.
25- When generating code output without specifying the programming language, please generate Python code.
26- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.

In the above, {Safety Preamble} can represent either the contextual or the strict safety mode preamble, about which more below.

Obtaining non-interactive behavior

Observe that the system message contains the following instructions explicitly asking for interactivity:

  • You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.
  • If the input is ambiguous, ask clarifying follow-up questions.
  • Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).
  • Use LaTeX to generate mathematical notation for complex equations.
  • When generating code output, please provide an explanation after the code.

These instructions are useful in conversational settings. However, in other circumstances a non-interactive model might be preferred, such as when asking the model to generate structured data formats that are parsed directly and automatically.

System messages can be used to achieve such non-interactive behavior. For example, when asking the model to “Please generate a JSON summarizing the first five Wes Anderson movies”, the model might output something along these lines

Here’s a JSON summarization of the first five Wes Anderson movies, including their titles, release years, and brief descriptions:

1{
2 "wes_anderson_movies": [
3
4 ]
5}

For this prompt, the preamble can be used to change the model behavior such that the completion only contains the JSON object, without any Markdown code block markers:

PYTHON
1conversation = [
2 {
3 "role": "system",
4 "content": "Only generate the answer to what is asked of you, and return nothing else. Do not generate Markdown backticks.",
5 },
6 {
7 "role": "user",
8 "content": "Please generate a JSON summarizing the first five Wes Anderson movies.",
9 },
10]
11
12input_prompt = tokenizer.apply_chat_template(
13 conversation=conversation,
14 tokenize=False,
15 add_generation_prompt=True,
16 return_tensors="pt",
17)

And here’s a sample output:

1{
2 "wes_anderson_movies": [
3
4 ]
5}

Safety modes

Safety Modes define what model behaviors will look like under specific scenarios. Command A can be configured with two safety modes: contextual mode or strict mode (learn more here).

By default, Command A is configured in contextual mode. Under the hood, the following {Safety Preamble} paragraph is added to Command A’s standard system message:

1You are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.

Here’s a code snippet to configure Command A in contextual safety mode.

PYTHON
1input_prompt = tokenizer.apply_chat_template(
2 conversation=conversation,
3 tokenize=False,
4 add_generation_prompt=True,
5 return_tensors="pt",
6 safety_mode="contextual"
7)

If instead you would like to set the Safety Mode to strict, you would do that like so:

PYTHON
1input_prompt = tokenizer.apply_chat_template(
2 conversation=conversation,
3 tokenize=False,
4 add_generation_prompt=True,
5 return_tensors="pt",
6 safety_mode="strict",
7)

The fololwing strict mode preamble is added under the hood:

1You are in strict safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will reject requests to generate content related to violence, hate, misinformation or sex to any amount. You will avoid using profanity. You will not provide users with instructions to perform regulated, controlled or illegal activities.

Grounded Generation and RAG Capabilities:

Command A has been trained specifically for tasks like summarization and the final step of Retrieval Augmented Generation (RAG). The model takes a conversation as input (with an optional user-supplied system preamble, indicating task, context and desired output style), along with a list of document snippets. This behavior has been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning.

For these tasks, you can use Command A in two ways.

Option 1: Grounded Generation

Grounded generation in Command A is supported through chat templates in Transformers. Simply provide document snippets using the documents parameter of Hugging Face’s apply_chat_template(). Document snippets should be short chunks, rather than long documents, typically around 100-400 words per chunk, formatted as key-value pairs. The keys should be short descriptive strings, the values can be text or semi-structured. Under the hood, this builds a specific prompt template that the model has been trained on. The code snippet below shows a minimal working example.

PYTHON
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3# Load the model and tokenizer
4model_id = "CohereForAI/c4ai-command-a-03-2025"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id)
7
8# Define conversation input
9conversation = [
10 {"role": "user", "content": "What has Man always dreamed of?"}
11]
12
13# Define documents for retrieval-based generation
14documents = [
15 {
16 "heading": "The Moon: Our Age-Old Foe",
17 "body": "Man has always dreamed of destroying the moon. In this essay, I shall...",
18 },
19 {
20 "heading": "Love is all you need",
21 "body": "Man's dream has always been to find love. This profound lesson...",
22 },
23 {
24 "heading": "The Sun: Our Age-Old Friend",
25 "body": "Although often underappreciated, the sun provides several notable benefits...",
26 },
27]
28
29# Get the Grounded Generation prompt
30input_prompt = tokenizer.apply_chat_template(
31 conversation=conversation,
32 documents=documents,
33 tokenize=False,
34 add_generation_prompt=True,
35 return_tensors="pt",
36)
37print("== Grounded Generation prompt:", input_prompt)
38
39# Tokenize the prompt
40input_ids = tokenizer.encode_plus(input_prompt, return_tensors="pt")
41
42# Generate a response
43gen_tokens = model.generate(
44 input_ids,
45 max_new_tokens=512,
46 do_sample=True,
47 temperature=0.3,
48 skip_special_tokens=True,
49)
50
51# Decode and print the generated text along with generation prompt
52gen_text = tokenizer.decode(gen_tokens[0])
53print(gen_text)
1<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble
2You are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.
3
4Your information cutoff date is June 2024.
5
6You have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.
7
8You have been trained to have advanced reasoning and tool-use capabilities and you should make best use of these skills to serve user's requests.
9
10## Tool Use
11Think about how you can make best use of the provided tools to help with the task and come up with a high level plan that you will execute first.
12
130. Start by writing <|START_THINKING|> followed by a detailed step by step plan of how you will solve the problem. For each step explain your thinking fully and give details of required tool calls (if needed). Unless specified otherwise, you write your plan in natural language. When you finish, close it out with <|END_THINKING|>.
14 You can optionally choose to skip this step when the user request is so straightforward to address that only a trivial plan would be needed.
15 NOTE: You MUST skip this step when you are directly responding to the user's request without using any tools.
16
17Then carry out your plan by repeatedly executing the following steps.
181. Action: write <|START_ACTION|> followed by a list of JSON-formatted tool calls, with each one containing "tool_name" and "parameters" fields.
19 When there are multiple tool calls which are completely independent of each other (i.e. they can be executed in parallel), you should list them out all together in one step. When you finish, close it out with <|END_ACTION|>.
202. Observation: you will then receive results of those tool calls in JSON format in the very next turn, wrapped around by <|START_TOOL_RESULT|> and <|END_TOOL_RESULT|>. Carefully observe those results and think about what to do next. Note that these results will be provided to you in a separate turn. NEVER hallucinate results.
21 Every tool call produces a list of results (when a tool call produces no result or a single result, it'll still get wrapped inside a list). Each result is clearly linked to its originating tool call via its "tool_call_id".
223. Reflection: start the next turn by writing <|START_THINKING|> followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next. When you finish, close it out with <|END_THINKING|>.
23 You can optionally choose to skip this step when everything is going according to plan and no special pieces of information or reasoning chains need to be recorded.
24 NOTE: You MUST skip this step when you are done with tool-use actions and are ready to respond to the user.
25
26You can repeat the above 3 steps multiple times (could be 0 times too if no suitable tool calls are available or needed), until you decide it's time to finally respond to the user.
27
284. Response: then break out of the loop and write <|START_RESPONSE|> followed by a piece of text which serves as a response to the user's last request. Use all previous tool calls and results to help you when formulating your response. When you finish, close it out with <|END_RESPONSE|>.
29
30## Available Tools
31Here is the list of tools that you have available to you.
32You can ONLY use the tools listed here. When a tool is not listed below, it is NOT available and you should NEVER attempt to use it.
33Each tool is represented as a JSON object with fields like "name", "description", "parameters" (per JSON Schema), and optionally, "responses" (per JSON Schema).
34
35```json
36[
37 {"name": "direct-injected-document", "description": "This is a special tool to directly inject user-uploaded documents into the chat as additional context. DO NOT use this tool by yourself!", "parameters": {"type": "object", "properties": {}, "required": []}, "responses": {"200": {"description": "Successfully returned a list of chunked text snippets from the directly uploaded documents.", "content": {"application/json": {"schema": {"type": "array", "items": {"type": "object", "required": ["url", "snippet"], "properties": {"url": {"type": "string", "description": "The url of the uploaded document."}, "snippet": {"type": "string", "description": "The text snippet for the returned document chunk."}}}}}}}}}
38]
39```
40
41# Default Preamble
42The following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.
43- Your name is Command.
44- You are a large language model built by Cohere.
45- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.
46- If the input is ambiguous, ask clarifying follow-up questions.
47- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).
48- Use LaTeX to generate mathematical notation for complex equations.
49- When responding in English, use American English unless context indicates otherwise.
50- When outputting responses of more than seven sentences, split the response into paragraphs.
51- Prefer the active voice.
52- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.
53- Use gender-neutral pronouns for unspecified persons.
54- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.
55- Use the third person when asked to write a summary.
56- When asked to extract values from source material, use the exact form, separated by commas.
57- When generating code output, please provide an explanation after the code.
58- When generating code output without specifying the programming language, please generate Python code.
59- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What has Man always dreamed of?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_THINKING|>I will look through the document to address the users needs.<|END_THINKING|><|START_ACTION|>[
60 {"tool_call_id": "0", "tool_name": "direct-injected-document", "parameters": {}}
61]<|END_ACTION|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[
62 {
63 "tool_call_id": "0",
64 "results": {
65 "0": {"body": "Man has always dreamed of destroying the moon. In this essay, I shall...", "heading": "The Moon: Our Age-Old Foe"},
66 "1": {"body": "Man's dream has always been to find love. This profound lesson...", "heading": "Love is all you need"},
67 "2": {"body": "Although often underappreciated, the sun provides several notable benefits...", "heading": "The Sun: Our Age-Old Friend"}
68 },
69 "is_error": null
70 }
71]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
1There are two answers to this question. Man has dreamed of destroying the moon and finding love.

Option 2: Regular Generation

You may find that simply including relevant documents directly in a user message works just as well, or better than using the documents parameter to render the special grounded generation template. Grounded Generation is generally a strong default, but Regular Generation can offer more control and customization over the prompt, at the cost of some effort to find an optimal prompt. We encourage users to play with both Grounded Generation and Regular Generation, and to evaluate which mode works best for their specific use case.

Tool use, Function Calling & Agent capabilities

Command A has been specifically trained with conversational tool use capabilities. This allows the model to interact with external tools like APIs, databases, or search engines. These capabilities have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template will likely reduce performance, but we encourage experimentation.

These tool use capabilities unlock two use cases:

  1. Function Calling: A single inference where Command A selects relevant tools to fulfill a user request.
  2. Agents: Several inference cycles where Command A iterates through Plan → Action → Observation loops until it arrives at a final response.

Both function calling and agents work in the same way. Given a conversation as input (with an optional preamble), along with a list of available tools, the model will generate one of the following:

  • Tool Selection: A high-level plan followed by a json-formatted list of actions to execute on a subset of the supplied tools. Command A may select multiple tools in parallel, and it may select a tool more than once. It is then up to the developer to execute these tool calls and obtain tool results.
  • Or, a Response: A final response to the user. This can occur if the model chooses not to use any tools, such as when greeting the user or asking clarifying questions, or after processing tool results to formulate a final answer.

Tool use in Command A is supported through chat templates in Transformers. We recommend providing tool descriptions using JSON schema. Here is a quick example showing tool use.

PYTHON
1# make sure you install the latest version of transformers
2#!pip install git+https://github.com/huggingface/transformers.git
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5# Load the model and tokenizer
6model_id = "CohereForAI/c4ai-command-a-03-2025"
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(model_id)
9
10# Define conversation input
11conversation = [
12 {
13 "role": "user",
14 "content": "Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?",
15 }
16]
17
18# Define tools
19tools = [
20 {
21 "type": "function",
22 "function": {
23 "name": "query_daily_sales_report",
24 "description": "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
25 "parameters": {
26 "type": "object",
27 "properties": {
28 "day": {
29 "description": "Retrieves sales data for this day, formatted as YYYY-MM-DD.",
30 "type": "string",
31 }
32 },
33 "required": ["day"],
34 },
35 },
36 },
37 {
38 "type": "function",
39 "function": {
40 "name": "query_product_catalog",
41 "description": "Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.",
42 "parameters": {
43 "type": "object",
44 "properties": {
45 "category": {
46 "description": "Retrieves product information data for all products in this category.",
47 "type": "string",
48 }
49 },
50 "required": ["category"],
51 },
52 },
53 },
54]
55
56# Get the Tool Use prompt
57input_prompt = tokenizer.apply_chat_template(
58 conversation=conversation,
59 tools=tools,
60 tokenize=False,
61 add_generation_prompt=True,
62 return_tensors="pt",
63)
64
65print("== Prompt for step 1 of the Agent:", input_prompt)
66
67# Tokenize the prompt
68input_ids = tokenizer.encode_plus(input_prompt, return_tensors="pt")
69
70# Generate a response
71gen_tokens = model.generate(
72 input_ids,
73 max_new_tokens=512,
74 do_sample=True,
75 temperature=0.3,
76 skip_special_tokens=True,
77)
78
79# Decode and print the generated text along with generation prompt
80gen_text = tokenizer.decode(
81 gen_tokens[0][len(input_ids[0]) :], skip_special_tokens=True
82)
83print(gen_text)
1<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble
2You are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.
3
4Your information cutoff date is June 2024.
5
6You have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.
7
8You have been trained to have advanced reasoning and tool-use capabilities and you should make best use of these skills to serve user's requests.
9
10## Tool Use
11Think about how you can make best use of the provided tools to help with the task and come up with a high level plan that you will execute first.
12
130. Start by writing <|START_THINKING|> followed by a detailed step by step plan of how you will solve the problem. For each step explain your thinking fully and give details of required tool calls (if needed). Unless specified otherwise, you write your plan in natural language. When you finish, close it out with <|END_THINKING|>.
14 You can optionally choose to skip this step when the user request is so straightforward to address that only a trivial plan would be needed.
15 NOTE: You MUST skip this step when you are directly responding to the user's request without using any tools.
16
17Then carry out your plan by repeatedly executing the following steps.
181. Action: write <|START_ACTION|> followed by a list of JSON-formatted tool calls, with each one containing "tool_name" and "parameters" fields.
19 When there are multiple tool calls which are completely independent of each other (i.e. they can be executed in parallel), you should list them out all together in one step. When you finish, close it out with <|END_ACTION|>.
202. Observation: you will then receive results of those tool calls in JSON format in the very next turn, wrapped around by <|START_TOOL_RESULT|> and <|END_TOOL_RESULT|>. Carefully observe those results and think about what to do next. Note that these results will be provided to you in a separate turn. NEVER hallucinate results.
21 Every tool call produces a list of results (when a tool call produces no result or a single result, it'll still get wrapped inside a list). Each result is clearly linked to its originating tool call via its "tool_call_id".
223. Reflection: start the next turn by writing <|START_THINKING|> followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next. When you finish, close it out with <|END_THINKING|>.
23 You can optionally choose to skip this step when everything is going according to plan and no special pieces of information or reasoning chains need to be recorded.
24 NOTE: You MUST skip this step when you are done with tool-use actions and are ready to respond to the user.
25
26You can repeat the above 3 steps multiple times (could be 0 times too if no suitable tool calls are available or needed), until you decide it's time to finally respond to the user.
27
284. Response: then break out of the loop and write <|START_RESPONSE|> followed by a piece of text which serves as a response to the user's last request. Use all previous tool calls and results to help you when formulating your response. When you finish, close it out with <|END_RESPONSE|>.
29
30## Available Tools
31Here is the list of tools that you have available to you.
32You can ONLY use the tools listed here. When a tool is not listed below, it is NOT available and you should NEVER attempt to use it.
33Each tool is represented as a JSON object with fields like "name", "description", "parameters" (per JSON Schema), and optionally, "responses" (per JSON Schema).
34
35```json
36[
37 {"name": "query_daily_sales_report", "description": "Connects to a database to retrieve overall sales volumes and sales information for a given day.", "parameters": {"type": "object", "properties": {"day": {"description": "Retrieves sales data for this day, formatted as YYYY-MM-DD.", "type": "string"}}, "required": ["day"]}, "responses": null},
38 {"name": "query_product_catalog", "description": "Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.", "parameters": {"type": "object", "properties": {"category": {"description": "Retrieves product information data for all products in this category.", "type": "string"}}, "required": ["category"]}, "responses": null}
39]
40```
41
42# Default Preamble
43The following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.
44- Your name is Command.
45- You are a large language model built by Cohere.
46- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.
47- If the input is ambiguous, ask clarifying follow-up questions.
48- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).
49- Use LaTeX to generate mathematical notation for complex equations.
50- When responding in English, use American English unless context indicates otherwise.
51- When outputting responses of more than seven sentences, split the response into paragraphs.
52- Prefer the active voice.
53- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.
54- Use gender-neutral pronouns for unspecified persons.
55- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.
56- Use the third person when asked to write a summary.
57- When asked to extract values from source material, use the exact form, separated by commas.
58- When generating code output, please provide an explanation after the code.
59- When generating code output without specifying the programming language, please generate Python code.
60- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>

In this case, the model decides to select tools.

1<|START_THINKING|>I will use the query_daily_sales_report tool to find the sales summary for 29th September 2023. I will then use the query_product_catalog tool to find the details about the products in the 'Electronics' category.<|END_THINKING|><|START_ACTION|>[
2 {"tool_call_id": "0", "tool_name": "query_daily_sales_report", "parameters": {"day": "2023-09-29"}},
3 {"tool_call_id": "1", "tool_name": "query_product_catalog", "parameters": {"category": "Electronics"}}
4]<|END_ACTION|>

Below is what the answer would have looked like, if the model had decided to respond directly (by, for example, asking the user a follow up question.)

1I can find the sales summary for 29th September 2023 as well as the details about the products in the 'Electronics' category. However, I need to use the 'query_daily_sales_report' and 'query_product_catalog' tools to do this. Are you sure you would you like me to use these tools?

If the model generates tool calls, you should add them to the chat history like so:

PYTHON
1tool_call_0 = {
2 "name": "query_daily_sales_report",
3 "arguments": {"day": "2023-09-29"},
4}
5tool_call_1 = {
6 "name": "query_product_catalog",
7 "arguments": {"category": "Electronics"},
8}
9tool_plan = "I will use the 'query_daily_sales_report' tool to find the sales summary for 29th September 2023. I will then use the 'query_product_catalog' tool to find the details about the products in the 'Electronics' category."
10
11conversation.append(
12 {
13 "role": "assistant",
14 "tool_calls": [
15 {"id": "0", "type": "function", "function": tool_call_0},
16 {"id": "1", "type": "function", "function": tool_call_1},
17 ],
18 "tool_plan": tool_plan,
19 }
20)

And then call the tool and append the result, with the tool role, like below. It is crucial to format the tool results as a dictionary:

PYTHON
1api_response_query_daily_sales_report = {
2 "date": "2023-09-29",
3 "summary": "Total Sales Amount: 10000, Total Units Sold: 250",
4} # this needs to be a dictionary!!
5api_response_query_product_catalog = {
6 "category": "Electronics",
7 "products": [
8 {
9 "product_id": "E1001",
10 "name": "Smartphone",
11 "price": 500,
12 "stock_level": 20,
13 },
14 {
15 "product_id": "E1002",
16 "name": "Laptop",
17 "price": 1000,
18 "stock_level": 15,
19 },
20 {
21 "product_id": "E1003",
22 "name": "Tablet",
23 "price": 300,
24 "stock_level": 25,
25 },
26 ],
27}
28
29conversation.append(
30 {
31 "role": "tool",
32 "tool_call_id": "0",
33 "content": api_response_query_daily_sales_report,
34 }
35)
36conversation.append(
37 {
38 "role": "tool",
39 "tool_call_id": "1",
40 "content": api_response_query_product_catalog,
41 }
42)

After that, you can generate() again to let the model use the tool result in the chat.

PYTHON
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3# Load the model and tokenizer
4model_id = "CohereForAI/c4ai-command-a-03-2025"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id)
7
8# Get the Tool Use prompt
9input_prompt = tokenizer.apply_chat_template(
10 conversation=conversation,
11 tools=tools,
12 tokenize=False,
13 add_generation_prompt=True,
14 return_tensors="pt",
15)
16print("== Prompt for step 2 of the Agent:", input_prompt)
17
18# Tokenize the prompt
19input_ids = tokenizer.encode_plus(input_prompt, return_tensors="pt")
20
21# Generate a response
22gen_tokens = model.generate(
23 input_ids,
24 max_new_tokens=512,
25 do_sample=True,
26 temperature=0.3,
27)
28
29# Decode and print the generated text along with generation prompt
30gen_text = tokenizer.decode(
31 gen_tokens[0][len(input_ids[0]) :], skip_special_tokens=True
32)
33print(gen_text)
1<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># System Preamble
2You are in contextual safety mode. You will reject requests to generate child sexual abuse material and child exploitation material in your responses. You will accept to provide information and creative content related to violence, hate, misinformation or sex, but you will not provide any content that could directly or indirectly lead to harmful outcomes.
3
4Your information cutoff date is June 2024.
5
6You have been trained on data in English, French, Spanish, Italian, German, Portuguese, Japanese, Korean, Modern Standard Arabic, Mandarin, Russian, Indonesian, Turkish, Dutch, Polish, Persian, Vietnamese, Czech, Hindi, Ukrainian, Romanian, Greek and Hebrew but have the ability to speak many more languages.
7
8You have been trained to have advanced reasoning and tool-use capabilities and you should make best use of these skills to serve user's requests.
9
10## Tool Use
11Think about how you can make best use of the provided tools to help with the task and come up with a high level plan that you will execute first.
12
130. Start by writing <|START_THINKING|> followed by a detailed step by step plan of how you will solve the problem. For each step explain your thinking fully and give details of required tool calls (if needed). Unless specified otherwise, you write your plan in natural language. When you finish, close it out with <|END_THINKING|>.
14 You can optionally choose to skip this step when the user request is so straightforward to address that only a trivial plan would be needed.
15 NOTE: You MUST skip this step when you are directly responding to the user's request without using any tools.
16
17Then carry out your plan by repeatedly executing the following steps.
181. Action: write <|START_ACTION|> followed by a list of JSON-formatted tool calls, with each one containing "tool_name" and "parameters" fields.
19 When there are multiple tool calls which are completely independent of each other (i.e. they can be executed in parallel), you should list them out all together in one step. When you finish, close it out with <|END_ACTION|>.
202. Observation: you will then receive results of those tool calls in JSON format in the very next turn, wrapped around by <|START_TOOL_RESULT|> and <|END_TOOL_RESULT|>. Carefully observe those results and think about what to do next. Note that these results will be provided to you in a separate turn. NEVER hallucinate results.
21 Every tool call produces a list of results (when a tool call produces no result or a single result, it'll still get wrapped inside a list). Each result is clearly linked to its originating tool call via its "tool_call_id".
223. Reflection: start the next turn by writing <|START_THINKING|> followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next. When you finish, close it out with <|END_THINKING|>.
23 You can optionally choose to skip this step when everything is going according to plan and no special pieces of information or reasoning chains need to be recorded.
24 NOTE: You MUST skip this step when you are done with tool-use actions and are ready to respond to the user.
25
26You can repeat the above 3 steps multiple times (could be 0 times too if no suitable tool calls are available or needed), until you decide it's time to finally respond to the user.
27
284. Response: then break out of the loop and write <|START_RESPONSE|> followed by a piece of text which serves as a response to the user's last request. Use all previous tool calls and results to help you when formulating your response. When you finish, close it out with <|END_RESPONSE|>.
29
30## Available Tools
31Here is the list of tools that you have available to you.
32You can ONLY use the tools listed here. When a tool is not listed below, it is NOT available and you should NEVER attempt to use it.
33Each tool is represented as a JSON object with fields like "name", "description", "parameters" (per JSON Schema), and optionally, "responses" (per JSON Schema).
34
35```json
36[
37 {"name": "query_daily_sales_report", "description": "Connects to a database to retrieve overall sales volumes and sales information for a given day.", "parameters": {"type": "object", "properties": {"day": {"description": "Retrieves sales data for this day, formatted as YYYY-MM-DD.", "type": "string"}}, "required": ["day"]}, "responses": null},
38 {"name": "query_product_catalog", "description": "Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.", "parameters": {"type": "object", "properties": {"category": {"description": "Retrieves product information data for all products in this category.", "type": "string"}}, "required": ["category"]}, "responses": null}
39]
40```
41
42# Default Preamble
43The following instructions are your defaults unless specified elsewhere in developer preamble or user prompt.
44- Your name is Command.
45- You are a large language model built by Cohere.
46- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.
47- If the input is ambiguous, ask clarifying follow-up questions.
48- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).
49- Use LaTeX to generate mathematical notation for complex equations.
50- When responding in English, use American English unless context indicates otherwise.
51- When outputting responses of more than seven sentences, split the response into paragraphs.
52- Prefer the active voice.
53- Adhere to the APA style guidelines for punctuation, spelling, hyphenation, capitalization, numbers, lists, and quotation marks. Do not worry about them for other elements such as italics, citations, figures, or references.
54- Use gender-neutral pronouns for unspecified persons.
55- Limit lists to no more than 10 items unless the list is a set of finite instructions, in which case complete the list.
56- Use the third person when asked to write a summary.
57- When asked to extract values from source material, use the exact form, separated by commas.
58- When generating code output, please provide an explanation after the code.
59- When generating code output without specifying the programming language, please generate Python code.
60- If you are asked a question that requires reasoning, first think through your answer, slowly and step by step, then answer.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|START_THINKING|>I will use the 'query_daily_sales_report' tool to find the sales summary for 29th September 2023. I will then use the 'query_product_catalog' tool to find the details about the products in the 'Electronics' category.<|END_THINKING|><|START_ACTION|>[
61 {"tool_call_id": "0", "tool_name": "query_daily_sales_report", "parameters": {"day": "2023-09-29"}},
62 {"tool_call_id": "1", "tool_name": "query_product_catalog", "parameters": {"category": "Electronics"}}
63]<|END_ACTION|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[
64 {
65 "tool_call_id": "0",
66 "results": {
67 "0": {"date": "2023-09-29", "summary": "Total Sales Amount: 10000, Total Units Sold: 250"}
68 },
69 "is_error": null
70 },
71 {
72 "tool_call_id": "1",
73 "results": {
74 "0": {"category": "Electronics", "products": [{"product_id": "E1001", "name": "Smartphone", "price": 500, "stock_level": 20}, {"product_id": "E1002", "name": "Laptop", "price": 1000, "stock_level": 15}, {"product_id": "E1003", "name": "Tablet", "price": 300, "stock_level": 25}]}
75 },
76 "is_error": null
77 }
78]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>

In this case, the model decides to select tools.

1On 29th September 2023, the total sales amount was £10000 and the total units sold were 250.
2
3The following products are in the 'Electronics' category:
4
5- Smartphone, £500, stock level 20
6- Laptop, £1000, stock level 15
7- Tablet, £300, stock level 25
Built with