﻿# [Important Notice]Passing Back reasoning_content in Multi-Turn Conversations for Agent Products

To ensure the reasoning quality of our models, we are issuing the following guidance on how `reasoning_content` must be passed back in multi-turn conversation scenarios for Agent-style products.

**1. Scope and Requirement**

When the MiMo thinking mode is enabled in multi-round conversations within Agent-based products, and there are tool calls in the conversation history, the `reasoning_content` field must be fully returned in any subsequent user interaction rounds where the returned assistant message contains tool calls. Otherwise, the API will return a 400 error.

This requirement exists because missing historical `reasoning_content` leads to an incomplete model context, which may result in decreased instruction-following ability, increased hallucinations, and an overall degraded user experience.

**2. Affected Agent Products**

The affected agent products are shown in the following table. We're actively working with the maintainers to push compatibility updates. 

<table>
<colgroup>
<col />
<col style="width: 720px" />
</colgroup>
<thead>
<tr>
<th>Protocol</th>
<th>**Affected Agent Products**</th>
</tr>
</thead>
<tbody>
<tr>
<td>OpenAI Compatibility Protocol</td>
<td>TRAE, Cursor, Roo Code, Codex, GitHub Copilot CLI, Zed, AutoGen, Goose</td>
</tr>
<tr>
<td>Anthropic Compatibility Protocol</td>
<td>TRAE, GitHub Copilot CLI, AutoGen, Goose, OpenClaw, OpenCode, Kilo Code</td>
</tr>
</tbody>
</table>

**3. Affected Models**

MiMo-V2.5-Pro, MiMo-V2.5, MiMo-V2-Pro, MiMo-V2-Omni, MiMo-V2-Flash

**4. Sample Code for Correct Usage**

**Code Sample**

```python
import os
import json
from openai import OpenAI

# Initialize client
client = OpenAI(
    api_key=os.environ.get("MIMO_API_KEY"),
    base_url="https://api.xiaomimimo.com/v1"
)

# Define tools
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Get the current weather for a given city",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "City name, e.g. Beijing"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
                },
                "required": ["location"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_time",
            "description": "Get the current time in a given timezone",
            "parameters": {
                "type": "object",
                "properties": {
                    "timezone": {"type": "string", "description": "Timezone, e.g. Asia/Shanghai"}
                },
                "required": ["timezone"]
            }
        }
    }
]

# Tool execution functions (replace with real API calls in production)
def get_current_weather(location: str, unit: str = "celsius") -> str:
    weather_data = {"Beijing": "Sunny 25°C", "Shanghai": "Cloudy 22°C", "Shenzhen": "Rainy 28°C"}
    return weather_data.get(location, f"Weather unknown for {location}")

def get_time(timezone: str) -> str:
    from datetime import datetime
    return datetime.now().strftime(f"%Y-%m-%d %H:%M:%S ({timezone})")

TOOL_MAP = {
    "get_current_weather": lambda **kw: get_current_weather(**kw),
    "get_time": lambda **kw: get_time(**kw)
}

def run_turn(messages, turn_num):
    """Execute a single user turn: call model, run tools in a loop until final answer."""
    request_num = 0
    while True:
        request_num += 1
        print(f"\nRequest {turn_num}-{request_num}:")

        response = client.chat.completions.create(
            model="mimo-v2.5-pro",
            messages=messages,
            tools=tools,
            extra_body={"thinking": {"type": "enabled"}}
        )

        assistant_message = response.choices[0].message
        messages.append(assistant_message)

        # Print full model response
        print(f"reasoning_content: {assistant_message.reasoning_content}")
        print(f"content: \"{assistant_message.content}\"")
        print(f"tool_calls: {assistant_message.tool_calls}")

        # If no tool calls, we have the final answer
        if not assistant_message.tool_calls:
            break

        # Execute each tool call and append results
        for tool_call in assistant_message.tool_calls:
            func_name = tool_call.function.name
            func_args = json.loads(tool_call.function.arguments)
            result = TOOL_MAP[func_name](**func_args)

            print(f"-> Tool result [{func_name}]: {result}")
            messages.append({
                "role": "tool",
                "tool_call_id": tool_call.id,
                "content": result
            })

# --- Multi-turn conversation ---
messages = []

# Turn 1
print("=== Turn 1 ===")
messages.append({"role": "user", "content": "How is the weather in Beijing today? What time is it now?"})
run_turn(messages, turn_num=1)

# Turn 2: reasoning_content from Turn 1 is already in messages via assistant_message
print("\n=== Turn 2 ===")
messages.append({"role": "user", "content": "How about Shanghai? And is it hotter or colder than Beijing?"})
run_turn(messages, turn_num=2)
```

