--- title: LLM 提供商适配 created: 2026-04-13 updated: 2026-04-14 type: entity tags: [llm, agent, api] sources: [packages/backend/src/modules/netaclaw/plugins/llm_providers/, packages/backend/src/modules/netaclaw/runtime/thinking.ts] --- # LLM 提供商适配 多模型提供商的统一适配层,将不同 API 格式转换为内部统一接口。支持 Thinking/Reasoning 能力的统一管理。 ## 关键文件 | 文件 | 提供商 | API 格式 | |------|--------|---------| | `llm_providers/anthropic.ts` | Anthropic | Messages API(原生,支持 extended_thinking) | | `llm_providers/openai.ts` | OpenAI / 兼容 | Chat Completions(支持 reasoning_effort) | | `llm_providers/deepseek.ts` | DeepSeek | OpenAI 兼容格式(支持 reasoning_content) | | `llm_providers/plugin_entry.ts` | - | 提供商接口定义 | | `llm_providers/logging.ts` | - | 请求/响应日志 | | `runtime/thinking.ts` | - | 思考能力检测、预算映射、参数构建 | ## 模型选择 通过 `runtime/model_selection.ts` 解析 `"provider:modelId"` 格式: ``` "anthropic:claude-3-5-sonnet" → Anthropic 适配器 "openai:gpt-4o" → OpenAI 适配器 "openai:MiniMax-M2.7" → OpenAI 兼容(自定义 baseUrl) "deepseek:deepseek-chat" → DeepSeek 适配器 ``` ## Thinking/Reasoning 支持 各提供商的思考能力通过 `runtime/thinking.ts` 统一管理: | 提供商 | 参数注入 | 思考内容提取 | |--------|---------|-------------| | Anthropic | `thinking: { type: 'adaptive' }` 或 `{ type: 'enabled', budget_tokens: N }` | response.content[] 中 `{ type: 'thinking' }` 块 | | OpenAI | `reasoning_effort: 'low'|'medium'|'high'` | `thinking` 字段 | | DeepSeek | 无参数控制 | `reasoning_content` 字段 或 `` 标签 | 详见 [[thinking-system]]。 ## 模型渠道管理 通过 `netaclaw_model_channel` 表配置: - `supplier`:OpenAI / Anthropic / DeepSeek - `baseUrl`:API 地址(支持自定义,如 MiniMax) - `apiKey`:密钥 - `models`:JSON 数组 `[{name, capability}]` 前端通过级联选择器选择:供应商 → 渠道 → 模型 ## 相关页面 - [[netaclaw-module]] — 所属模块 - [[agent-runtime]] — 运行时初始化提供商 - [[thinking-system]] — Thinking/Reasoning 能力详解 - [[crew-orchestration]] — Crew 编排中的模型配置解析