Skip to content
Jackway's Blog
Go back

Agent应用接口格式设计

Updated:

Agent应用接口格式设计

当前 Agentic(智能体)应用的对外接口设计,正在从传统的“自定义 REST API”向标准化协议演进。为了打破不同框架和平台之间的壁垒,业界目前普遍采用分层架构的协议栈来定义这些接口。

以下是当前主流的三大类接口格式设计及其具体示例:

1. 智能体与外部工具/数据的交互接口(以 MCP 为代表)

当智能体需要调用外部 API、数据库或文件系统时,最主流的接口标准是 ​MCP(Model Context Protocol,模型上下文协议) 。它规范了工具的名称、参数定义和返回结果格式,避免因接口不统一导致调用失败。

【工具调用接口示例】 (参考 MCP 工具接口规范):

{ 
  "tool_name": "performance_test_tool", 
  "tool_version": "v3.2", 
  "params": { 
    "test_url": "https://campus-app.example.com/api/goods", 
    "concurrent_users": 100, 
    "test_duration": 60, 
    "metrics": ["response_time", "error_rate"] 
  }, 
  "callback_url": "https://test-agent.example.com/callback" 
}

2. 智能体与智能体之间的协作接口(以 A2A / ACP 为代表)

在多智能体系统中,跨平台、跨厂商的任务委派和协同工作是核心需求。目前的接口格式主要分为两种流派:

(1) A2A(Agent-to-Agent Protocol)

由 Google 主导,聚焦于让 Agent 互相“认识”并发起调用。其核心机制是通过一个名为 /.well-known/agent.json​ 的标准化**智能体卡片(Agent Card)**来暴露身份和能力。

{   
  "name": "内容助手",
  "description": "负责撰写和优化公众号文章",
  "url": "https://agent.example.com",
  "capabilities": { "streaming": true, "pushNotifications": false },
  "skills": [
    {
      "id": "write_article",
      "name": "撰写文章",
      "inputModes": ["text"],
      "outputModes": ["text"]
    }
  ]
}

(2) ACP(Agent Communication Protocol)

由 IBM BeeAI 推动,采用传统的 RESTful HTTP 接口格式(如 HTTP POST),无需特殊 SDK,非常适合企业级规模的模块化集成和遗留系统集成。

3. 智能体与网页环境的原生交互接口(WebMCP)

为了让网站不再只是静态页面,而是能直接向 AI 代理暴露结构化工具,W3C 社区正在孵化 WebMCP 标准。它允许网页在浏览器层面声明可调用的工具,带有明确的名称、描述和输入输出 Schema。

navigator.modelContext.registerTool({
  name: "add_to_cart",
  description: "将商品加入购物车",
  type: "object",
  properties: {
    productId: { type: "string" },
    quantity: { type: "integer" }
  },
  required: ["productId"]
},
execute: async (params) => {
  await addToCart(params.productId, params.quantity);
  return { success: true, cartCount: getCartCount() };
}
});	

Share this post:

Previous Post
电动车丢了
Next Post
装修总结