Skip to content

故障排除指南 — Troubleshooting Compass

學員 / 操作員 / Builder 跑 agent 時常見的問題 + 解法,按症狀分類。用瀏覽器 Ctrl-F 找關鍵字最快

這頁是各章節「常見地雷」段的彙整 + 全文搜尋友好版。詳細解釋見對應章節。

配套:速查卡 Cheatsheet — 不報錯但忘了哪個指令時翻這頁。


環境 / 安裝

症狀原因解法章節
claude command not foundnpm 沒裝起來 / PATH 沒設npm i -g @anthropic-ai/claude-codewhich claude 確認Ch 4
ANTHROPIC_API_KEY not set沒 export env var加到 ~/.zshrc~/.bashrc: export ANTHROPIC_API_KEY="sk-ant-..."Ch 4
Node version too lowNode < 18nvm install 20 或升級 NodeCh 4
pip install 衝突全域 Python 髒uv venvpython -m venv .venv 隔離Ch 0
WSL2 路徑慢Windows / WSL 跨檔案系統把 repo 放在 ~/ (Linux FS) 不要放 /mnt/c/Ch 0

API / 金鑰 / 認證

症狀原因解法章節
401 Unauthorizedkey 錯 / revoked重新 Anthropic Console 生 key 並 exportCh 0 / LLM 申請
429 Rate limit短時間太多 requestexponential backoff retry,或升級 tierCh 8
Invalid API key formatsk-ant- 跟 sk-or- 混各家 key 開頭不同 (Anthropic sk-ant-, OpenAI sk-, Groq gsk_)LLM 申請指南
key 進 git commit不小心 push 上 GitHub立刻 rotate key + git filter-branch 移除 historyCh 8 / CONTRIBUTING
沒信用卡無法綁Anthropic / OpenAI 需信用卡改用 Groq 免費 / Gemini 免費 / Ollama 本地FAQ / LLM 申請

Cost / 預算 / 失控

症狀原因解法章節
帳單一個月 $500沒設 monthly limitconsole.anthropic.com Billing → set $20 monthly capCh 8
一個 task 燒 $5沒 per-run cost capcost_tracker.py 每 call 預估 + 超 cap fail-closedCh 8 starter
retry 燒 5x costretry policy 沒算錢retry 也計入 budget, 用 exponential backoffCh 8
log cost 跟帳單對不起PRICING dict 過期每月對 Anthropic pricing refreshCh 8
prompt 重複付全錢沒用 cache_control大 system prompt 用 cache_control: ephemeral beta,省 90%Ch 8

Agent loop / 行為

症狀原因解法章節
Agent 跑無限步沒 max_stepsfor _ in range(N): + 偵測 thought 重複 breakCh 9 / Ch 12
Reflection 永遠 rejectreviewer 太苛刻reviewer rubric 寫 measurable criteria + max iterations 3Ch 10
ReAct loop 跑同 tool 50 次沒 dedup 偵測偵測「同 thought + 同 input」直接 breakCh 12
Plan 階段太樂觀 step 3 卡住plan 沒 mid-way revise每完成一步 review plan 允許改Ch 10
Agent 亂走不照規則system prompt 規則太多 / 矛盾CLAUDE.md audit, 同一檔內規則不能衝突Ch 5
/clear 後失憶session memory 沒持久化重要 context 寫 CLAUDE.md / SKILL 或用 memory MCPCh 4 / Ch 13

Tool use / function calling

症狀原因解法章節
expected tool_result for tool_use_id漏 append tool_result收到 stop_reason='tool_use' 必加 {"type":"tool_result", "tool_use_id":..., "content":...}Ch 9
LLM 漏傳參數input_schema 沒寫 requiredinput_schema 加 "required": ["arg1", "arg2"]Ch 9
LLM 不知何時 call tooldescription 寫太空description 寫「何時用 + 輸入 + 輸出」3 段Ch 9 / Ch 6
Parallel tool 只處理 1 個iterate 漏接for block in resp.content if block.type == "tool_use" 全接Ch 9
tool 回 None 報錯LLM 收 null 亂答tool 一定 return 非空 str/dict, None → "(empty)"Ch 12

MCP

症狀原因解法章節
/mcp disconnectedcommand path 找不到用絕對路徑 / which uv 確認 / 看 stderr logCh 6
stdio mode JSON-RPC 解析錯server print() 弄壞 stdoutserver 內 print(..., file=sys.stderr), stdout 給 MCPCh 6 starter
改 server 後沒生效Claude Code 沒重啟/exit 重新 claudeCh 6
server 一個 tool fail 整個 crashtool 自己會 raise每 tool try/except return {"error": "..."}Ch 6

