22
Harness / 平台
身份与 Connections
caller identity vs 凭证、OAuth interrupt
谁在调用 agent(caller identity)≠ 工具拿谁的凭证(connection owner)。OAuth interrupt 把授权堵在模型回合之前。
我的理解
- 博客 Identity 节说这是他们踩得最深的坑:agent 做事时,究竟以谁的身份?
- 业界两大路:
- On-behalf-of(OBO):以触发这次调用的人的名义
- Fixed credentials:固定服务账号 / 应用凭证,不管谁触发
- MDA 把这两件事拆开:
1.
identity.py:鉴权「谁在调用」,决定 private threads、user memory、user-owned credentials 的 key 2. Connections:外部服务凭证的容器;connections.get(slug, {"type": "agent"|"user"})在运行时解析 - 博客落地对照(GTM / OpenSWE / Content Studio):
- OpenSWE:消息交互时 OBO 开 PR(你的 GitHub handle);后台 code review 用 GitHub App 自己的身份
- GTM:Salesforce 等固定身份;email 等 OBO,且只在 DM 可用,共享频道不给
- Content Studio:Notion 等 OBO;公司 Twitter 固定凭证 + 白名单才能发帖(其他人可能只能读/起草)
- 默认
mda init用 LangSmith API key:适合 SDK/脚本锁部署;不会给每个终端用户 private threads——Alice 可能看到 Bob 的线程。要分人,用 Supabase / 其他 JWT / 自有 backend。 - Workspace 成员通过 Studio 的另一条鉴权路径仍可读搜部署里线程;文档写明:per-user privacy 对 end users 成立,不对 LangSmith workspace 成员成立。
选型或决策
| 目标 | 用什么 | 注意 |
|---|---|---|
| SDK / 脚本 / 服务调用,锁部署 | auth.langsmith_api_key()(默认) |
持 key 者共享同一 identity;当 secret |
| 浏览器端登录用户 + private chats | auth.supabase(project_ref=...) 或其它 JWT |
客户端送 Authorization: Bearer <access_token> |
| 自有 API 已鉴权用户,再代调 MDA | define_identity(auth="backend") + MDA_INGRESS_SECRET |
送 x-mda-ingress-secret + x-mda-user-id;secret 绝不能进浏览器 |
| 全组织共享线程/凭证 | 把 org ID 当 user ID | 文档:MDA 不接受自定义 LangGraph auth handler |
| 每人 private | 用人的稳定 ID | 换 ID = 另一套 threads / credentials |
| 工具:人人同一能力(Tavily、团队频道) | connections.get(..., {"type": "agent"}) |
opaque secret / client credentials / --authorize 一次签入 |
| 工具:以调用者名义(Notion、个人 GitHub、发邮件) | {"type": "user"} |
需要真实 person identity;缺 grant → interrupt |
| 公司 Twitter 只允许部分人发 | agent 固定凭证 + 应用层白名单 | 博客 Content Studio 模式;细则在你的工具代码 |
代码
identity 四种形态(摘自 Identity 文档;没实跑过)
python
# identity.py —— 四种 provider(文档示例折叠;没实跑过)
from managed_deepagents import auth, define_identity
# 1) 默认:LangSmith API key(客户端送 x-api-key)
identity = define_identity(auth=auth.langsmith_api_key())
# 2) Supabase
identity = define_identity(auth=auth.supabase(project_ref="your-project-ref"))
# 3) 其它 JWT(Auth0 / Okta / Clerk / Entra …)
identity = define_identity(
auth={
"issuer": "https://your-tenant.us.auth0.com/",
"audience": "https://api.example.com",
"discover": True,
"claims": {"user": "sub"},
}
)
# 4) 自有 backend
identity = define_identity(auth="backend")
# .env: MDA_INGRESS_SECRET=<openssl rand -hex 32>
backend 调部署(没实跑过)
python
# 自有 backend → MDA(文档示例;没实跑过)
import httpx
response = httpx.post(
f"{deployment_url}/threads/{thread_id}/runs",
headers={
"x-mda-ingress-secret": mda_ingress_secret,
"x-mda-user-id": user_id, # 要跨会话稳定
"Content-Type": "application/json",
},
json=run_body,
)
Connections:创建与解析(没实跑过)
bash
# opaque secret → agent-owned
uv run mda connections create organization-tavily --secret-from-env TAVILY_API_KEY
# 通用 OAuth(BYOT)→ 默认每 caller 授权;slug 是你的名字,--oauth 是 catalog provider
uv run mda connections create frontend-github --oauth github \
--client-id "********" --secret-from-env GITHUB_CLIENT_SECRET
# MCP OAuth(Notion MCP 等)
uv run mda connections create engineering-notion --mcp https://mcp.notion.com/mcp
python
# 工具里解析(文档示例;没实跑过)
from managed_deepagents import connections
tavily_key = await connections.get("organization-tavily", {"type": "agent"})
notion_token = await connections.get("engineering-notion", {"type": "user"})
# 代码从不传 user id;runtime 用当前 caller
OAuth interrupt 载荷形状(没实跑过)
json
{
"type": "credential_authorization_required",
"message": "Connect the following integrations to continue.",
"credentials": [
{
"slug": "engineering-notion",
"kind": "oauth2",
"connect_url": "https://api.smith.langchain.com/v1/agent-auth/...",
"auth_id": "sess_abc123"
}
]
}
恢复时前端 stream.respond({ "type": "credential_authorization_completed", "connected_slugs": ["engineering-notion"] }, { interruptId })。Slack / Studio 会替你跑完 OAuth;自定义前端要自己处理。kind: "secret" 没有 connect_url(当前限制:Slack/Studio 不收 per-caller API key)。
Caller 来源(文档表)
| Surface | Caller identity |
|---|---|
| Slack channel | 发消息的 Slack user |
| LangSmith Studio | 登录的 LangSmith user |
| SDK / 自定义前端 | identity.py 鉴权出来的身份 |
失败模式
| 现象 | 常见原因 | 我怎么处置 |
|---|---|---|
| 人人共享同一 Notion/邮件 | 用了 API key identity + 误以为有 user connection | 换 JWT/Supabase/backend;connections 用 type: user |
credential_authorization_required 死循环 |
resume 时 grant 还没齐;或匿名/agent-only run | 等 oauth session completed;确认有 person caller |
no agent connection is set for slug |
别的部署建过同 slug,本部署没有 | 从本项目 root 再 mda connections create <slug> |
| 401 | 缺 x-api-key / Bearer / ingress 双头 |
对照文档 Test and deploy 节逐项查 |
| 403 读别人的线程 | 预期:跨用户应被拒 | 用 Supabase 测「不能读别人」 |
| 给现有部署加 Supabase 后旧线程无主 | 文档:不加 owner metadata 到已有线程 | 先规划迁移再依赖 identity ACL |
--authorize 用了个人号 |
审计日志挂你名;你离职/改密就挂 | 用团队专用账号 + 最窄 scope |
踩坑 / 注意
- ❌ 坑:混淆 caller identity 与 connection owner——前者定「谁」,后者定「拿哪份凭证」。
- ❌ 坑:
MDA_INGRESS_SECRET进前端 = 任何人可冒充任意x-mda-user-id。 - ❌ 坑:opaque CLI secret 永远是 agent-owned;要 per-caller 用 OAuth。
- ❌ 坑:Notion REST(
--oauth notion-api)≠ Notion MCP(--mcp)——文档写它们是不同 OAuth app。 - ❌ 注意:agent-owned credential 要在至少一次成功
mda deploy之后创建;同 slug 跨部署要各建一次。 - ❌ 注意:
mda connections list是 workspace 范围,不报告哪个部署持有该 slug 的凭证。 - ❌ 注意:本地
mda dev下 agent-owned opaque 读MDA_DEV_<SLUG>(连字符→下划线、大写);user-owned 要部署后才能端到端测 interrupt。
待试
- [ ] 画一张表:自己的工具哪些 OBO、哪些 fixed、哪些只许 DM
- [ ]
mda connections catalog看一眼支持的--oauth服务 - [ ] 用 Studio 走一遍 user-owned OAuth interrupt(Notion 或 GitHub)
- [ ] 若走 backend identity:确认
user_id稳定策略(员工工号 / IdP sub)
收藏
- 博客 Identity 节(同一篇 company harness) — langchain.com
- Add identity to Managed Deep Agents — docs.langchain.com
- Manage connections — docs.langchain.com
- Human-in-the-loop / useStream — docs.langchain.com
- Set up Agent Auth — docs.langchain.com