功能特性
工具调用
使用标准 tools、tool_choice 和 tool_calls 结构连接模型与外部系统。
函数调用让模型输出结构化的工具调用意图。应用负责真正执行工具,因此可以在执行前加入权限、确认、审计和幂等控制。
标准请求体
{
"model": "glm-5.1",
"messages": [
{
"role": "user",
"content": "上海现在天气如何?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "获取指定城市的当前天气",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称"
}
},
"required": ["city"],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto"
}模型返回的调用
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_weather_01",
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": "{\"city\":\"上海\"}"
}
}
]
}工具结果消息
{
"role": "tool",
"tool_call_id": "call_weather_01",
"content": "{\"city\":\"上海\",\"temperature\":25,\"condition\":\"多云\"}"
}版本说明
旧结构 functions
functionsfunction_call- 旧教程中仍然常见
当前结构 tools
toolstool_choicemessage.tool_calls
完整的应用执行与结果回传代码,请继续阅读用户指南中的函数调用。