2026-05-20 21:39:12 +08:00

62 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Thinking/Reasoning 能力系统
created: 2026-04-14
updated: 2026-04-14
type: concept
tags: [llm, agent, runtime]
sources: [packages/backend/src/modules/netaclaw/runtime/thinking.ts, packages/backend/src/modules/netaclaw/plugins/llm_providers/anthropic.ts]
---
# Thinking/Reasoning 能力系统
统一管理不同 LLM 提供商的思考/推理能力,支持会话级动态调节思考深度。
## 支持的模型
| 提供商 | 模型 | 机制 | 级别 |
|--------|------|------|------|
| Anthropic | claude-3-5-sonnet, claude-4* | extended_thinking (budget_tokens) | minimal(2k)/low(4k)/medium(8k)/high(16k) |
| Anthropic | claude-4.6+ | adaptive thinking | 自适应(无需指定预算) |
| OpenAI | o1, o3 | reasoning_effort | low/medium/high |
| DeepSeek | deepseek-r1 | reasoning_content 字段 | 无级别控制 |
## 核心函数runtime/thinking.ts
| 函数 | 用途 |
|------|------|
| `isThinkingSupported(model)` | 检查模型是否支持思考 |
| `supportsAdaptiveThinking(model)` | 检测 Claude 4.6+ 自适应思考 |
| `getModelThinkingCapability(supplier, model)` | 返回能力描述supported, adaptive, levels, defaultLevel |
| `buildAnthropicThinkingParams(model, level)` | 构建 Anthropic 参数adaptive 或 budget_tokens |
| `buildOpenAIThinkingParams(level)` | 构建 OpenAI reasoning_effort 参数 |
## 参数注入
**Anthropic 适配器**
- 自适应模式:`thinking: { type: 'adaptive' }` + beta header `interleaved-thinking-2025-05-14`
- 固定预算:`thinking: { type: 'enabled', budget_tokens: N }` + 强制 `temperature: 1.0`
**OpenAI 适配器**
- `reasoning_effort: 'low' | 'medium' | 'high'`
## 思考内容提取
| 提供商 | 提取方式 |
|--------|---------|
| Anthropic | response.content[] 中 `{ type: 'thinking' }` 块 |
| OpenAI/o1/o3 | `thinking` 字段 |
| DeepSeek-R1 | `reasoning_content` 字段 |
| 通用 | `<think>...</think>` 标签解析 |
## 会话级控制
优先级链:会话级 `sessionThinkLevel` > Agent 配置 `defaultThinkLevel` > 模型默认值
前端通过 `ClientSetThinkingLevelMessage` WebSocket 消息动态调节,服务端通过 `ServerThinkingEvent` / `ServerThinkingDeltaEvent` / `ServerThinkingDoneEvent` 流式推送思考内容。
## 相关页面
- [[llm-providers]] — 提供商适配层实现
- [[agent-runtime]] — 运行时集成思考参数
- [[websocket-gateway]] — 思考事件的 WebSocket 协议