When calling LongCat-Flash-Thinking-2601 locally with Transformers, use the repository's apply_chat_template, explicitly enable thinking, and pass tools as needed instead of hand-writing special tokens.
Suitable tasks: Local Transformers inference, multi-turn deep reasoning, tool calling, and tool-result injection.
Unsuitable tasks: Applying this directly to a third-party API that does not implement this template; the model card does not provide field mappings for general-purpose service providers.
Applicable model version: meituan-longcat/LongCat-Flash-Thinking-2601.
Applicable client, Agent, or API: Hugging Face Transformers; the model card also mentions SGLang/vLLM, but the code on this page is a local tokenizer/model invocation example.
Recommended inference tier and parameters: The official example uses enable_thinking=True, add_generation_prompt=True, and max_new_tokens=32768; no fixed temperature is publicly disclosed, and the high-temperature recommendation for Heavy Thinking applies only to multi-trajectory exploration.
The key invocation structure from the model card is retained below; replace model and tokenizer with locally loaded objects. Tool declarations and message fields must retain the OpenAI-style tools, tool_calls, and reasoning_content structure.
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "meituan-longcat/LongCat-Flash-Thinking-2601"
tokenizer = AutoTokenizer.from_pretrained(model_name)
# model = AutoModelForCausalLM.from_pretrained(model_name, ...)
tools = [{
"type": "function",
"function": {
"name": "func_add",
"description": "Calculate the sum of two numbers",
"parameters": {
"type": "object",
"properties": {
"x1": {"type": "number", "description": "The first addend"},
"x2": {"type": "number", "description": "The second addend"}
},
"required": ["x1", "x2"]
}
}
}]
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Please tell me what is 125679 + 234519?"},
{
"role": "assistant",
"reasoning_content": "This calculation requires precision; I will use the func_add tool.",
"tool_calls": [{
"type": "function",
"function": {
"name": "func_add",
"arguments": {"x1": 125679, "x2": 234519}
}
}]
},
{"role": "tool", "name": "func_add", "content": '{"ans": 360198}'}
]
text = tokenizer.apply_chat_template(
messages,
tools=tools,
tokenize=False,
enable_thinking=True,
add_generation_prompt=True,
save_history_reasoning_content=False
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
print(tokenizer.decode(output_ids, skip_special_tokens=True).strip("\n"))Register the tool schema and pass the tool list to apply_chat_template.
Send the user task; when the model returns reasoning_content and tool_calls, execute the real tool using the call arguments.
Append the tool result as a role=tool message, then call the template and model again.
By default, use save_history_reasoning_content=False to discard historical reasoning and save context; switch it to True when historical reasoning must be retained, and monitor context length separately.
The model card directly provides tokenizer.apply_chat_template(messages, tools=tools, tokenize=False, enable_thinking=True, add_generation_prompt=True, save_history_reasoning_content=False).
The official tool example uses func_add, the tool result is {"ans": 360198}, and the example sets the generation limit to max_new_tokens=32768.
The model card states that tool declarations appear at the beginning of the conversation; the default interleaved thinking mode retains the final answer and tool trajectory while discarding earlier reasoning.
This is the local template for the 2601 weights, not the request format of every hosted API; an API gateway may rewrite reasoning_content or tool fields.
A model with 560B total parameters has demanding VRAM, parallelism, and quantization requirements; the code snippet on this page does not promise that it can run on consumer hardware.
max_new_tokens=32768 is the official example value, not the optimal value for every task; long reasoning substantially increases cost and latency.
The model card does not disclose fixed temperature, top-p, or Heavy Thinking trajectory counts, so no universal parameter set can be inferred from this example.
The page explicitly makes retaining reasoning history optional: disable save_history_reasoning_content to save tokens, and enable it when a complete review is needed.
LongCat Flash Thinking