sunilp/aip

GitHub: sunilp/aip

AIP 是一个面向 AI Agent 的身份协议,为跨 MCP 和 A2A 的多 Agent 系统提供基于公钥签名的可验证身份、作用域递减委派和完整审计轨迹。

Stars: 2 | Forks: 1

# Agent Identity Protocol (AIP) [![PyPI - agent-identity-protocol](https://img.shields.io/pypi/v/agent-identity-protocol?label=agent-identity-protocol)](https://pypi.org/project/agent-identity-protocol/) [![PyPI - aip-agents](https://img.shields.io/pypi/v/aip-agents?label=aip-agents)](https://pypi.org/project/aip-agents/) [![下载量](https://img.shields.io/pypi/dm/agent-identity-protocol)](https://pypi.org/project/agent-identity-protocol/) [![许可证](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE) **为跨 MCP 和 A2A 的 AI agent 提供可验证的身份与作用域委派。** [IETF Internet-Draft](https://datatracker.ietf.org/doc/draft-prakash-aip/) | [arXiv 论文](https://arxiv.org/abs/2603.24775) | [项目中心](https://sunilprakash.com/aip/) | [快速入门](https://sunilprakash.com/aip/quickstart/) ## 问题所在 MCP 没有身份验证机制。A2A 只有自我声明的身份,缺乏证明。你的 agent 匿名调用工具,在未经证实的情况下委派给其他 agent,并且不留任何审计轨迹。当出现问题时,你无法追溯是谁授权了什么。 ``` Agent A Agent B MCP Server ─────── ─────── ────────── │ │ │ │ AIP Token │ │ │ (signed, │ │ │ scoped) │ │ ├─────────────────▶│ │ │ │ Delegated Token │ │ │ (narrowed scope, │ │ │ chained sig) │ │ ├──────────────────▶│ │ │ │ Verify chain │ │ │ Check scope │ │ │ Audit trail ✓ │ │ 200 OK │ │ │◀──────────────────┤ ``` ## 为什么不使用 OAuth / UCAN / Macaroons? | 方案 | 对 agent 的局限性 | |----------|----------------------| | **OAuth 2.1** | 仅限客户端到服务器。Token 对中间人是不透明的,因此在多跳链中委派上下文会丢失。每个域都需要集中式的身份验证服务器。 | | **UCAN** | DID 依赖继承了密钥管理的复杂性。嵌套的 JWT 在深层链中会导致 token 膨胀。除了 capability URI 之外没有策略语言。 | | **Macaroons** | 共享密钥验证 (HMAC) 意味着验证者持有根密钥。存在单点入侵风险。Caveat 过于简单,无法满足复杂的策略需求。 | | **SPIFFE/SPIRE** | 基础设施庞大(需要 SPIRE 服务器)。X.509 轮换复杂。非为临时 agent 创建而设计。 | | **IETF AIMS/WIMSE** | AIMS 没有 token 格式或委派语义。WIMSE 仅支持双方(不支持多跳的 A 到 B 到 C)。 | AIP 使用 Ed25519 + 带有 Datalog 策略的 Biscuit。公钥验证(无共享密钥),持有者可衰减的作用域(每一跳只能缩小,不能扩大),以及基于 DNS 的身份(不依赖区块链)。[完整比较](docs/competitive-analysis.md) ## 开始使用 ``` pip install aip-agents[crewai] ``` ``` from aip_agents.adapters.crewai import CrewAIPlugin plugin = CrewAIPlugin(app_name="my-app") plugin.setup(crew) # every agent gets a cryptographic identity headers = plugin.get_auth_headers("researcher") # signed token for tool calls ``` 就是这样。现在每个 agent 都拥有一个 Ed25519 身份、作用域委派 token 和兼容 MCP 的 auth 请求头。 ### Google ADK ``` pip install aip-agents[adk] ``` ``` from aip_agents.adapters.adk import ADKPlugin plugin = ADKPlugin(app_name="my-app") plugin.setup(root_agent) # walks the agent tree, assigns identities headers = plugin.get_auth_headers("specialist") ``` ### LangChain ``` pip install aip-agents[langchain] ``` ``` from aip_agents.adapters.langchain import LangChainPlugin plugin = LangChainPlugin(app_name="my-app") plugin.register(executor, name="researcher") headers = plugin.get_auth_headers("researcher") ``` ## 这能为你带来什么 - **密码学身份** -- 每个 agent 获得一个 Ed25519 密钥对和一个 AIP 标识符 - **作用域委派** -- 当 agent 进行委派时,每一跳只能缩小作用域,不能扩大 - **MCP auth 请求头** -- 签名的 `X-AIP-Token` 请求头,任何 MCP 服务器都可以验证 - **审计轨迹** -- 每个 token 都记录了谁授权了什么,经过了哪些 agent,以及使用了什么作用域 - **两种 token 模式** -- 用于单跳的紧凑型和用于多 agent 委派的链式型 ## 性能 基于紧凑型和链式型 token 操作的基准测试(1000 次迭代): | 操作 | Python | Rust | |-----------|--------|------| | Token 创建 (紧凑型) | 0.086 ms | 0.018 ms | | Token 验证 (紧凑型) | 0.189 ms | 0.049 ms | | 委派追加 (链式型) | 0.042 ms | 0.073 ms | | 验证 5 跳链 | 0.447 ms | 0.744 ms | | Token 大小 (紧凑型) | 356 字节 | 356 字节 | | 每跳的 Token 增长 | +340 字节 | +388 字节 | 2 跳委派的端到端开销:AIP 增加约 2.3 ms,而 OAuth 增加约 20 ms(token 交换模拟)。在 100 种攻击场景中,对未授权 token 操作的拒绝率为 100%。两种语言均通过 160 多项测试。 完整的基准测试代码位于 `paper/benchmarks/`。 ## 多 agent 委派 当 agent 委派给其他 agent 时,每一跳都会在密码学层面缩小作用域: ``` from aip_core.crypto import KeyPair from aip_token.chained import ChainedToken root_kp = KeyPair.generate() # Orchestrator:广泛权限 token = ChainedToken.create_authority( issuer="aip:web:myorg.com/orchestrator", scopes=["tool:search", "tool:email"], budget_cents=500, max_depth=3, ttl_seconds=3600, keypair=root_kp, ) # 委托给 specialist:仅搜索,更低 budget delegated = token.delegate( delegator="aip:web:myorg.com/orchestrator", delegate="aip:web:myorg.com/specialist", scopes=["tool:search"], budget_cents=100, context="research task for user query", ) # Specialist 可以搜索,但不能发电子邮件 delegated.authorize("tool:search", root_kp.public_key_bytes()) # passes delegated.authorize("tool:email", root_kp.public_key_bytes()) # raises ``` ## A2A 集成 使用 `A2AVerifyMiddleware` 包装任何 A2A 任务处理器,以验证传入的 AIP token,检查受众和作用域,并将验证通过的身份传递给你的处理器: ``` from aip_a2a import A2AVerifyMiddleware middleware = A2AVerifyMiddleware( your_handler, own_aip_id="aip:web:acme.com/agent", root_public_key_bytes=root_pubkey, required_scope="research:read", ) ``` 中间件从 `metadata.aip_token` 中提取链式 token(根据规范 §3),端到端验证整条链(签名、衰减、深度、过期时间、受众),然后才会使用 `context.subject` / `context.chain_depth` / `context.issuer` 调用你的处理器。 在转发任务之前,使用同一模块中的 `append_delegation_block()` 沿着链向下衰减作用域。 [A2A 集成指南](https://sunilprakash.com/aip/guides/a2a/) | [多跳委派指南](https://sunilprakash.com/aip/guides/delegation/) ## MCP Auth 代理 使用一个命令保护任何 MCP 服务器: ``` pip install agent-identity-protocol aip-proxy --upstream http://localhost:3000 --port 8080 --trust-key z6Mkf... ``` 代理会验证每个请求的 AIP token,运行安全自审计(TTL、作用域、预算、链深度),并转发到你的 MCP 服务器。拒绝任何未授权的访问。无需对你的服务器代码进行任何更改。 [MCP 代理指南](https://sunilprakash.com/aip/guides/mcp-proxy/) | [安全模型](https://sunilprakash.com/aip/security/) ## 安装 ``` # 核心库(如果直接在 protocol 上构建) pip install agent-identity-protocol # Framework adapters(推荐) pip install aip-agents[crewai] # CrewAI pip install aip-agents[adk] # Google ADK pip install aip-agents[langchain] # LangChain pip install aip-agents[all] # all frameworks ``` 该包附带四个子包:`aip_core`(加密,身份)、`aip_token`(紧凑型 + 链式型 token)、`aip_mcp`(MCP 绑定 + auth 代理),以及 `aip_a2a`(A2A 绑定:中间件、链验证、委派助手)。 PyPI:[agent-identity-protocol](https://pypi.org/project/agent-identity-protocol/) | [aip-agents](https://pypi.org/project/aip-agents/) Rust 参考实现可在 `rust/` 中找到。 ### 集成 - **[aip-gateway](https://github.com/sunilp/aip-gateway)** -- 开箱即用的 MCP/A2A 策略代理,支持 YAML 策略和审计日志 - **[aip-node](https://github.com/sunilp/aip-node)** -- TypeScript SDK (`@aip-sdk/core`, `@aip-sdk/token`, `@aip-sdk/mcp`, `@aip-sdk/agents`) - **[aip-openclaw](https://github.com/sunilp/aip-openclaw)** -- 用于技能签名和运行时 capability 执行的 OpenClaw 插件 - **[aip-claude-code](https://github.com/sunilp/aip-claude-code)** -- Claude Code 插件:使用 Ed25519 CompactToken 对传出的 MCP 工具调用进行签名 ([npm](https://www.npmjs.com/package/aip-claude-code)) ## 文档 - **[sunilprakash.com/aip/](https://sunilprakash.com/aip/)** -- 包含指南和教程的项目中心 - [快速入门](https://sunilprakash.com/aip/quickstart/) -- 5 分钟获取你的第一个 AIP token - [委派指南](docs/guide-delegation.md) -- 链式 token、作用域衰减、策略配置文件 - [竞品分析](docs/competitive-analysis.md) -- AIP vs OAuth, DID, UCAN, Macaroons, Biscuit, SPIFFE - [规范](SPEC.md) -- 完整的协议规范 ## 示例 - [单 agent MCP](examples/single-agent-mcp/) -- agent 向 MCP 工具服务器进行身份验证 - [多 agent 委派](examples/multi-agent-delegation/) -- 编排器委派给专家,调用工具服务器 ## 论文与标准 - **IETF Internet-Draft:** [draft-prakash-aip-00](https://datatracker.ietf.org/doc/draft-prakash-aip/) (2026-09-28 到期) - **NIST:** 正在接受 NCCoE agent 身份演示项目的评估 ``` @article{prakash2026aip, title={AIP: Agent Identity Protocol for Verifiable Delegation Across MCP and A2A}, author={Prakash, Sunil}, journal={arXiv preprint arXiv:2603.24775}, year={2026} } ``` ### 相关论文 AIP 是多 agent 信任栈的一部分: | 层级 | 论文 | arXiv | |-------|-------|-------| | **身份** | AIP: Verifiable Delegation Across MCP and A2A | [2603.24775](https://arxiv.org/abs/2603.24775) | | **溯源** | The Provenance Paradox in Multi-Agent LLM Routing | [2603.18043](https://arxiv.org/abs/2603.18043) | | **协议** | LDP: An Identity-Aware Protocol for Multi-Agent LLM Systems | [2603.08852](https://arxiv.org/abs/2603.08852) | | **推理** | DCI: Structured Collective Reasoning with Typed Epistemic Acts | [2603.11781](https://arxiv.org/abs/2603.11781) | ## 测试 ``` cd python && pytest tests/ -v ``` ## 许可证 Apache 2.0
标签:A2A协议, IETF草案, MCP协议, Modbus, Python, Web报告查看器, 人工智能代理, 令牌验证, 去中心化身份, 可视化界面, 可验证凭证, 后端开发, 密码学签名, 无后门, 权限委托, 知识图谱, 责任追踪, 跨域认证, 身份与访问管理, 身份验证协议, 逆向工具, 零信任架构