
前面是通过 提示词 的形式,将工具箱带过去。
这种方式有什么问题?
- 繁琐:大段大段的提示词,仅仅是为了约束大模型的输出
- 不标准:每个开发者的提示词的描述千差万别
- 约束力不高:即便使用了语气最重的提示词,大模型的底层原理决定了它总会有不按照要求回复的情况
- 工具箱的提供
// 工具箱
const tools = [{
type: "function",
name: "get_weather",
description: "Get current temperature for provided coordinates in celsius.",
parameters: {
type: "object",
properties: {
latitude: { type: "number" },
longitude: { type: "number" }
},
required: ["latitude", "longitude"],
additionalProperties: false
},
strict: true
}];
- 返回的调用工具请求
[{
"type": "function_call",
"id": "fc_12345xyz",
"call_id": "call_12345xyz",
"name": "get_weather",
"arguments": "{\"latitude\":48.8566,\"longitude\":2.3522}"
}]
不同的模型,Function Calling的格式不一致。
deepseek
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather of an location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
}
},
"required": ["location"]
},
}
}]
GPT
const tools = [{
type: "function",
name: "get_weather",
description: "Get current temperature for provided coordinates in celsius.",
parameters: {
type: "object",
properties: {
latitude: { type: "number" },
longitude: { type: "number" }
},
required: ["latitude", "longitude"],
additionalProperties: false
},
strict: true
}];
claude
"tools": [{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}],




