Autonomous Deep
Research Engine
自主深度
研究引擎
A full-stack platform where an AI agent triages each question's complexity, routes it to the right strategy, then runs multi-round web search with cross-verification — delivering fully cited Markdown reports. 全棧研究平台:AI 代理自動判斷每個問題的難度,路由到對應的研究策略,執行多輪網頁搜尋與交叉驗證,最後產出附完整引用的 Markdown 報告。
The "agent" in this project isn't a custom model — it's OpenAI's Codex CLI, given three different prompt-based skills (below) and shelled out to as a subprocess. There's no benchmark measuring whether skill tuning improves report accuracy over time, so this case study doesn't claim one. What it shows instead: the actual routing architecture, and one real end-to-end run of the deep-research skill on a genuine topic, with real citations. 這個專案裡的「代理」不是自建模型 —— 它是 OpenAI 的 Codex CLI,接上下方三種提示詞式技能,以子行程方式呼叫執行。沒有衡量標準能證明技能調整長期下來有沒有讓報告變準,所以這篇案例研究不做這個宣稱。取而代之,這裡展示的是實際的路由架構,以及一次真實跑完的 deep-research 技能執行結果,附真實引用來源。
Three-Tier Routing三級難度路由
A lightweight classifier reads the question first and assigns it to one of three skills — each just a Markdown prompt file loaded at runtime and embedded into the Codex CLI's codex exec command.
一個輕量分類器先讀懂問題,把它分派到三種技能之一 —— 每種技能其實就是一份 Markdown 提示詞檔案,在執行時載入並嵌進 Codex CLI 的 codex exec 指令裡。
Tier 1 · quick-answer
No Search不搜尋
Definitions, simple facts, greetings — answered directly from the model's own knowledge in 1–5 paragraphs. 定義、簡單事實、打招呼 —— 直接用模型自身知識回答,1–5 段文字。
Tier 2 · standard-research
2–4 Queries2–4 次搜尋
Recent news, specific lookups, comparisons — a single research pass with source citations, moderate depth. 近期新聞、特定資料查詢、比較 —— 單輪研究並附來源引用,深度適中。
Tier 3 · deep-research
Multi-Round + Cross-Check多輪+交叉驗證
3–7 sub-questions, 2+ search queries each, conflicting info flagged explicitly. Used for the sample report below. 拆成 3–7 個子問題,每個至少 2 次搜尋,明確標出互相矛盾的資訊。下方範例報告用的就是這一級。
Progress streams to the frontend as JSONL events parsed from the Codex subprocess's stdout — thread.started, item.completed, turn.completed — polled by the browser, not pushed via WebSocket. 進度會以 JSONL 事件的形式從 Codex 子行程的 stdout 解析並串到前端 —— thread.started、item.completed、turn.completed —— 由瀏覽器輪詢取得,不是用 WebSocket 推播。
Live Sample Run真實執行範例
Rather than mock up a report, this is a real deep-research pass — run live for this case study, following the exact deep-research skill prompt above — on the question: "How are production teams reducing LLM inference cost in 2026?" 8 real web searches, real sources, written in English (the skill writes in whatever language the question is asked in). 與其做一份假報告,這是一次真的 deep-research 執行結果 —— 為了這篇案例研究即時跑的,完全照上面的 deep-research 技能提示詞執行 —— 問題是:「2026 年生產環境的團隊如何降低 LLM 推論成本?」共 8 次真實網頁搜尋、真實來源,以英文撰寫(技能本身會用使用者提問的語言撰寫報告)。
Reducing LLM Inference Cost in Production AI Agent Systems (2026)
降低生產環境 AI 代理系統的 LLM 推論成本(2026)
Executive Summary
摘要
As of mid-2026, four levers dominate production LLM cost reduction: prompt caching (up to 90% off repeated prefixes), complexity-based model routing (20–85% bill reduction by sending easy requests to cheap models), self-hosting open-weight models (favorable only above roughly 10–30M tokens/day, with wide disagreement on the exact break-even point), and knowledge distillation into smaller specialist models (5–30x cheaper inference per token). None of these is a silver bullet alone — 2026-era production stacks combine at least two, most often caching + routing, since they compound rather than compete.
截至 2026 年中,生產環境降低 LLM 成本主要靠四個手段:提示詞快取(重複前綴最高可省 90%)、依複雜度分流的模型路由(把簡單請求導向便宜模型,帳單可降 20–85%)、自架開源權重模型(通常要每天用量超過 1,000–3,000 萬 token 才划算,各方對確切損益平衡點看法差異很大),以及知識蒸餾成較小的專用模型(每 token 推論成本可降至 5–30 倍便宜)。這四者沒有一個是萬靈丹——2026 年的生產架構通常會同時搭配至少兩種,最常見的組合是快取+路由,因為兩者是疊加效果,不是互相排斥。
Background
背景
Enterprises running LLM-backed products at scale in 2026 face a cost structure dominated by input/output token pricing from frontier model APIs. As traffic volume grows, teams that treat every request identically — same model, same context, no reuse — see costs scale linearly with usage. The four techniques below each attack a different part of that cost curve.
2026 年,大規模運行 LLM 產品的企業,成本結構主要由前沿模型 API 的輸入/輸出 token 計價主導。隨著流量成長,如果每個請求都一視同仁——同一顆模型、同樣的上下文、完全不重複使用——成本就會跟用量呈線性成長。下面四種技術,各自針對這條成本曲線的不同環節下手。
Detailed Findings
詳細發現
Prompt Caching
提示詞快取
Every major provider — Anthropic, OpenAI, and Google Gemini — supports prompt caching in 2026, though implementation and discount depth differ: Anthropic caches at roughly 0.1x the input price (a 90% discount) via an explicit request field, OpenAI applies an automatic 0.5x discount with no code change, and Gemini offers 0.1–0.25x pricing plus a separate storage cost [1]. Because caching reuses the computed key-value tensors behind a repeated prompt prefix, it is a pure win for workloads with a stable system prompt or shared context — precisely the shape of this engine's own skill-prompt structure. The recommended 2026 production pattern layers exact-match, semantic, and prefix caches together, and tracks hit rate per layer rather than assuming the pricing-table discount is actually being captured [2].
2026 年主流供應商——Anthropic、OpenAI、Google Gemini——都支援提示詞快取,但實作方式與折扣幅度各不相同:Anthropic 透過明確的請求欄位,把快取部分的計費降到輸入價格的約 0.1 倍(等於打一折,省下 90%);OpenAI 則是自動套用 0.5 倍折扣,不需改程式碼;Gemini 提供 0.1–0.25 倍的計價,但另外收取儲存費用 [1]。由於快取重複使用的是重複提示詞前綴背後已算好的 key-value 張量,對於有固定系統提示詞或共享上下文的工作負載來說是純粹的利多——這正好符合這套引擎自己的技能提示詞結構。2026 年建議的生產模式,是把精確匹配、語意相似、前綴匹配三種快取疊加使用,並逐層追蹤命中率,而不是假設定價表上寫的折扣就真的有吃到 [2]。
Complexity-Based Model Routing
依複雜度分流的模型路由
Model routing sends each request to the cheapest model tier that can still answer it correctly, using an upstream classifier that scores the request as simple / medium / complex before dispatch [3]. Reported savings vary by source: one analysis cites a 20–60% token cost reduction while holding accuracy constant [4], while a vendor case study claims up to 85% savings via multi-model routing [5]. Semantic/ML-based classifiers add roughly 50–100ms of routing overhead — a small fraction of typical 500–2000ms LLM response latency [3]. This is architecturally identical to this project's own quick-answer / standard-research / deep-research split: a classifier decides complexity before any expensive multi-round search runs.
模型路由會在派送請求前,先用一個分類器把請求標記為簡單/中等/複雜,然後導向還能正確回答、但費用最低的模型層級 [3]。各方回報的省錢幅度不一:一份分析指出可在準確率不變的情況下,降低 20–60% 的 token 成本 [4];另一份廠商案例研究則宣稱透過多模型路由可省下高達 85% [5]。語意/ML 分類器大約會增加 50–100 毫秒的路由額外開銷——相對於典型 500–2000 毫秒的 LLM 回應延遲只是很小一部分 [3]。這在架構上跟這個專案自己的「秒答/標準研究/深度研究」三級分流完全一樣:都是先用分類器判斷難度,再決定要不要跑昂貴的多輪搜尋。
Self-Hosting Open-Weight Models vs. API
自架開源權重模型 vs. API
Self-hosting economics improved between 2024 and 2026 as GPU prices fell and open-weight model quality closed the gap with frontier APIs for many text-reasoning tasks [6]. Sources disagree meaningfully on where the break-even point sits: one puts the crossover at 10–30M tokens/day depending on model size and infrastructure [7]; another calculates roughly 5.7 billion tokens/month for a single H100 against a budget API near $0.14/1M input tokens [8]; a third places break-even as low as 5–10M tokens/month for premium models [9]. All sources agree the hidden costs matter: 0.5–1.0 FTE of ongoing DevOps/MLOps time, plus power and cooling running 1.5–2x the GPU's rated draw [9]. Open-model API providers (Together AI, Fireworks, Groq) now undercut frontier APIs enough — Llama 4 70B around $0.20–$0.60/1M tokens blended — that most teams under ~50M tokens/month are better off staying on an API [10].
2024 到 2026 年間,隨著 GPU 價格下跌、開源權重模型在許多文字推理任務上的品質逐漸追上前沿 API,自架的經濟效益跟著改善 [6]。但各方對損益平衡點的看法差異很大:一份資料認為臨界點落在每天 1,000–3,000 萬 token,實際數字要看模型大小與基礎設施而定 [7];另一份計算指出,若拿一張 H100 去對比每百萬輸入 token 約 0.14 美元的平價 API,損益平衡點大約是每月 57 億 token [8];第三份資料則認為,對高階模型來說,損益平衡點低到每月 500–1,000 萬 token 就能達到 [9]。所有資料都同意隱藏成本不能忽視:持續要投入 0.5–1.0 個全職人力做 DevOps/MLOps,加上電力與散熱的實際耗用,通常是 GPU 額定功耗的 1.5–2 倍 [9]。開源模型 API 供應商(Together AI、Fireworks、Groq)現在把價格壓得夠低——Llama 4 70B 混合計價大約每百萬 token 0.20–0.60 美元——讓大多數每月用量在 5,000 萬 token 以下的團隊,繼續用 API 反而更划算 [10]。
Knowledge Distillation into Specialist Models
知識蒸餾成專用模型
Distillation trains a smaller "student" model on a larger "teacher" model's outputs, producing a task specialist that can match or beat the teacher on in-domain tasks at 5–20x lower per-token cost, described as foundational to 2026's "heterogeneous architecture" trend of expensive models planning and cheap models executing [11]. One production write-up reports a 75% inference cost reduction via distillation with no measured quality loss [12], and a research-tooling vendor reports 5–30x cheaper inference from distillation with programmatic data curation [13]. The described 2026 pattern is a size ladder: a frontier teacher model for the hardest ~5% of traffic, a distilled mid-size model for ~80%, and a small/cached path for the rest.
知識蒸餾是用一個較大的「教師」模型的輸出,去訓練一個較小的「學生」模型,讓學生模型在特定領域任務上能追平甚至贏過教師模型,同時每 token 成本降低 5–20 倍——這被視為 2026 年「異質架構」趨勢的基礎:由昂貴模型負責規劃、便宜模型負責執行 [11]。一份實際上線案例回報透過蒸餾把推論成本降低 75%,且沒有測到品質下降 [12];一間研究工具廠商則回報透過蒸餾搭配程式化資料整理,推論成本可降至 5–30 倍便宜 [13]。2026 年常見的模式是一個階梯式架構:最難的約 5% 流量交給前沿教師模型,約 80% 交給蒸餾後的中型模型,其餘走小模型或快取路徑。
Key Insights
關鍵洞見
- Caching and routing are the lowest-risk, highest-ROI levers — no model swap required, and they compound since a cached prefix still benefits from being routed to a cheaper model.
- Self-hosting is a scale decision, not a default: below tens of millions of tokens/month, API pricing (especially open-model APIs) usually wins once DevOps overhead is counted.
- Distillation is the technique with the most direct architectural parallel to this project's own 3-tier skill routing: both bet that most requests don't need the most expensive model available.
- 快取與路由是風險最低、報酬最高的兩個手段——不需要更換模型,而且兩者可以疊加,因為就算前綴已經被快取,還是能再被路由到更便宜的模型上。
- 自架是規模到了才該做的決定,不該是預設選項:只要每月用量低於幾千萬 token,算進 DevOps 的額外負擔後,用 API(尤其是開源模型 API)通常還是比較划算。
- 知識蒸餾是跟這個專案自己的三級技能路由架構最相似的技術:兩者都是賭大多數請求根本不需要用到最貴的那顆模型。
Limitations & Open Questions
限制與待解問題
- Conflicting break-even numbers: sources disagree on the self-hosting crossover point by more than 100x (5M tokens/month vs. 5.7B tokens/month) depending on assumptions about model size, hardware, and comparison API — treat any single break-even figure as scenario-specific, not universal.
- Most sources are vendor blogs or tooling-company content published in 2026 rather than independent academic benchmarks; figures should be read as directional industry claims, not peer-reviewed measurements.
- This report used 8 total search queries across 4 sub-questions in one pass — a production run of this skill would typically go further per the spec (2+ queries per sub-question, re-querying when results are thin).
- 損益平衡點的數字互相矛盾:各方對自架的臨界點看法差了超過 100 倍(每月 500 萬 token vs. 57 億 token),差異來自對模型大小、硬體、比較對象 API 的假設不同——任何單一的損益平衡數字都該視為特定情境下的結果,不是放諸四海皆準的答案。
- 大部分來源是 2026 年發布的廠商部落格或工具公司內容,不是獨立的學術基準測試;這些數字應該視為產業界的方向性說法,不是經過同儕審查的實測數據。
- 這份報告只跑了一輪,4 個子問題總共用了 8 次搜尋——照這個技能原本的規格,正式執行通常會做得更深入(每個子問題至少 2 次搜尋,結果不夠時還會再查)。
Sources
來源
- Prompt Caching in 2026: Cut LLM Costs, Keep Quality — provider-by-provider caching discount rates
- How to Cut LLM Token Costs in 2026 — layered caching strategy
- LLM Model Routing in 2026: Cost-Quality Optimization — routing architecture and latency overhead
- Model Routing LLM: 7 Strategies — 20–60% savings figure
- Intelligent LLM Routing (Swfte AI) — 85% savings case study
- Self-Hosting Open-Weight LLMs: 2026 Decision Guide — self-hosting economics trend
- LLM Hosting Cost 2026 — 10–30M tokens/day break-even
- Self-Hosting vs Cloud APIs: The 2026 Showdown — H100 break-even calculation
- Self-Hosting AI Models vs API Pricing — hidden DevOps/power costs
- Self-Hosted LLM Costs 2026 — open-model API pricing
- Model Distillation for LLMs: Cut Costs & Boost Speed in 2026 — heterogeneous architecture pattern
- How We Reduced LLM Inference Costs by 75% Using Model Distillation — production case study
- Distillation with Programmatic Data Curation — 5–30x inference cost reduction
- Prompt Caching in 2026: Cut LLM Costs, Keep Quality — 各家供應商的快取折扣細節
- How to Cut LLM Token Costs in 2026 — 分層快取策略
- LLM Model Routing in 2026: Cost-Quality Optimization — 路由架構與延遲開銷
- Model Routing LLM: 7 Strategies — 20–60% 省錢數據
- Intelligent LLM Routing (Swfte AI) — 85% 省錢案例研究
- Self-Hosting Open-Weight LLMs: 2026 Decision Guide — 自架經濟效益趨勢
- LLM Hosting Cost 2026 — 每天 1,000–3,000 萬 token 損益平衡點
- Self-Hosting vs Cloud APIs: The 2026 Showdown — H100 損益平衡試算
- Self-Hosting AI Models vs API Pricing — 隱藏的 DevOps/電力成本
- Self-Hosted LLM Costs 2026 — 開源模型 API 計價
- Model Distillation for LLMs: Cut Costs & Boost Speed in 2026 — 異質架構模式
- How We Reduced LLM Inference Costs by 75% Using Model Distillation — 實際上線案例
- Distillation with Programmatic Data Curation — 推論成本降至 5–30 倍便宜
Tech Stack技術工具
Engineering Notes工程筆記
The Skill Is the Product技能本身就是產品
The FastAPI backend is orchestration — auth, task isolation, progress polling. The actual research quality lives entirely in three Markdown prompt files, which means iterating on quality is a prompt edit, not a redeploy. FastAPI 後端做的是編排 —— 認證、任務隔離、進度輪詢。真正決定研究品質的是三份 Markdown 提示詞檔案,這代表要改善品質只需要改提示詞,不用重新部署。
No Accuracy Benchmark — By Design Choice沒有準確度基準 —— 這是取捨
There's no eval suite scoring report quality before/after a skill edit. Honest tradeoff to flag: skill tuning here is judged by reading the output, not by a number. This case study shows one real run instead of an unproven quality claim. 目前沒有評測套件對修改前後的報告品質打分。老實承認這個取捨:這裡技能的調整是靠讀輸出結果判斷,不是靠一個數字。這篇案例研究選擇展示一次真實執行結果,而不是講一個沒有證據的品質提升說法。
Polling Over Streaming用輪詢取代串流
Progress is parsed from JSONL lines in the Codex subprocess's stdout into an in-memory dict, then polled by the frontend — simpler than WebSockets for a single-admin tool where sub-second progress updates don't matter. 進度是從 Codex 子行程 stdout 的 JSONL 逐行解析進記憶體字典,再由前端輪詢取得 —— 對單一管理員使用的工具來說,這比 WebSocket 簡單,反正不需要毫秒級的進度更新。