Community程式設計與開發github.com

langsmith-fetch

透過在終端機中直接從 LangSmith Studio 擷取執行追蹤,來除錯 LangChain 和 LangGraph 代理程式。

langsmith-fetch 是什麼?

langsmith-fetch 是一個 CLI 工具,專門用於除錯 LangChain 和 LangGraph 代理程式。它能讓開發者直接從 LangSmith Studio 擷取執行追蹤,並在終端機中進行分析。此技能支援四種主要工作流程:快速除錯近期活動、深入分析特定追蹤、匯出除錯工作階段,以及錯誤偵測。它還涵蓋多種常見使用案例,例如代理程式無回應、呼叫錯誤工具、記憶體運作異常以及效能問題。使用者可以透過 `pip install langsmith-fetch` 安裝,並設定 `LANGSMITH_API_KEY` 和 `LANGSMITH_PROJECT` 環境變數來開始使用。此技能會自動引導使用者執行相關的 CLI 指令、分析輸出,並提供可行的建議,以解決代理程式的問題。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComposioHQ/awesome-claude-skills/tree/master/langsmith-fetch

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

LangSmith Fetch - 代理程式除錯技能

透過在終端機中直接從 LangSmith Studio 擷取執行追蹤,來除錯 LangChain 和 LangGraph 代理程式。

何時使用此技能

當使用者提及以下內容時自動啟用:

  • 🐛 「除錯我的代理程式」或「出了什麼問題?」
  • 🔍 「顯示最近的追蹤」或「發生了什麼事?」
  • ❌ 「檢查錯誤」或「為什麼失敗?」
  • 💾 「分析記憶體操作」或「檢查 LTM」
  • 📊 「檢視代理程式效能」或「檢查 token 用量」
  • 🔧 「呼叫了哪些工具?」或「顯示執行流程」

先決條件

1. 安裝 langsmith-fetch

pip install langsmith-fetch

2. 設定環境變數

export LANGSMITH_API_KEY="your_langsmith_api_key"
export LANGSMITH_PROJECT="your_project_name"

驗證設定:

echo $LANGSMITH_API_KEY
echo $LANGSMITH_PROJECT

核心工作流程

工作流程 1:快速除錯近期活動

當使用者詢問:「剛剛發生什麼事?」或「除錯我的代理程式」

執行:

langsmith-fetch traces --last-n-minutes 5 --limit 5 --format pretty

分析並回報:

  1. ✅ 找到的追蹤數量
  2. ⚠️ 任何錯誤或失敗
  3. 🛠️ 已呼叫的工具
  4. ⏱️ 執行時間
  5. 💰 Token 用量

回覆格式範例:

在過去 5 分鐘內找到 3 個追蹤:

追蹤 1:✅ 成功
- 代理程式:memento
- 工具:recall_memories, create_entities
- 持續時間:2.3s
- Token:1,245

追蹤 2:❌ 錯誤
- 代理程式:cypher
- 錯誤:"Neo4j 連線逾時"
- 持續時間:15.1s
- 失敗於:search_nodes 工具

追蹤 3:✅ 成功
- 代理程式:memento
- 工具:store_memory
- 持續時間:1.8s
- Token:892

💡 發現問題:追蹤 2 因 Neo4j 逾時而失敗。建議檢查資料庫連線。

工作流程 2:深入分析特定追蹤

當使用者提供: 追蹤 ID 或說「調查那個錯誤」

執行:

langsmith-fetch trace <trace-id> --format json

分析 JSON 並回報:

  1. 🎯 代理程式嘗試做什麼
  2. 🛠️ 呼叫了哪些工具(按順序)
  3. ✅ 工具結果(成功/失敗)
  4. ❌ 錯誤訊息(如果有)
  5. 💡 根本原因分析
  6. 🔧 建議的修正

回覆格式範例:

深入分析 - 追蹤 abc123

目標:使用者詢問「在 Neo4j 中尋找所有專案」

執行流程:
1. ✅ search_nodes(query: "projects")
   → 找到 24 個節點

2. ❌ get_node_details(node_id: "proj_123")
   → 錯誤:"節點未找到"
   → 這是失敗點

3. ⏹️ 執行停止

根本原因:
search_nodes 工具回傳的節點 ID 在資料庫中已不存在,
可能是因為近期有刪除操作。

建議的修正:
1. 在 get_node_details 工具中加入錯誤處理
2. 在搜尋結果中過濾已刪除的節點
3. 更新快取失效策略

Token 用量:1,842 tokens ($0.0276)
執行時間:8.7 秒

工作流程 3:匯出除錯工作階段

當使用者說:「儲存此工作階段」或「匯出追蹤」

執行:

# 使用時間戳記建立工作階段資料夾
SESSION_DIR="langsmith-debug/session-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$SESSION_DIR"

# 匯出追蹤
langsmith-fetch traces "$SESSION_DIR/traces" --last-n-minutes 30 --limit 50 --include-metadata

# 匯出執行緒(對話)
langsmith-fetch threads "$SESSION_DIR/threads" --limit 20

