函数调用
向模型声明工具,让模型返回结构化参数,再由你的应用执行真实操作。
声明工具
json
{
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "上海天气怎么样?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}执行闭环
- 验证模型返回的函数名和参数
- 在你的服务端执行函数
- 将工具结果作为 tool 消息加入对话
- 再次调用模型生成最终回复
安全边界
模型只能提出调用建议。权限校验、参数验证、超时和副作用确认必须由你的应用完成。
