基础篇
进阶篇
高频篇
精选篇
手写篇
面经篇
AI 篇
原理篇
每日一题
小程序题库
知识卡片
  • 场景篇按分类整理的大前端场景考点
  • 历年面经按年份追踪真实考点
  • 算法题库NEW在线编码即时判题
  • 专项自测100 题快速查漏
  • 前端基础
    • HTTP从报文一路讲到 HTTPS
    • 浏览器渲染、事件循环、进程
    • 计算机基础Linux、网络、操作系统
  • 进阶专项
    • 设计模式23 种模式怎么用
    • 前端系统进阶学习大型项目工程化
    • 前端综合文章长期沉淀的实践文
  • 工程与工具
    • Node学习指南从环境搭建到服务端
    • NPM工作流script、依赖与发布
    • Docker容器化部署上手
    • Canvas图形与动画实战
  • 路线与导图
    • 思维导图知识点全景图
    • 学习路线按图索骥不跑偏
  • 动态
    • 公众号动态公众号历史文章
    • 博客动态站长的技术博客
    • 开发者导航常用工具与文档站
  • AI 助手随时提问,即时解析
  • AI 模拟面试模拟真实面试 + 报告
  • AI 知识地图串起全站知识点
  • AI 定制路线按你的简历现排
AI 热点
旧版
AIHT
内容
精选全部 AI 动态热点榜AI 日报收藏
分类
模型行业编程产品技术观点开源
更多
Agent 接入
返回首页开发者导航
AIHT
精选 / 资讯详情
8.0
热点
AI SCORE
技术实践2026-09-08 05:31

2026年Agent-to-Agent市场完全指南

dev.to · AI#Agent#A2A#协议
Editor brief · 编辑速览

解析 A2A 市场的架构与协议:服务发现(IPFS 注册表)、 micropayment(x402/USDC)、信任与声誉机制。

文章思维导图
Knowledge map
拖拽缩放
Full translation

完整中文译文

1. 为什么需要 A2A Marketplace

如今的 Agent 已经高度专业化:一个感知模块、一个规划器、一个 LLM wrapper、一个数据获取器等等。开发者不再把所有能力都塞进一个单体应用,而是将离散的服务暴露出来(例如"summarize-text-v2"、"fetch-weather-latlon"),让其他 Agent 在运行时发现、付费并组合使用它们。

一个 Marketplace 提供三个核心功能:

2. 核心协议栈(2026)

注意:协议栈特意设计为模块化。你可以如果愿意承受审查风险,将 IPFS 替换为集中式 CDN;如果你需要不同的流动性,可以将 USDC 替换为另一条 L2 上的稳定币。

3. 服务发现的实践

Agent 通过向 IPFS gateway(或本地 ipfs 节点)发送简单的 HTTP GET 请求来解析一份 manifest。该 manifest 列出了该 Agent 发布的所有服务,每个服务都有一个 MCP-Lite descriptor URL。

// discover.ts – minimal resolver (Node.js ≥18)
import { createHash } from 'crypto';
import { fetch } from 'undici';

const IPFS_GATEWAY = 'https://ipfs.io/ipfs/';

export async function resolveManifest(cid: string) {
  const url = `${IPFS_GATEWAY}${cid}/manifest.json`;
  const resp = await fetch(url);
  if (!resp.ok) throw new Error(`Manifest fetch failed: ${resp.status}`);
  return resp.json(); // { services: [{ name, descriptorUrl, priceUsdc }] }
}

// Example usage
(async () => {
  const manifest = await resolveManifest('bafybeigdyrzt5wfp7ud7gku7v2kfulza6mnkykakwlwt3e6t2i2jiuowe');
  console.log(manifest.services);
})();

权衡点:IPFS 保证不可变性,但冷读会增加约 200-400ms 的延迟。通过 Filecoin 或专用 gateway 固定服务可以降低方差,但会引入运营成本。

4. 按次付费与 x402

当一个 Agent 想调用某个服务时,它首先发送一个不带支付的探测请求。该服务回复 402 Payment Required,并在 x402-payment-request header 中包含:

  • token:USDC 合约地址(0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)
  • amount:微单位(1e6 per USDC)
  • payload:一个 nonce + 时间戳,用于防止重放

