Qwen 3 Chat Template

{# 
Block 1: Tool Definitions Preamble
(a) What this block is about: 
This block handles the initial system prompt setup. It checks if tools are provided and, if so, injects a system message that includes tool definitions, usage instructions, and formatting rules for tool calls. If no tools are present, it simply formats any existing system message. This ensures the model is aware of available tools and how to invoke them right at the start of the prompt.
 
(b) What concretely each part is about:
- The outer if: Checks for the presence of 'tools' (a list of tool definitions) to decide between tool-enabled or plain system prompt.
- If tools exist: Starts a system turn, includes any pre-existing system content, adds a header for tools, loops to output each tool as JSON inside <tools> tags, and provides explicit instructions on formatting tool calls with <tool_call>.
- Else: Just outputs a basic system message if the first message is system-role.
#}
 
{%- if tools %}
    {{- '<|im_start|>system\n' }} {# Starts the system prompt turn #}
    {%- if messages[0].role == 'system' %} {# Checks for an existing system message to include its content #}
        {{- messages[0].content + '\n\n' }} {# Appends the system content with newlines for separation #}
    {%- endif %}
    {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }} {# Adds instructional text about tools and starts the <tools> tag #}
    {%- for tool in tools %} {# Loops over each tool in the list #}
        {{- "\n" }} {# Adds a newline for formatting #}
        {{- tool | tojson }} {# Converts the tool object to JSON and outputs it #}
    {%- endfor %}
    {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }} {# Closes <tools>, adds instructions for tool call format, and ends the system turn #}
{%- else %}
    {%- if messages[0].role == 'system' %} {# Fallback for no tools: check for system message #}
        {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }} {# Outputs plain system prompt #}
    {%- endif %}
{%- endif %}
 
{# 
Block 2: Rolling Checkpoint System
(a) What this block is about: 
This block implements dynamic context management by identifying the index of the last genuine user query (not a tool response). It scans messages in reverse to find this boundary, which is used later to decide whether to preserve or prune reasoning (<think> blocks) in assistant messages. This "rolling checkpoint" keeps recent context detailed while pruning old reasoning to save tokens and avoid staleness.
 
(b) What concretely each part is about:
- Namespace setup: Creates a mutable namespace with 'multi_step_tool' flag (initially true) and 'last_query_index' (set to last message index).
- Reverse loop: Iterates over messages from newest to oldest, calculating original indices.
- Condition check: Looks for a user-role message whose content is a string and not wrapped in <tool_response> (i.e., a real query, not tool output).
- Update namespace: Once found, sets flag to false and saves the index as the checkpoint.
#}
 
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %} {# Initializes tracking variables #}
{%- for message in messages[::-1] %} {# Reverse iteration over messages #}
    {%- set index = (messages|length - 1) - loop.index0 %} {# Computes forward index from reverse loop #}
    {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %} {# Checks for real user query #}
        {%- set ns.multi_step_tool = false %} {# Disables flag to stop further checks #}
        {%- set ns.last_query_index = index %} {# Saves the index of the last real query #}
    {%- endif %}
{%- endfor %}
 
{# 
Block 3: Main Conversation Loop & Message Formatting
(a) What this block is about: 
This is the core processing loop that formats each message in chronological order based on its role. It handles user/system messages simply, assistant messages with conditional reasoning preservation and tool calls, and tool responses by grouping them under user turns. It applies the checkpoint to prune old <think> blocks.
 
(b) What concretely each part is about:
- Outer loop: Iterates through all messages in order.
- Content setup: Ensures 'content' is a string, defaults to empty if not.
- User/system handling: Formats these roles with basic start/end tokens.
- Assistant handling: Extracts reasoning (from explicit field or by parsing <think> in content), checks against checkpoint to include/prune <think>, outputs content, appends tool calls if present, and ends the turn.
- Tool handling: Groups consecutive tool responses into one user turn, wraps each in <tool_response>.
#}
 
{%- for message in messages %} {# Starts main forward loop over messages #}
    {%- if message.content is string %} {# Checks if content is a string #}
        {%- set content = message.content %} {# Sets content variable #}
    {%- else %}
        {%- set content = '' %} {# Defaults to empty string #}
    {%- endif %}
    {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} {# Handles user or non-first system roles #}
        {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }} {# Outputs formatted turn #}
    {%- elif message.role == "assistant" %} {# Handles assistant role #}
        {%- set reasoning_content = '' %} {# Defaults reasoning to empty #}
        {%- if message.reasoning_content is string %} {# Checks for explicit reasoning_content #}
            {%- set reasoning_content = message.reasoning_content %} {# Uses provided reasoning #}
        {%- else %}
            {%- if '</think>' in content %} {# Parses <think> from content if present #}
                {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %} {# Extracts reasoning text #}
                {%- set content = content.split('</think>')[-1].lstrip('\n') %} {# Removes it from main content #}
            {%- endif %}
        {%- endif %}
        {%- if loop.index0 > ns.last_query_index %} {# Checks if after checkpoint (active context) #}
            {%- if loop.last or (not loop.last and reasoning_content) %} {# Includes <think> if last message or has reasoning #}
                {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }} {# Outputs with full <think> #}
            {%- else %}
                {{- '<|im_start|>' + message.role + '\n' + content }} {# Outputs without <think> #}
            {%- endif %}
        {%- else %} {# Before checkpoint: prune <think> #}
            {{- '<|im_start|>' + message.role + '\n' + content }} {# Outputs stripped content #}
        {%- endif %}
        {%- if message.tool_calls %} {# Checks for tool calls #}
            {%- for tool_call in message.tool_calls %} {# Loops over tool calls #}
                {%- if (loop.first and content) or (not loop.first) %} {# Adds newline if appropriate #}
                    {{- '\n' }}
                {%- endif %}
                {%- if tool_call.function %} {# Normalizes if function sub-object #}
                    {%- set tool_call = tool_call.function %}
                {%- endif %}
                {{- '<tool_call>\n{\"name\": \"' }} {# Starts JSON for tool call #}
                {{- tool_call.name }}
                {{- '\", \"arguments\": ' }}
                {%- if tool_call.arguments is string %} {# Handles arguments as string or JSON #}
                    {{- tool_call.arguments }}
                {%- else %}
                    {{- tool_call.arguments | tojson }}
                {%- endif %}
                {{- '}\n</tool_call>' }} {# Ends tool call JSON #}
            {%- endfor %}
        {%- endif %}
        {{- '<|im_end|>\n' }} {# Ends assistant turn #}
    {%- elif message.role == "tool" %} {# Handles tool role #}
        {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %} {# Starts user turn if first or non-consecutive #}
            {{- '<|im_start|>user' }}
        {%- endif %}
        {{- '\n<tool_response>\n' }} {# Wraps tool response #}
        {{- content }}
        {{- '\n</tool_response>' }}
        {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %} {# Ends turn if last or non-consecutive #}
            {{- '<|im_end|>\n' }}
        {%- endif %}
    {%- endif %}
{%- endfor %} {# Ends main loop #}
 
{# 
Block 4: Final Generation Prompt
(a) What this block is about: 
This block appends a prompt to start the next assistant response if generation is requested. It cues the model to begin outputting, optionally including an empty <think> if thinking is disabled.
 
(b) What concretely each part is about:
- Condition: Checks 'add_generation_prompt' flag to decide if to add the starter.
- Output: Starts assistant turn, and if thinking is explicitly disabled, adds an empty <think> block.
#}
 
{%- if add_generation_prompt %} {# Checks for generation prompt flag #}
    {{- '<|im_start|>assistant\n' }} {# Starts new assistant turn #}
    {%- if enable_thinking is defined and enable_thinking is false %} {# Checks if thinking is disabled #}
        {{- '<think>\n\n</think>\n\n' }} {# Adds empty think block #}
    {%- endif %}
{%- endif %}

Overall Structure and Special Tokens

The entire template’s job is to convert a list of message objects into a single, correctly formatted string that the model can understand. It does this using special tokens to define the structure of the conversation.

  • <|im_start|>{role}: This token marks the beginning of a turn. {role} will be system, user, or assistant.
  • <|im_end|> : This token marks the end of a turn.
  • The Goal: To create a sequence like this:
    <|im_start|>system
    You are a helpful assistant.<|im_end|>
    <|im_start|>user
    What is the weather in London?<|im_end|>
    <|im_start|>assistant
    <think>
    The user is asking for the weather. I should use the weather tool.
    </think>
    <tool_call>
    {"name": "get_weather", "arguments": {"city": "London"}}
    </tool_call><|im_end|>

A Deep Dive

Block 1: The Tool Definitions Preamble

{%- if tools %}
    {{- '<|im_start|>system\n' }}
    {%- if messages[0].role == 'system' %}
        {{- messages[0].content + '\n\n' }}
    {%- endif %}
    {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
    {%- for tool in tools %}
        {{- "\n" }}
        {{- tool | tojson }}
    {%- endfor %}
    {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
    {%- if messages[0].role == 'system' %}
        {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
    {%- endif %}
{%- endif %}

This first block sets up the initial instructions for the model.

  • Condition: {%- if tools %}
  • What it Checks: It checks if a list of tools (function definitions) was provided when formatting the prompt.
  • If TRUE (Tools are available):
    1. It creates a special <|im_start|>system message.
    2. It prints the available tools in JSON format, wrapped inside <tools> tags.
    3. Crucially, it gives the model explicit instructions on how to format a tool call using the <tool_call> tag. This is the model’s instruction manual for using the tools you’ve given it.
  • If FALSE (No tools): It just formats the regular system message, if one exists.

Block 2: The Rolling Checkpoint System

{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
    {%- set index = (messages|length - 1) - loop.index0 %}
    {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
        {%- set ns.multi_step_tool = false %}
        {%- set ns.last_query_index = index %}
    {%- endif %}
{%- endfor %}

This is the most clever part of the template. It’s a “rolling checkpoint” or “save point” system.

  • What it Does: Before formatting the main conversation, this block loops through the messages in reverse (messages[::-1]). Its goal is to find the index of the last “real” user query.
  • Condition: if message.role == "user" and not(message.content.startswith('<tool_response>'))
  • What it Checks: It looks for a message that is from the user but is not a tool response (which is also formatted under the user role). This identifies the user’s most recent, genuine prompt.
  • Why it’s important: The model’s reasoning (its “thinking”) is only relevant for the current turn it’s working on. For all past turns in the history, we only care about the final answer, not the thought process that got there. This last_query_index marks the boundary between “past, completed turns” and the “current, active turn.”

Block 3: The Main Conversation Loop & Message Roles

This section iterates through the messages in chronological order and formats each one based on its role and whether it’s part of the “current” turn.

User and System Messages

{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
    {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}

This is straightforward. It takes user messages and any system messages (after the first one, which is handled by the preamble) and wraps them in the standard <|im_start|>{role} and <|im_end|> tags.

Assistant Messages: Reasoning <think> and Tool Calls <tool_call>

{%- elif message.role == "assistant" %}
    ...
    {%- if loop.index0 > ns.last_query_index %}
        {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
    {%- else %}
        {{- '<|im_start|>' + message.role + '\n' + content }}
    {%- endif %}
    {%- if message.tool_calls %}
        ...
        {{- '<tool_call>\n{\"name\": \"' ... '}\n</tool_call>' }}
    {%- endif %}
    {{- '<|im_end|>\n' }}

This is where the checkpoint system pays off.

  • Reasoning (<think>):
    • Condition: loop.index0 > ns.last_query_index
    • What it Checks: It checks if the current assistant message occurs after the last real user query we found earlier.
    • If TRUE (It’s the current turn): It includes the assistant’s reasoning, wrapped in <think> tags. This shows the model’s internal monologue for the problem it is currently solving.
    • If FALSE (It’s a past turn): It strips out the <think> block and only includes the final content. This keeps the history clean and focused.
  • Tool Calling (<tool_call>):
    • Condition: {%- if message.tool_calls %}
    • What it Checks: It checks if the assistant’s message contains instructions to call one or more tools.
    • What it Does: If so, it iterates through the tool_calls and formats each one into the <tool_call> structure that the model was instructed to use in the preamble. This is the model’s output when it decides to use a tool.

Tool Response Messages

{%- elif message.role == "tool" %}
    {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
        {{- '<|im_start|>user' }}
    {%- endif %}
    {{- '\n<tool_response>\n' + content + '\n</tool_response>' }}
    {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
        {{- '<|im_end|>\n' }}
    {%- endif %}

This handles the results that come back after a tool is executed.

  • What it Does: It formats the tool’s output inside <tool_response> tags.
  • Clever Grouping: Notice the if conditions at the start and end. They check if the previous or next message is also a tool response. This allows the template to group multiple tool responses into a single user turn, which is more efficient. It tells the model, “Here are all the results from the functions you called.”

Block 4: The Final Generation Prompt

{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant\n<think>\n' }}
{%- endif %}
  • Condition: {%- if add_generation_prompt %}
  • What it Checks: A flag that indicates we want the model to generate a response.
  • What it Does: After formatting the entire conversation history, this adds <|im_start|>assistant\n<think>\n at the very end. This is the final cue. It prompts the model to begin its turn, and specifically encourages it to start by thinking before producing an answer or calling another tool.

How Qwen Template Processes Reasoning in History?

Understanding how Qwen3’s chat template handles reasoning_content in conversation history is crucial for working with the model effectively. The behavior depends on who sent the last message.

🎯 The Core Rule

The template processes reasoning content based on conversation state:

  • Last message = User → Strip all historical reasoning (ready for new generation)
  • Last message = Assistant → Show the final assistant’s reasoning only

📋 Scenario A: Conversation Ends with Assistant Message

When the conversation ends with an assistant response, you’re viewing a completed exchange.

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What's 15 * 24?"},
    {
        "role": "assistant", 
        "content": "15 × 24 = 360",
        "reasoning_content": "I'll multiply: 15 × 24 = 15 × (20 + 4) = 300 + 60 = 360"
    }
    # ↑ Conversation ends with assistant
]

Template Output:

<|im_start|>user
What's 15 * 24?<|im_end|>
<|im_start|>assistant
<think>
I'll multiply: 15 × 24 = 15 × (20 + 4) = 300 + 60 = 360
</think>

15 × 24 = 360<|im_end|>

Result: The final assistant’s reasoning_content is displayed in <think></think> blocks.

🚀 Scenario B: Conversation Ends with User Message

When the conversation ends with a user message, the model is about to generate a new response.

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What's 2+2?"},
    {
        "role": "assistant", 
        "content": "4", 
        "reasoning_content": "Simple addition: 2 + 2 = 4"
    },
    {"role": "user", "content": "What's 3+3?"}
    # ↑ Conversation ends with user (assistant's turn to respond)
]

Template Output:

<|im_start|>user
What's 2+2?<|im_end|>
<|im_start|>assistant
4<|im_end|>
<|im_start|>user
What's 3+3?<|im_end|>

What will be completed by LLM: 
<|im_start|>assistant
<think>...

Result: All historical reasoning_content is stripped away. The template provides a clean slate for new generation with fresh thinking.

🔍 Why This Design Makes Sense

For Completed Conversations (Scenario A):

  • Shows the reasoning behind the final response
  • Useful for understanding how the model arrived at its answer
  • Perfect for viewing/analyzing completed exchanges

For Active Generation (Scenario B):

  • Clean slate approach: Historical thinking doesn’t interfere
  • Memory efficiency: Avoids repeating all past reasoning
  • Fresh reasoning: Each new response gets its own thinking space
  • Incremental conversation: Optimized for back-and-forth dialogue

💡 Key Takeaways

  1. Historical reasoning_content is metadata - it’s part of the conversation context but not always displayed
  2. Only “active” reasoning appears in <think> blocks - either the final response or the new generation
  3. The template automatically adapts based on conversation state
  4. This prevents reasoning clutter while maintaining the ability to show thinking when relevant

🎯 Practical Implications

  • When viewing logs: You’ll see thinking for the last assistant message
  • When generating: Historical thinking is hidden, new thinking starts fresh
  • When debugging: Remember that missing <think> blocks might be due to conversation state, not broken functionality
  • When building applications: Design your UI expecting this behavior

This design elegantly balances transparency (showing reasoning when relevant) with clarity (avoiding cognitive overload from historical thinking repetition).

Tool Usage in Qwen3

This guide shows you how to use tools with Qwen3 and understand why the output looks different when tools are involved.

🛠️ How to Use Tools with Qwen3

Step 1: Define Your Tools

tools = [
    {
        "type": "function",
        "function": {
            "name": "calculator",
            "description": "Perform mathematical calculations",
            "parameters": {
                "type": "object",
                "properties": {
                    "expression": {"type": "string", "description": "Math expression"}
                },
                "required": ["expression"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "weather",
            "description": "Get weather information",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "City name"}
                },
                "required": ["location"]
            }
        }
    }
]

Step 2: Use the Tokenizer with Tools

from transformers import AutoTokenizer
 
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-32B")
 
messages = [
    {"role": "user", "content": "What's 15*24 and what's the weather in Tokyo?"}
]
 
# IMPORTANT: Pass the tools parameter!
template_output = tokenizer.apply_chat_template(
    messages,
    tools=tools,
    enable_thinking=True,
    tokenize=False,
    add_generation_prompt=True
)

📊 Understanding the Output: 2-Round Conversations

Let’s compare what happens with and without tools in 2-round conversations.

Without Tools: Simple 2-Round Dialog

Conversation:

Round 1: User asks "What's 5+3?"
Round 2: User asks "What's 7*2?"

Template Output:

<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
What's 5+3?<|im_end|>
<|im_start|>assistant
8<|im_end|>
<|im_start|>user
What's 7*2?<|im_end|>
<|im_start|>assistant
<think>
User wants 7*2. That's 14.
</think>

14<|im_end|>

Key Observation: Only the LAST assistant shows thinking. The first assistant’s reasoning is gone.

With Tools: 2-Round Dialog (2 tools each round)

Conversation:

Round 1: User asks "Calculate 5+3 and get weather in Tokyo"
Round 2: User asks "Calculate 7*2 and get weather in Paris"

Template Output:

<|im_start|>system
You are a helpful assistant.

# Tools

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{"type": "function", "function": {"name": "calculator", ...}}
{"type": "function", "function": {"name": "weather", ...}}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call><|im_end|>
<|im_start|>user
Calculate 5+3 and get weather in Tokyo<|im_end|>
<|im_start|>assistant
<think>
User wants two things: calculate 5+3 and get Tokyo weather. I'll call both tools.
</think>

I'll calculate 5+3 and check Tokyo weather for you.
<tool_call>
{"name": "calculator", "arguments": {"expression": "5+3"}}
</tool_call>
<tool_call>
{"name": "weather", "arguments": {"location": "Tokyo"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
8
</tool_response>
<tool_response>
Tokyo: 22°C, sunny
</tool_response><|im_end|>
<|im_start|>assistant
<think>
Got results: 5+3=8 and Tokyo is 22°C and sunny. Perfect!
</think>

The calculation result is 8, and Tokyo is currently 22°C with sunny weather.<|im_end|>
<|im_start|>user
Calculate 7*2 and get weather in Paris<|im_end|>
<|im_start|>assistant
<think>
Now user wants 7*2 calculation and Paris weather. Using both tools again.
</think>

I'll calculate 7*2 and check Paris weather.
<tool_call>
{"name": "calculator", "arguments": {"expression": "7*2"}}
</tool_call>
<tool_call>
{"name": "weather", "arguments": {"location": "Paris"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
14
</tool_response>
<tool_response>
Paris: 18°C, cloudy
</tool_response><|im_end|>
<|im_start|>assistant
<think>
Results: 7*2=14 and Paris is 18°C, cloudy conditions.
</think>

The calculation gives us 14, and Paris is currently 18°C with cloudy weather.<|im_end|>

Key Observation: ALL assistants show thinking! Every <think> block is preserved.

🎯 Why Tools Change the Output

The Simple Truth

Without tools: Only the last assistant gets <think> blocks
With tools: ALL assistants get <think> blocks

The Reason: Message Indexing

Here’s what happens behind the scenes:

Simple conversation structure:

[0] System
[1] User: "What's 5+3?" 
[2] Assistant: "8" (reasoning stripped)
[3] User: "What's 7*2?" ← last_query_index = 3
[4] Assistant: "14" ← index 4 > 3: Shows thinking ✓

Tool conversation structure:

[0] System  
[1] User: "Calculate 5+3 and weather Tokyo"
[2] Assistant: calls tools ← index 2 > 1: Shows thinking ✓
[3] Tool response 1
[4] Tool response 2  
[5] Assistant: results ← index 5 > 1: Shows thinking ✓
[6] User: "Calculate 7*2 and weather Paris" ← NEW last_query_index = 6
[7] Assistant: calls tools ← index 7 > 6: Shows thinking ✓
[8] Tool response 1
[9] Tool response 2
[10] Assistant: results ← index 10 > 6: Shows thinking ✓

The difference: Tool responses add extra messages, pushing more assistants above the “thinking boundary.”

🚀 Practical Usage Tips

1. Expect More Thinking with Tools

When you use tools, you’ll see reasoning for:

  • The assistant calling the tools
  • The assistant processing tool results
  • Every round of tool usage

2. Design Your UI Accordingly

# Your UI should handle multiple thinking blocks
for response_chunk in model_output:
    if "<think>" in response_chunk:
        display_reasoning(response_chunk)
    else:
        display_response(response_chunk)

3. Tool Call Format

Always call multiple tools like this:

"tool_calls": [
    {"id": "call_1", "function": {"name": "calculator", "arguments": {...}}},
    {"id": "call_2", "function": {"name": "weather", "arguments": {...}}}
]

4. Understanding Tool Responses

Each tool call gets its own response:

{"role": "tool", "tool_call_id": "call_1", "name": "calculator", "content": "8"}
{"role": "tool", "tool_call_id": "call_2", "name": "weather", "content": "Tokyo: 22°C"}