Tool use chat template not being filled in

#1
by s42chen - opened

Hello!

I am encountering some issues regarding tool use; may I have your guidance:

Currently, when following the example tool use code to apply_chat_template with the tokenizer, the tools section is empty in the final prompt. Running:

# pip install transformers accelerate
from transformers import AutoTokenizer

model_id = "CohereLabs/command-a-reasoning-08-2025"
tokenizer = AutoTokenizer.from_pretrained(model_id)

tools = [{ 
  "type": "function", 
  "function": {
    "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"]
    },
  }
}]

# Define conversation input
conversation = [{"role": "user", "content": "Can you provide a sales summary for 29th September 2023?"}]


# Get the Tool Use prompt
input_prompt = tokenizer.apply_chat_template(conversation=conversation, tools=tools, tokenize=False, add_generation_prompt=True, reasoning=True, return_tensors="pt")

print(input_prompt)

Gives:

...previous sections
## Available Tools
Here is the list of tools that you have available to you.
You 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.
Each tool is represented as a JSON object with fields like "name", "description", "parameters" (per JSON Schema), and optionally, "responses" (per JSON Schema).

json
[

]

...remaining sections

Consequently, when generating with this prompt, the model does not know how to call the functions, due to the lack of description in the input prompt.

However, if we replace "CohereLabs/command-a-reasoning-08-2025" with "CohereLabs/c4ai-command-a-03-2025", we get the correct tools section filled in:

## Available Tools
Here is the list of tools that you have available to you.
You 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.
Each tool is represented as a JSON object with fields like "name", "description", "parameters" (per JSON Schema), and optionally, "responses" (per JSON Schema).

json
[
    {"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}
]

I have tried both the stable version of transformers==4.55.4, as well as the version from source, transformers== 4.56.0.dev0, and the issue remains.

Would appreciate any comments on how to resolve this. Thank you!

Sign up or log in to comment