付款方随后用其私钥对 payload 签名,并在重新发送的请求中带上 x402-payment header。

// x402Client.ts – generic caller using ethers v6
import { ethers } from 'ethers';
import { fetch } from 'undici';

const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
const RPC_URL = 'https://base-mainnet.infura.io/v3/<PROJECT_ID>';

const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);

/**
 * Calls an x402‑protected endpoint and returns the JSON payload.
 * @param url   Full URL of the service endpoint.
 * @param body  Optional JSON‑serializable body (POST) or undefined (GET).
 */
export async function x402Fetch(url: string, body?: any) {
  // 1️⃣ Probe
  let probe = await fetch(url, {
    method: body ? 'POST' : 'GET',
    headers: body ? { 'Content-Type': 'application/json' } : {},
    ...(body && { body: JSON.stringify(body) }),
  });

  if (probe.status !== 402) {
    // No payment required – return directly
    const data = await probe.json();
    return data;
  }

  // 2️⃣ Parse payment request
  const reqHeader = probe.headers.get('x402-payment-request');
  if (!reqHeader) throw new Error('Missing x402-payment-request header');
  const { scheme, network, token, amount, payload } = JSON.parse(reqHeader);

  if (scheme !== 'erc20' || network !== 'base' || token.toLowerCase() !== USDC_BASE.toLowerCase())
    throw new Error('Unsupported payment scheme');

  // 3️⃣ Sign the payload (EIP‑191 signed message)
  const message = ethers.getBytes(payload);
  const signature = await wallet.signMessage(message);

  // 4️⃣ Resend with payment header
  const paid = await fetch(url, {
    method: body ? 'POST' : 'GET',
    headers: {
      ...(body ? { 'Content-Type': 'application/json' } : {}),
      'x402-payment': `${wallet.address}:${signature}`,
    },
    ...(body && { body: JSON.stringify(body) }),
  });

  if (!paid.ok) throw new Error(`Paid request failed: ${paid.status}`);
  return paid.json();
}

// Example: calling a summarizer service
(async () => {
  const result = await x402Fetch(
    'https://agent-service.example.com/summarize',
    { text: 'The quick brown fox jumps over the lazy dog.', maxLength: 20 }
  );
  console.log('Summary:', result.summary);
})();

无状态——无需管理托管合约;每次调用都是原子的。

延迟——两次往返(探测 + 付费)在 Base 上增加约 100-200ms。

成本——x402 header 几乎不产生 gas;USDC 转账本身在 Base 上的成本约为 0.0005 USDC(≈ $0.0005)。

5. 用 MCP-Lite 描述服务

MCP-Lite 文档在 OpenAPI 基础上扩展了一个 x-payment 对象,告诉消费者需要支付多少以及使用什么代币。

openapi: 3.1.0
info:
  title: Text Summarizer
  version: 2.0.0
servers:
  - url: https://agent-service.example.com
paths:
  /summarize:
    post:
      summary: Return a concise summary of the supplied text.
      operationId: summarize
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [text]
              properties:
                text:
                  type: string
                  description: Input text to summarize.
                maxLength:
                  type: integer
                  minimum: 10
                  maximum: 200
                  default: 60
      responses:
        '200':
          description: Summary result.
          content:
            application/json:
              schema:
                type: object
                properties:
                  summary:
                    type: string
        '402':
          description: Payment required.
          headers:
            x402-payment-request:
              schema:
                type: string
                example: |
                  {"scheme":"erc20","network":"base","token":"0x833589fCD6e
Original source

本文由 AI 翻译整理,来源 dev.to · AI,原文版权归原作者所有。

阅读原文
上一篇
AI Agent的USDC托管支付:无信任自由职业实战
下一篇
双代码库架构:如何让 LLM 彻底戒掉编造引文

资讯速览

dev.to · AI · 2026-09-08 05:31

AI 评分 8.0 / 10

相关标签

#Agent#A2A#协议

继续阅读

  • 2026年Agent间市场平台完全指南
  • AI Agent的USDC托管支付:无信任自由职业实战
  • 双代码库架构:如何让 LLM 彻底戒掉编造引文
  • AI连接Odoo数据后仍算错收入:业务语义陷阱实战
  • AI编程Agent从单兵作战到分层协作