**Example Output**

**Turn 1:**

The user asks about Beijing's weather and current time. After receiving the message, the model thinks and decides to call both `get_current_weather` and `get_time` tools simultaneously (Request 1-1). The client executes the tools, appends the results as `role: "tool"` messages to `messages`, and calls the model again. The model then generates the final answer based on tool results (Request 1-2).

```bash
=== Turn 1 ===

Request 1-1:
reasoning_content: The user wants to know two things:
1. The current weather in Beijing
2. The current time in Beijing

I can call both functions at the same time since they are independent of each other.
content: ""
tool_calls: [ChatCompletionMessageFunctionToolCall(id='call_dd34ce1810be4afbaaa11c9a', function=Function(arguments='{"location": "Beijing"}', name='get_current_weather'), type='function'), ChatCompletionMessageFunctionToolCall(id='call_cf4c667abd094ce090b40f00', function=Function(arguments='{"timezone": "Asia/Shanghai"}', name='get_time'), type='function')]
-> Tool result [get_current_weather]: Sunny 25°C
-> Tool result [get_time]: 2026-05-12 16:37:26 (Asia/Shanghai)

Request 1-2:
reasoning_content: I got the results for both calls. Let me present this information in a friendly way.
content: "Here's the information for Beijing:

☀️ **Weather:** Sunny, 25°C — a lovely day!

🕒 **Current Time:** 2026年5月12日 16:37 (北京时间)

Looks like a beautiful afternoon in Beijing! Perfect weather for being outdoors. Is there anything else you'd like to know? 😊"
tool_calls: None
```

**Turn 2:**

The user follows up asking about Shanghai's weather and comparing it with Beijing. Since Turn 1's `assistant` message (containing `reasoning_content`, `content`, and `tool_calls`) has been accumulated into the conversation history via `messages.append()`, the model can directly access Beijing's 25°C information from context. It only needs to call `get_current_weather` for Shanghai (Request 2-1), then generates a comparison based on both cities' weather data (Request 2-2).

```bash
=== Turn 2 ===

Request 2-1:
reasoning_content: The user wants to know the weather in Shanghai and compare it with Beijing. I already know Beijing is 25°C, so I just need to get Shanghai's weather.
content: ""
tool_calls: [ChatCompletionMessageFunctionToolCall(id='call_f4fc7fdbfbd14cb497026d21', function=Function(arguments='{"location": "Shanghai"}', name='get_current_weather'), type='function')]
-> Tool result [get_current_weather]: Cloudy 22°C

Request 2-2:
reasoning_content: Shanghai is 22°C and cloudy, while Beijing is 25°C and sunny. So Shanghai is 3°C cooler than Beijing.
content: "Here's the weather for Shanghai:

☁️ **Weather:** Cloudy, 22°C

And comparing the two cities:

| City | Temperature | Conditions |
|------|------------|------------|
| Beijing | 25°C | ☀️ Sunny |
| Shanghai | 22°C | ☁️ Cloudy |

**Beijing is 3°C warmer** than Shanghai right now! Beijing also has clearer skies, while Shanghai is a bit cloudier. Both are pleasant temperatures though — great weather in both cities! 😊

Is there anything else you'd like to check?"
tool_calls: None
```
