> ## 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.