官方给出的 GLM-5.2 迁移清单与参数配置:模型 ID 改为 glm-5.2、temperature 默认 1.0 / top_p 默认 0.95(二选一调参)、思考默认开启、reasoning_effort 用 high 或 max、流式与工具流式(stream=true + tool_stream=true)需按官方方式拼接,并附可直接使用的 Python 迁移示例。
适合的任务:从 GLM-5.1、GLM-5、GLM-4.7/4.6/4.5 等旧模型切换到 GLM-5.2 的存量应用;需要流式输出、流式工具调用、思考内容读取的 Agent/编码产品;需要明确采样参数与思考档位的后端集成。
不适合的任务:依赖"关闭思考省 token"的旧逻辑(GLM-5.2 思考默认开启,应改用 reasoning_effort 控制成本);GLM-4.7 时代的"强制思考"行为假设(GLM-5.2 是模型自动判断是否需要思考)。
适用的模型版本:GLM-5.2(文中参数对 GLM-5.1/GLM-5 系列同样适用,思考默认行为一致)。
适用的客户端、Agent 或 API:Z.ai Chat Completions API(OpenAI 兼容);使用 delta.reasoning_content / delta.content / delta.tool_calls 的流式客户端。
推荐的推理档位和参数:thinking: {"type": "enabled"}(复杂推理/编码推荐开启);reasoning_effort: high(增强推理)或 max(深度推理,默认);temperature 与 top_p 只调其中一个;max_tokens 按任务设置(上限 128K)。
模型标识改为 glm-5.2
采样参数:temperature 默认 1.0、top_p 默认 0.95,建议只调其中一个
深度思考:按需 thinking={"type": "enabled"} 用于复杂推理/编码
推理档位:reasoning_effort 在 high(增强推理)与 max(深度推理,默认)之间选择
流式响应:stream=true,正确处理 delta.reasoning_content 与 delta.content
流式工具调用:stream=true + tool_stream=true,流式拼接 delta.tool_calls[*].function.arguments
最大输出与上下文:max_tokens 按需设置(GLM-5.2 上限 128K 输出、1M 上下文)
提示词优化:配合深度思考使用更清晰的指令和约束
开发环境验证:回归测试关注随机性、延迟、工具流式参数完整性
# Plan A: Use temperature (recommended)
resp = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Write a more creative brand introduction"}],
temperature=1.0
)
# Plan B: Use top_p
resp = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Generate more stable technical documentation"}],
top_p=0.8
)resp = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Design a three-tier microservice architecture for me"}],
thinking={"type": "enabled"},
reasoning_effort="max"
)response = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "How's the weather in Beijing"}],
tools=[
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather conditions for a specified location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City, eg: Beijing, Shanghai"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
],
stream=True,
tool_stream=True,
)
# Initialize streaming collection variables
reasoning_content = ""
content = ""
final_tool_calls = {}
reasoning_started = False
content_started = False
# Process streaming response
for chunk in response:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
# Streaming reasoning process output
if hasattr(delta, 'reasoning_content') and delta.reasoning_content:
if not reasoning_started and delta.reasoning_content.strip():
print("\n🧠 Thinking Process:")
reasoning_started = True
reasoning_content += delta.reasoning_content
print(delta.reasoning_content, end="", flush=True)
# Streaming answer content output
if hasattr(delta, 'content') and delta.content:
if not content_started and delta.content.strip():
print("\n\n💬 Answer Content:")
content_started = True
content += delta.content
print(delta.content, end="", flush=True)
# Streaming tool call information (parameter concatenation)
if delta.tool_calls:
for tool_call in delta.tool_calls:
idx = tool_call.index
if idx not in final_tool_calls:
final_tool_calls[idx] = tool_call
final_tool_calls[idx].function.arguments = tool_call.function.arguments
else:
final_tool_calls[idx].function.arguments += tool_call.function.arguments
# Output final tool call information
if final_tool_calls:
print("\n📋 Function Calls Triggered:")
for idx, tool_call in final_tool_calls.items():
print(f" {idx}: Function Name: {tool_call.function.name}, Parameters: {tool_call.function.arguments}")上下文最大 1M、输出最大 128K。
新增工具调用过程流式输出(tool_stream=true),可实时拿到工具调用参数。
深度思考 thinking={"type":"enabled"}:开启后模型自动判断是否思考(区别于 GLM-4.7 的强制思考)。
新增 reasoning_effort 参数控制思考档位。
更强的代码能力与推理能力。
官方原文使用"深度思考默认开启"表述:思考在 GLM-5.2/5.1/5/4.7 系列默认激活(见思考模式文档),与 GLM-4.6 的混合思考默认行为不同。
迁移后回归重点:输出随机性是否过大或过于保守、工具流式拼接是否正常、长上下文与深度思考下的延迟与成本。
GLM-5.2