学习笔记 · Obsidian

Context Hub、Chat、MCP 与 Skills

LangChainLangSmithMCP

Context Engineering 管的是模型在一次决策时真正能看到的全部信息。Prompt 只是其中一项;Agent 指令、skills、tools、memory、retrieval 和运行状态都要被版本化、裁剪和审计。

一、Context Engineering

上下文包括:

  • system/developer instructions。
  • 用户当前输入与对话历史。
  • 短期/长期 memory。
  • 检索到的文档。
  • 可用 tools 和 schema。
  • 当前任务、状态、权限和环境信息。
  • skills / agent instructions。

目标不是“塞得越多越好”,而是在正确时刻给足够、可信、相关的上下文。过多上下文会带来:

  • token/cost 与 latency 增长。
  • 注意力稀释和冲突指令。
  • 过期知识。
  • 跨租户泄露。
  • prompt injection 攻击面。

生产策略:最小化、分层加载、来源标记、版本固定、权限过滤、时效校验和结果评估。

二、Context Hub 对象

Context 是一个版本化文件 bundle:

  • Agent:完整 Agent,核心文件 <code>AGENTS.md</code>,可含 tools/skills。
  • Skill:可复用能力,核心文件 <code>SKILL.md</code>。

每次保存生成 commit,可浏览、比较和回退。当前环境 promotion 只支持:

  • staging。
  • production。

运行时可以按 commit 或 <code>:production</code> 等环境 tag 拉取。生产应把最终解析的 commit hash 写到 trace,才能回答“当时用了哪版上下文”。

<code>context-hub</code> 与 <code>prompt-context-hub</code> 当前正文完全相同,是别名入口。

三、SDK 管理

Context SDK 支持 push、pull、list、delete 等操作。治理建议:

  • handle 命名稳定,类型 agent/skill 不随意互换。
  • CI 校验必需文件、frontmatter、引用资源和大小。
  • production 只拉受控 tag/commit。
  • 删除前查 runtime 引用。
  • 拉取失败定义 fail closed、fallback commit 或本地缓存,不要隐式 latest。

四、Context Hub Webhook

Webhook 是 workspace-wide:

  • 每个 endpoint 收到所有 agent/skill commits,包括 Fleet 创建的。
  • 当前事件 <code>context_hub.commit.created.v1</code> 不支持按 repo/type 过滤。
  • 需要 <code>prompts:update</code> 权限管理。
  • 仅公开 HTTPS endpoint。

交付语义:

项当前值
timeout每次 20 秒
attempts1 次初始 + 最多 3 次重试
重试网络、408、425、429、5xx
成功状态码小于 400
幂等键event id,重试保持不变

安全处理顺序:

  1. 读取原始 body bytes。
  2. 用 signing secret 计算 HMAC-SHA256。
  3. 对完整 <code>sha256=...</code> 常量时间比较。
  4. 通过后才解析 JSON。
  5. 按完整 event type 分支。
  6. 用 id 去重,再产生下游副作用。

签名 secret roll 后旧 secret 立即失效。轮换要协调所有消费者,不能假定有双 secret 宽限期。

五、LangSmith Chat

Chat 原名 Polly,是 workspace 内的分析助手,可出现在:

  • project、trace、thread。
  • Playground、Prompt Hub。
  • dataset/experiment/example。
  • annotation queue、evaluator。

它能查询/筛 runs、分析 trace、修改 Playground、帮助构建 evaluator 和数据集。Chat 的回答是模型推断:

  • 关键结论要回到 trace/数据集验证。
  • 任何写操作先确认目标范围。
  • 不应给 Chat 比操作者更高的 workspace 数据权限。

Chat 使用 workspace model configuration/secrets;OAuth-enabled 配置不要求 workspace provider secret。Provider egress IP 受 allowlist 时要配置 LangSmith egress。

别名:

  • <code>chat-observability</code>。
  • <code>chat-prompt-engineering</code>。

当前两条路径都重定向到 canonical <code>/langsmith/chat</code>,下载到的是同一 HTML 页面而非独立 Markdown 规范。

六、Standalone MCP 与 Remote MCP

Standalone LangSmith MCP 已 deprecated,Remote MCP 是推荐方案。两者工具面相同:

  • thread/history。
  • prompts。
  • traces/runs/projects。
  • datasets/examples。
  • experiments。
  • billing usage。

Remote MCP:

  • Streamable HTTP。
  • 交互客户端用 OAuth 2.1 + Dynamic Client Registration。
  • headless 用 <code>X-Api-Key</code>。
  • Cloud 全区域。
  • self-hosted 要 0.16+,并配置 Ed25519 signing JWKS;未配置保持 404。

Standalone 使用不同 header <code>LANGSMITH-API-KEY</code>,不能照搬 Remote 的 header。

版本矛盾:旧 standalone 页面提到 self-host Remote MCP 0.15+;专用 Remote 页面明确要求 0.16+ 和 signing JWKS,应以后者为准。

七、MCP 客户端兼容

Claude Code、Cursor、Deep Agents Code 可完成 OAuth。LangSmith CLI 用同一授权服务器的 device flow。

当前已知:OpenAI Codex CLI 的 OAuth 流程缺 RFC 8707 <code>resource</code> 参数,token 没绑定 MCP resource,initialize 会失败。临时用 LangSmith CLI;不要把“浏览器登录成功”当 MCP 已可用。

远程工具遵守用户/API key 的 workspace 权限。MCP 本身不会扩大权限,但 Agent 能组合多个工具产生更大副作用,仍需最小权限和审批。

八、LangSmith Skills

官方 langsmith-skills 提供三个 Agent Skills:

  • langsmith-trace:查询/导出 traces。
  • langsmith-dataset:生成/上传 datasets。
  • langsmith-evaluator:创建/附加 evaluators。

Skill 是 <code>SKILL.md</code> 加可选 scripts,可通过 npx skills 或仓库 install script 安装。

生产使用:

  • 固定 commit/tag,不盲目重复安装 latest。
  • 阅读 SKILL.md 和 scripts 后再授权。
  • project/global 安装范围最小化。
  • 不把 API key 写进 skill。
  • 更新前对比 diff;安装说明中的删除目标命令要确认精确目录。

九、上下文发布闭环

编辑 Agent/Skill → commit → webhook 验签与 CI 校验 → staging promotion → 真实 trace/eval → production promotion → runtime 记录 commit → dashboard/feedback

Context Hub 负责资产版本,runtime 负责加载和执行,LangSmith tracing 负责证明实际使用;三者不能互相替代。