回報:

✅ 工作階段已成功匯出!

位置:langsmith-debug/session-20251224-143022/
- 追蹤:42 個檔案
- 執行緒:8 個檔案

您現在可以:
1. 檢閱個別追蹤檔案
2. 與團隊分享資料夾
3. 使用外部工具分析
4. 歸檔以供日後參考

工作階段大小:2.3 MB

工作流程 4:錯誤偵測

當使用者問:「顯示錯誤」或「什麼在失敗?」

執行:

# 擷取最近的追蹤
langsmith-fetch traces --last-n-minutes 30 --limit 50 --format json > recent-traces.json

# 搜尋錯誤
grep -i "error\|failed\|exception" recent-traces.json

分析並回報:

  1. 📊 找到的錯誤總數
  2. ❌ 錯誤類型和頻率
  3. 🕐 錯誤發生的時間
  4. 🎯 哪些代理程式/工具失敗
  5. 💡 常見模式

回覆格式範例:

錯誤分析 - 過去 30 分鐘

追蹤總數:50
失敗追蹤:7(14% 失敗率)

錯誤細項:
1. Neo4j 連線逾時(4 次)
   - 代理程式:cypher
   - 工具:search_nodes
   - 首次發生:14:32
   - 最後一次發生:14:45
   - 模式:發生在尖峰負載時段

2. 記憶體儲存失敗(2 次)
   - 代理程式:memento
   - 工具:store_memory
   - 錯誤:"Pinecone 速率限制已達上限"
   - 發生時間:14:38, 14:41

3. 找不到工具(1 次)
   - 代理程式:sqlcrm
   - 嘗試的工具:"export_report"(不存在)
   - 發生時間:14:35

💡 建議:
1. 為 Neo4j 逾時加入重試邏輯
2. 對 Pinecone 實作速率限制
3. 修正 sqlcrm 工具設定

常見使用案例

使用案例 1:「代理程式無回應」

使用者說:「我的代理程式沒有任何動作」

步驟:

  1. 檢查是否有追蹤:

    langsmith-fetch traces --last-n-minutes 5 --limit 5
    
  2. 如果未找到任何追蹤:

    • 追蹤功能可能已停用
    • 檢查環境變數:LANGCHAIN_TRACING_V2=true
    • 檢查:LANGCHAIN_API_KEY 是否已設定
    • 確認代理程式確實已執行
  3. 如果找到追蹤:

    • 檢閱是否有錯誤
    • 檢查執行時間(是否卡住?)
    • 確認工具呼叫已完成

使用案例 2:「呼叫了錯誤的工具」

使用者說:「為什麼它使用了錯誤的工具?」

步驟:

  1. 取得特定追蹤
  2. 檢閱執行時期可用的工具
  3. 檢查代理程式選擇工具的推理過程
  4. 檢查工具的描述與指示
  5. 建議改善提示詞或工具設定

使用案例 3:「記憶體無法運作」

使用者說:「代理程式不記得事情」

步驟:

  1. 搜尋記憶體相關操作:

    langsmith-fetch traces --last-n-minutes 10 --limit 20 --format raw | grep -i "memory\|recall\|store"
    
  2. 檢查:

    • 是否呼叫了記憶體工具?
    • recall 是否有回傳結果?
    • 記憶體是否確實被儲存?
    • 擷取的記憶體是否被使用?

使用案例 4:「效能問題」

使用者說:「代理程式太慢了」

步驟:

  1. 匯出並包含中繼資料:

    langsmith-fetch traces ./perf-analysis --last-n-minutes 30 --limit 50 --include-metadata
    
  2. 分析:

    • 每個追蹤的執行時間
    • 工具呼叫延遲
    • Token 用量(上下文大小)
    • 迭代次數
    • 最慢的操作
  3. 找出瓶頸並建議最佳化方案


輸出格式指南

美化格式(預設)

langsmith-fetch traces --limit 5 --format pretty

用於: 快速視覺檢查、向使用者展示

JSON 格式

langsmith-fetch traces --limit 5 --format json

用於: 詳細分析、語法高亮檢閱

原始格式

langsmith-fetch traces --limit 5 --format raw

用於: 管道傳送給其他指令、自動化


進階功能

時間過濾

# 特定時間戳記之後
langsmith-fetch traces --after "2025-12-24T13:00:00Z" --limit 20

# 最近 N 分鐘(最常用)
langsmith-fetch traces --last-n-minutes 60 --limit 100

包含中繼資料

# 取得額外上下文
langsmith-fetch traces --limit 10 --include-metadata

# 中繼資料包含:代理程式類型、模型、標籤、環境

並行擷取(更快)

# 加速大量匯出
langsmith-fetch traces ./output --limit 100 --concurrent 10

疑難排解

「未找到符合條件的追蹤」

可能原因:

  1. 時間範圍內沒有代理程式活動
  2. 追蹤功能已停用
  3. 專案名稱錯誤
  4. API 金鑰問題

解決方案:

