API 概览
不同厂商对“模型请求调用外部能力”这件事,命名不同,但核心思想相同:
| Provider | 常见术语 | 典型响应承载位置 |
|---|---|---|
| OpenAI | tool calls | message.tool_calls |
| Anthropic | tool use | content blocks |
| Gemini | function calling | SDK / response parts |
统一抽象
如果你要做 provider adapter,建议内部统一成一套中间结构:
ts
interface NormalizedToolCall {
provider: 'openai' | 'anthropic' | 'gemini'
id: string
name: string
input: Record<string, unknown>
raw: unknown
}这样你的业务层就不需要知道每个 provider 原始 JSON 的细节。
通用闭环
text
定义工具
↓
发送用户消息 + tools
↓
读取模型返回的工具调用
↓
执行工具
↓
把结果回填给模型
↓
获得最终自然语言输出