Translation(model translation, not the source's own text)
a2a-gateway
精简、生产级 Rust A2A(Agent2Agent v1.0)边缘网关,专为低内存虚拟机(如 GCP Always Free e2-micro)设计,特性包括:
- 严格的边缘 Media-Type / CSRF 防御:在解析请求体前强制要求 application/json 或 application/*+json(包括 application/a2a+json),以 JSON-RPC -32005(CONTENT_TYPE_NOT_SUPPORTED)阻止跨域 text/plain 与表单编码的 CORS 简单请求。
- 恒定时间鉴权与按租户限流:可选的 Bearer token 校验 + 按租户(/{tenant}/agents/{agent_id})的轻量令牌桶限流器。
- 动态 Agent 发现与聚合卡片:发现上游 /.well-known/agent-card.json 端点,并提供确定性的聚合 A2A v1.0 Agent Card。
- 零拷贝 SSE 流式透传:逐块代理 SendStreamingMessage / text/event-stream 响应,不做缓冲。
- 零 PII Mizan 遥测:输出结构化 JSONL 指标(ts_ms、tenant、agent_id、rpc_method、status、streaming、latency_ms、bytes_in、bytes_out)——从不记录消息体、提示词、请求头或 IP 地址。
- 无状态 MCP 2.0(2026-07-28)发现门面:通过 POST /mcp(server/discover 与 tools/list)暴露已注册的健康的 A2A 技能,并带有 cacheScope 和 ttlMs。
- 可选 langextract-agent 二进制(--features langextract-agent):附带一个零 LLM 成本的 A2A v1.0 agent,由 langextract-core 驱动,用于确定性的文本清洗、分块与片段定位。
真实生产基准测试(GCP Always Free e2-micro,1 GB RAM)
在 mizan-cloud-prod(e2-micro,us-central1,300 个并发 SendMessage JSON-RPC 请求,并发度=10,完整往返 a2a-gateway -> langextract-agent -> langextract-core 0.3.0 + JSONL 遥测)上实测:
| 指标 | 实测值 |
|---|---|
| 吞吐量 | 973.6 RPS(300 个请求耗时 0.308s) |
| 端到端延迟(p50 / p95 / p99) | 8.99 ms / 18.24 ms / 25.21 ms |
| langextract-core 计算(p50 / p95 / p99) | 25 us / 41 us / 71 us |
| a2a-gateway RSS(空闲 / 基准测试后) | 5.4 MB / 6.5 MB |
| langextract-agent RSS(空闲 / 基准测试后) | 4.0 MB / 6.8 MB |
| 组合栈内存 | < 13.5 MB RSS |
在线演示(立即试用)
# 1. Aggregated A2A v1.0 Agent Card
curl -s https://a2a.35-209-222-203.sslip.io/.well-known/agent-card.json
# 2. Stateless MCP 2.0 (2026-07-28) Discovery
curl -s -X POST https://a2a.35-209-222-203.sslip.io/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"server/discover"}'
# 3. Live A2A v1.0 SendMessage (clean, chunk & ground snippets via langextract-core)
curl -s -X POST https://a2a.35-209-222-203.sslip.io/agents/langextract \
-H "Content-Type: application/json" \
-H "A2A-Version: 1.0" \
-d '{"jsonrpc":"2.0","id":1,"method":"SendMessage","params":{"message":{"messageId":"demo-1","role":"ROLE_USER","parts":[{"text":"Rust A2A Edge Gateway runs in 5.4 MB RSS on GCP e2-micro."}]},"metadata":{"maxChars":120,"overlap":10,"snippets":["5.4 MB RSS"]}}}'
安装与运行
# Install from crates.io
cargo install a2a-gateway
# Or build with the optional LangExtract A2A v1.0 agent
cargo install a2a-gateway --features langextract-agent
# Run with config
cp a2a-gateway.example.toml a2a-gateway.local.toml
a2a-gateway a2a-gateway.local.toml
端点
| 端点 | 用途 |
|---|---|
| GET /health/live | 存活探针 |
| GET /health/ready | 就绪探针(报告健康的上游 agent 数量) |
| GET /.well-known/agent-card.json | 聚合 A2A v1.0 Agent Card,合并健康的上游技能 |
| POST /agents/{agent_id} | JSON-RPC 2.0 与 SSE 代理(默认租户) |
| POST /{tenant}/agents/{agent_id} | 多租户 JSON-RPC 2.0 与 SSE 代理 |
| POST /mcp | 无状态 MCP 2.0(2026-07-28)server/discover 与 tools/list 门面 |
验证
文章标题:Show HN: A2a-gateway – Rust A2A v1.0 and MCP 2.0 gateway (973 RPS, 13.5 MB RAM)
正文:
cargo test --all-targets --all-features
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check