# 1. 嘗試更長的時間範圍
langsmith-fetch traces --last-n-minutes 1440 --limit 50

# 2. 檢查環境變數
echo $LANGSMITH_API_KEY
echo $LANGSMITH_PROJECT

# 3. 改為嘗試擷取執行緒
langsmith-fetch threads --limit 10

# 4. 確認程式碼中已啟用追蹤
# 檢查:LANGCHAIN_TRACING_V2=true

「找不到專案」

解決方案:

# 檢視目前設定
langsmith-fetch config show

# 設定正確的專案
export LANGSMITH_PROJECT="correct-project-name"

# 或永久設定
langsmith-fetch config set project "your-project-name"

環境變數未持久化

解決方案:

# 加入 shell 設定檔(~/.bashrc 或 ~/.zshrc)
echo 'export LANGSMITH_API_KEY="your_key"' >> ~/.bashrc
echo 'export LANGSMITH_PROJECT="your_project"' >> ~/.bashrc

# 重新載入 shell 設定檔
source ~/.bashrc

最佳實踐

1. 定期健康檢查

# 在修改後快速檢查
langsmith-fetch traces --last-n-minutes 5 --limit 5

2. 有組織的儲存

langsmith-debug/
├── sessions/
│   ├── 2025-12-24/
│   └── 2025-12-25/
├── error-cases/
└── performance-tests/

3. 記錄發現

當您發現錯誤時:

  1. 匯出有問題的追蹤
  2. 儲存到 error-cases/ 資料夾
  3. 在 README 中記錄問題
  4. 與團隊分享追蹤 ID

4. 與開發流程整合

# 提交程式碼前
langsmith-fetch traces --last-n-minutes 10 --limit 5

# 如果發現錯誤
langsmith-fetch trace <error-id> --format json > pre-commit-error.json

快速參考

# 最常用的指令

# 快速除錯
langsmith-fetch traces --last-n-minutes 5 --limit 5 --format pretty

# 特定追蹤
langsmith-fetch trace <trace-id> --format pretty

# 匯出工作階段
langsmith-fetch traces ./debug-session --last-n-minutes 30 --limit 50

# 尋找錯誤
langsmith-fetch traces --last-n-minutes 30 --limit 50 --format raw | grep -i error

# 包含中繼資料
langsmith-fetch traces --limit 10 --include-metadata

資源


給 Claude 的備註

  • 執行指令前務必檢查 langsmith-fetch 是否已安裝
  • 確認環境變數已設定
  • 人類可讀的輸出使用 --format pretty
  • 需要解析和分析資料時使用 --format json
  • 匯出工作階段時,建立有組織的資料夾結構
  • 務必提供清晰的分析和可行的建議
  • 如果指令失敗,請協助排除設定問題

版本: 0.1.0 作者: Ahmad Othman Ammar Adi 授權: MIT 儲存庫: https://github.com/OthmanAdi/langsmith-fetch-skill

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ably-automation

Automate Ably tasks via Rube MCP (Composio). Always search tools first for current schemas.

abstract-automation

Automate Abstract tasks via Rube MCP (Composio). Always search tools first for current schemas.

abuselpdb-automation

Automate Abuselpdb tasks via Rube MCP (Composio). Always search tools first for current schemas.

abyssale-automation

Automate Abyssale tasks via Rube MCP (Composio). Always search tools first for current schemas.

accelo-automation

Automate Accelo tasks via Rube MCP (Composio). Always search tools first for current schemas.

accredible-certificates-automation

Automate Accredible Certificates tasks via Rube MCP (Composio). Always search tools first for current schemas.

acculynx-automation

Automate Acculynx tasks via Rube MCP (Composio). Always search tools first for current schemas.

active-campaign-automation

Automate ActiveCampaign tasks via Rube MCP (Composio). Always search tools first for current schemas.

addresszen-automation

Automate Addresszen tasks via Rube MCP (Composio). Always search tools first for current schemas.

adobe-automation

Automate Adobe tasks via Rube MCP (Composio). Always search tools first for current schemas.

adrapid-automation

Automate Adrapid tasks via Rube MCP (Composio). Always search tools first for current schemas.

adyntel-automation

Automate Adyntel tasks via Rube MCP (Composio). Always search tools first for current schemas.

aeroleads-automation

Automate Aeroleads tasks via Rube MCP (Composio). Always search tools first for current schemas.

aero-workflow-automation

Automate Aero Workflow tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinda-automation

Automate Affinda tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinity-automation

Automate Affinity tasks via Rube MCP (Composio). Always search tools first for current schemas.

agencyzoom-automation

Automate Agencyzoom tasks via Rube MCP (Composio). Always search tools first for current schemas.

agent-mail-automation

Automate Agent Mail tasks via Rube MCP (Composio). Always search tools first for current schemas.

agentql-automation

Automate Agentql tasks via Rube MCP (Composio). Always search tools first for current schemas.

agenty-automation

Automate Agenty tasks via Rube MCP (Composio). Always search tools first for current schemas.

相關技能