> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hitheo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Theo 是如何思考的

> 支撑每一次 API 调用的多阶段编排流水线。

每次调用 `POST /api/v1/completions` 时，Theo 运行的都是一条多阶段编排流水线——而不是单次模型调用。你只需发送一个请求，Theo 会自动完成意图分类、路由、技能注入、工具执行、回退和计费。

## 流水线

```
Your prompt
  │
  ▼
┌─────────────────────┐
│  Intent Classifier   │  ← Determines the best execution mode
│  Determines: mode,   │
│  confidence, tools   │
└────────┬────────────┘
         │
         ▼
┌─────────────────────┐
│  Skill Loader        │  ← Loads installed skills + per-request skill slugs
│  Merges: prompts,    │
│  tools, engine prefs │
└────────┬────────────┘
         │
         ▼
┌─────────────────────┐
│  Engine Router       │  ← Selects the optimal Theo engine
│  Checks: availability│     Falls back automatically if primary is down
│  + failover          │
└────────┬────────────┘
         │
         ▼
┌─────────────────────┐
│  Agent Loop          │  ← Think → act → observe, iterates until done
│  Calls tools, feeds  │
│  results back in     │
└────────┬────────────┘
         │
         ▼
┌─────────────────────┐
│  Response            │  ← Formatted, billed, cached, audited
└─────────────────────┘
```

## 第 1 阶段：意图分类

当你发送 `mode: "auto"`（默认值）时，Theo 会对你的提示词进行分类，以确定最合适的执行模式。

Theo 使用多层分类系统，将快速启发式规则与 AI 驱动的分析相结合，从而准确地路由你的请求。明显的信号（例如 "帮我画一个 logo" → `image`）会被即时识别。含义模糊的提示词则会被更深入地分析。

**覆盖：**
如果你显式传入 `mode: "code"`，分类过程会被完全跳过。

最终确定的模式决定了由哪个 Theo 引擎处理该请求、使用哪个系统提示词，以及会给出哪些后续建议。

## 第 2 阶段：技能加载

技能从两个来源加载：

1. **已安装的技能** —— 每次请求都会加载的常驻技能
2. **按请求加载的技能** —— 在 `skills[]` 数组中传入的技能 slug，按需加载

每个已加载的技能都会提供以下内容：

* **系统提示词扩展** —— 注入上下文中的领域专属指令
* **工具定义** —— 引擎可以调用的可执行操作
* **引擎偏好** —— 该技能可以推荐由哪个 Theo 引擎来处理其任务效果最佳

所有技能提示词都会被聚合并沙箱隔离，以确保彼此互不干扰。

## 第 3 阶段：引擎路由

Theo 会根据最终确定的模式选择最优引擎：

|| Mode | Engine | Description |
||------|--------|-------------|
|| fast / auto | `theo-1-flash` | 快速、轻量的补全 |
|| think | `theo-1-reason` | 深度推理与分析 |
|| code | `theo-1-code` | 生产级代码生成 |
|| image | `theo-1-create` | 图像生成 |
|| video | `theo-1-motion` | 视频生成 |
|| research | `theo-1-research` | 多步骤网络研究 |
|| roast | `theo-1-edge` | 无过滤的幽默吐槽 |
|| genui | `theo-1-genui` | 生成式 UI 组件 |

如果主引擎不可用，Theo 会自动回退到备用引擎——你永远不会看到失败的响应。

## 第 4 阶段：代理循环

对于有可用工具的请求，Theo 会进入一个迭代式的代理循环：

```
Iteration 0: Engine reads prompt + system prompt + tool definitions
             → Responds with text AND a tool call
             → Theo executes the tool, gets result

Iteration 1: Engine reads the tool result + previous context
             → Responds with text (no more tool calls)
             → Final response returned to caller
```

该循环会持续进行，直到任务完成或达到迭代次数上限。对于没有工具的简单提示词，循环会收缩为单次调用——不产生额外开销。

## 第 5 阶段：响应

最终响应包含：

* `content` —— 生成的文本
* `model` —— 处理该请求的 Theo 引擎（例如 `theo-1-reason`）
* `tools_used` —— 被调用的工具及其状态
* `artifacts` —— 任何生成的文件（图像、代码、文档）
* `follow_ups` —— 建议的后续提示词
* `usage` —— 令牌计数与以美分计的费用

该响应同时会被**计费**、**缓存**（相同请求可零成本即时返回）并**审计**（记录到不可篡改的审计日志中）。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.