# 自动模型路由

代理中的不同部分想要不同的模型。长推理需要前沿模型。快速的“修正这个拼写错误”调用需要一个又快又便宜的模型。视觉任务需要视觉模型。OpenHuman 通过内置的 **路由提供程序** 来处理这一切，因此你无需为此费心。

## 请求如何被路由

任何聊天调用上的 model 参数都可以采用以下两种形式之一：

* **具体模型名称**。例如 `anthropic/claude-sonnet-4`。路由到默认提供程序，并使用该精确模型。
* **提示前缀**。例如 `hint:reasoning`。会在路由表中查找该提示，并解析为一个 `（提供程序，模型）` 对。

```rust
// src/openhuman/providers/router.rs
fn resolve(&self, model: &str) -> (usize, String) {
    if let Some(hint) = model.strip_prefix("hint:") {
        if let Some((idx, resolved_model)) = self.routes.get(hint) {
            return (*idx, resolved_model.clone());
        }
    }
    (self.default_index, model.to_string())
}
```

路由器包装了多个预先创建的提供程序（Anthropic、OpenAI、Google、Groq 等），并根据每个请求选择合适的一个。提示可以在运行时重新映射，而无需重启核心。

## 常见提示

| 提示               | 典型目标        | 使用场景              |
| ---------------- | ----------- | ----------------- |
| `hint:reasoning` | 一个强大的推理模型   | 多步规划、数学、重代码的轮次    |
| `hint:fast`      | 一个快速/便宜的模型  | UI 辅助、自动补全、小型分类调用 |
| `hint:vision`    | 一个具备视觉能力的模型 | 截图、图片附件、OCR       |
| `hint:summarize` | 一个擅长压缩的模型   | 记忆树摘要构建器          |
| `hint:code`      | 一个针对代码优化的模型 | 原生编码轮次            |

精确映射是可配置的；默认配置会随附每个提供程序都合理的路由。

## 一个订阅

路由发生在单一的 OpenHuman 订阅之后。你无需为 Anthropic、OpenAI、Google 等分别持有单独的 API 密钥，后端会代理访问，而路由器会为每个任务选择合适的那个。这就是 README 中“一个订阅，多个提供程序”的承诺，变得具体可见。

## 覆盖路由

* **全局**。config TOML（`Config` 结构体位于 `src/openhuman/config/schema/types.rs`）可在启动时提供自定义路由表。
* **每次调用**。传入一个具体的模型名称（不带 `hint:` 前缀），路由器就会直接落到默认提供程序并使用该精确模型。
* **针对某项技能**。技能可以在其清单中固定一个提示或模型。

## 每个代理的模型固定

子代理也可以固定一个精确模型，而不会为应用其余部分禁用自动路由。当编排器或团队负责人需要更强的模型，而高频的叶子代理应继续使用更便宜的模型时，就用这种方式。

一次委派时，内联调用优先：

```json
{
  "agent_id": "researcher",
  "model": "anthropic/claude-sonnet-4",
  "prompt": "收集发布备忘录的来源笔记。"
}
```

持久默认值保存在 `config.toml`:

```toml
[orchestrator]
model = "anthropic/claude-sonnet-4"

[teams.research]
lead_model = "openai/gpt-5.1"
agent_model = "groq/llama-3.1-8b-instant"

[teams.code]
agent_model = "qwen/qwen3-coder"
```

解析顺序：

1. 内联 `model` 在 `spawn_subagent` 或原型委派调用上。
2. `[orchestrator].model` 或 `[teams.<team>]` / 内置别名，例如 `[teams.research]` 和 `[teams.code]`.
3. 该原型自身的模型提示以及正常的路由表。

对于 `[teams.*]`, `lead_model` 适用于可以委派的代理，而 `agent_model` 适用于叶子工作者。如果只设置了其中一个，框架会将其回退用于这两种角色。

## 为什么这不只是“模型切换器”

路由并不是一个 UI 下拉框。代理循环本身会根据即将执行的操作发出提示。不是你来选择模型；而是 *任务* 来决定。这就是“多模型”和“智能路由”之间的区别。

## 另请参阅

* [智能令牌压缩](/openhuman/zh/gong-neng/token-compression.md)。让大规模推理调用变得经济实惠的关键。
* [原生工具](/openhuman/zh/gong-neng/native-tools.md)。不同的工具调用会暗示不同的路由。
* [本地 AI（可选）](/openhuman/zh/gong-neng/model-routing/local-ai.md)。轻量级聊天提示可在设备上运行。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tinyhumans.gitbook.io/openhuman/zh/gong-neng/model-routing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