Memory / RAG

症狀原因解法章節
retrieval 不準chunk 切太大 / 太小中文 200-500 字 / 英文 500-1000 token, overlap 50-100 charCh 13
舊資料 retrieval 全錯embedding model 換版embedding model + version 寫死 / 升級全 re-embedCh 13
答案被無關文件淹沒沒 metadata filterwhere={"category": "policy"}Ch 13
第 30 輪對話 context 撞 200Ksession memory 沒截斷用 summarizer 每 10 輪壓 1 段Ch 13
PII 進 vector DB沒 mask 直接索引索引前 mask 姓名 / 電話 / emailCh 13

Multi-agent

症狀原因解法章節
簡單任務拆 5 agent debug 變難過度 multi-agentprompt 能解就別拆Ch 14
Supervisor 自己做事不派 workersystem prompt 沒禁寫死「不能自己做、只能 delegate」Ch 14
Pipeline stage 失敗整條斷沒 retry每階段 try/except + retry 1 次再 fail-outCh 14
4 agent 平行 + Sonnet 燒 $1/run全用大 modelsummarizer Haiku, final Sonnet/OpusCh 14
supervisor 回非 JSONLLM 自由發揮system prompt 強制 + parse fail fallback to ask userCh 14 starter

Production deploy / governance

症狀原因解法章節
出事不知道發生啥沒 audit log每 LLM/tool call 寫 SQLite 7 欄 (ts/run_id/event/payload/cost/error/duration)Ch 15
replay 不能 reproducelog 缺欄位replay record 含 input + output + model + temperature + seedCh 15
HTTP /run 等 60s 才回同步阻塞background_task + run_id polling 或 SSE streamingCh 15
database is locked多 process 寫 SQLiteWAL mode 或升 PostgreSQLCh 15
runaway agent 無法 abort沒 cancellation/runs/{id}/abort endpoint + agent 每 tick check flagCh 15
log 含 API key 外洩沒 redactmask sk-* / sk-ant-* / key=* patternCh 15

框架 / Skills / Plugins

症狀原因解法章節
單 agent 用 CrewAI 三倍 code框架選錯單 agent → vanilla / Pydantic AI; 多 role → CrewAICh 11
框架升級整個系統重寫直接綁 framework API寫 adapter layer, 換框架只動 adapterCh 11
Skill 不出現在 /skillfrontmatter 缺 name 或 description--- 區內必填 name + descriptionCh 7
LLM 誤觸發 Skilldescription 太空 / 太細description = 「何時用 + 做什麼」一句話 <150 字Ch 7
Skill 自動 commit / push 損失沒 confirmation gateConstraints 段「Never commit/push/delete without approval」Ch 7

Researcher / RL (進階)

症狀原因解法章節
掰假 citation沒 grounding強制 DOI verify + Reflection fact-check 5 條Ch 16
LLM 把 abstract 假裝讀全文paywall + 沒區分「abstract 內容」 vs 「full-paper 推論」分開 promptCh 16
GPU OOMmodel 太大4-bit + LoRA + 降 batch sizeCh 17
metric 飆升但實際變爛reward hacking加 eval 跑真實任務 + human spot-checkCh 17
fine-tune 後通用能力降catastrophic forgettingLoRA 替全參 + KL penalty + retain setCh 17

Web / Site / VitePress

症狀原因解法
看不到 LLMTryout 元件瀏覽器 cache 舊hard refresh Cmd-Shift-R / Ctrl-Shift-R
互動試玩按了沒反應API key 沒輸入LLMTryout 頂部設 API key 才會 enable 按鈕(不上傳)
行動裝置 sidebar 切不開mobile menu點左上 hamburger icon

還是卡關

  1. 搜索本頁:Ctrl-F 找關鍵字
  2. 看對應章節常見地雷18 章節都有「## 常見地雷」段
  3. FAQ:30 題 7 大類常見問題
  4. 看 starter code每章對應 dir 有 working version
  5. GitHub Discussion:問題公開 + 答案幫到後人
  6. 報 bugOpen Issue 附 OS / Python / SDK 版本 + 錯誤訊息

首頁 · FAQ · Roadmap · LLM / API 申請

MIT License — 章節內容跟 starter code 都可以 copy 進你自己的商業專案