Community研究與資料分析github.com

ComposioHQ/langsmith-fetch

透過從 LangSmith Studio 擷取執行追蹤來除錯 LangChain 和 LangGraph 代理程式。在用於除錯代理行為、調查錯誤、分析工具呼叫、檢查記憶體操作或檢視代理效能時使用。會自動擷取最近的追蹤並分析執行模式。需要安裝 langsmith-fetch CLI。

langsmith-fetch 是什麼?

這個技能旨在幫助開發者透過終端機直接擷取 LangSmith Studio 中的執行追蹤,來除錯基於 LangChain 和 LangGraph 的 AI 代理程式。它支援多種常見的除錯場景,包括快速檢視近期活動、深入調查特定追蹤、匯出除錯工作階段以及錯誤檢測。技能預設了多個自動化工作流程,能根據使用者輸入的關鍵字(如「除錯我的代理」、「顯示最近的追蹤」或「檢查錯誤」)自動觸發對應的 langsmith-fetch CLI 命令。其核心功能涵蓋了分析工具呼叫順序、記憶體操作、錯誤原因、執行時間及 token 用量。該技能支援 `pretty`、`json` 和 `raw` 三種輸出格式,並提供時間過濾、中繼資料包含及並行擷取等進階功能,可整合至開發流程中作為程式碼提交前的健康檢查。

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

Installed? Explore more 研究與資料分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · 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

# 搜尋錯誤
sort -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. 檢查:

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

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

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

步驟:

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

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

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


輸出格式指南

Pretty 格式(預設)

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

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

JSON 格式

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

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

Raw 格式

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.

ComposioHQ/-21risk-automation

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

ComposioHQ/-2chat-automation

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

ComposioHQ/ably-automation

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

ComposioHQ/abstract-automation

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

ComposioHQ/abuselpdb-automation

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

ComposioHQ/abyssale-automation

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

ComposioHQ/accelo-automation

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

ComposioHQ/accredible-certificates-automation

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

ComposioHQ/acculynx-automation

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

ComposioHQ/active-campaign-automation

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

ComposioHQ/addresszen-automation

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

ComposioHQ/adobe-automation

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

ComposioHQ/adrapid-automation

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

ComposioHQ/adyntel-automation

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

ComposioHQ/aeroleads-automation

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

ComposioHQ/aero-workflow-automation

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

ComposioHQ/affinda-automation

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

ComposioHQ/affinity-automation

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

ComposioHQ/agencyzoom-automation

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

ComposioHQ/agent-deep-links

Build, validate, and troubleshoot deep links for Codex, Cursor, VS Code, Visual Studio, and similar tools. Use when users ask for clickable links (especially in Slack) that open threads, files, folders, or app settings.

相關技能