LangSmith CLI Skill
CLI: scripts/langsmith.py. Requires LANGSMITH_API_KEY in env (or ~/.zshrc).
No second API key needed — the ask command fetches and formats traces as structured context for your agent to analyze. No trace data is sent to any third-party LLM.
Commands
Tier 0 — Ask (agent Q&A over traces)
python3 scripts/langsmith.py ask "<question>" --project <name> [--since 24h] [--limit 50]
Fetches recent runs and prints them as structured JSON context. Your agent reads the output and answers the question — no external LLM calls, no data leaving your machine beyond the LangSmith API.
Examples:
- - INLINECODE4
- INLINECODE5
- INLINECODE6
Tier 1 — Situational Awareness
CODEBLOCK1
Tier 2 — Before/After Comparisons
python3 scripts/langsmith.py diff <project> --before <ISO_date> --after <ISO_date>
python3 scripts/langsmith.py prompt-diff <run_id_a> <run_id_b>
diff compares avg latency, error rate, cost, output length across two time windows.
prompt-diff shows side-by-side system prompts + outputs for two specific runs.
Tier 3 — Deep Analysis (stubs, expand as needed)
CODEBLOCK3
Auth Setup
CODEBLOCK4
Test with: INLINECODE9
Security & Data Flow
This skill makes outbound network requests only to api.smith.langchain.com (the LangSmith API). That's it.
- -
LANGSMITH_API_KEY — sent as an HTTP header to api.smith.langchain.com only. Never logged or stored. - Trace data — fetched from LangSmith and printed to stdout for your agent to read. No trace data is sent to any third-party LLM or external service.
- No second API key required — the
ask command outputs structured trace context for your existing agent to analyze, rather than making its own LLM calls. - No telemetry — the script collects no usage data.
The script is ~300 lines of pure Python with no obfuscation. Audit it at scripts/langsmith.py.
API Reference
See
references/langsmith-api.md for endpoint details and run object schema.
LangSmith CLI 技能
CLI:scripts/langsmith.py。需要在环境变量(或 ~/.zshrc)中设置 LANGSMITHAPIKEY。
无需第二个 API 密钥——ask 命令会获取追踪数据并将其格式化为结构化上下文,供你的智能体进行分析。没有任何追踪数据被发送到第三方大语言模型。
命令
第 0 层——询问(基于追踪的智能体问答)
bash
python3 scripts/langsmith.py ask <问题> --project <项目名称> [--since 24h] [--limit 50]
获取最近的运行记录,并将其打印为结构化的 JSON 上下文。你的智能体读取输出并回答问题——无需外部大语言模型调用,除 LangSmith API 外,没有数据离开你的机器。
示例:
- - ask 为什么我的链这周这么慢 --project my-project
- ask 失败的运行有什么共同点 --project my-project --since 7d
- ask 周五的系统提示更改是否影响了输出质量 --project my-project
第 1 层——态势感知
bash
python3 scripts/langsmith.py runs <项目名称> [--since 2h] [--status error|success] [--limit 20]
python3 scripts/langsmith.py cost <项目名称> [--since 7d] # 按链/节点统计的令牌消耗
python3 scripts/langsmith.py latency <项目名称> [--since 24h] # 按运行名称统计的 p50/p95/p99
第 2 层——前后对比
bash
python3 scripts/langsmith.py diff <项目名称> --before
--after
python3 scripts/langsmith.py prompt-diff <运行IDa> <运行IDb>
diff 比较两个时间窗口内的平均延迟、错误率、成本、输出长度。
prompt-diff 并排显示两个特定运行的系统提示和输出。
第 3 层——深度分析(占位,可按需扩展)
bash
python3 scripts/langsmith.py cluster-failures <项目名称> [--since 7d]
python3 scripts/langsmith.py replay <运行ID>
认证设置
bash
export LANGSMITHAPIKEY=<你的密钥>
或添加到 ~/.zshrc
测试命令:python3 scripts/langsmith.py runs <项目名称> --limit 3
安全与数据流
此技能仅向 api.smith.langchain.com(LangSmith API)发起出站网络请求。仅此而已。
- - LANGSMITHAPIKEY——仅作为 HTTP 标头发送到 api.smith.langchain.com。从不记录或存储。
- 追踪数据——从 LangSmith 获取并打印到标准输出,供你的智能体读取。没有任何追踪数据被发送到第三方大语言模型或外部服务。
- 无需第二个 API 密钥——ask 命令输出结构化的追踪上下文供你现有的智能体分析,而不是自行发起大语言模型调用。
- 无遥测——脚本不收集任何使用数据。
该脚本约 300 行纯 Python 代码,无混淆。可在 scripts/langsmith.py 处审计。
API 参考
端点详情和运行对象模式请参见 references/langsmith-api.md。