欢迎光临
我们一直在努力

智能体通信协议:MCP、A2A与ANP,构建智能体协作网络

本章将深入探讨智能体通信协议这一关键基础设施层。从单体智能体的局限性出发,解析为何需要通信协议,然后系统介绍三种主流协议:MCP(Model Context Protocol) 用于智能体与工具的标准化通信,A2A(Agent-to-Agent Protocol) 用于智能体间的点对点协作,ANP(Agent Network Protocol) 用于构建大规模智能体网络。通过对比三种协议的设计理念与HelloAgents的三层架构实现,帮助读者理解如何选择合适的协议解决实际问题。

在前面的章节中,我们构建了功能完备的单体智能体,它们具备推理、工具调用和记忆能力。然而,当我们尝试构建更复杂的AI系统时,自然会有疑问:如何让智能体与外部世界高效交互?如何让多个智能体相互协作?

这正是智能体通信协议要解决的核心问题。本章将为HelloAgents框架引入三种通信协议:MCP(Model Context Protocol) 用于智能体与工具的标准化通信,A2A(Agent-to-Agent Protocol) 用于智能体间的点对点协作,ANP(Agent Network Protocol) 用于构建大规模智能体网络。这三种协议共同构成了智能体通信的基础设施层。

通过本章的学习,您将掌握智能体通信协议的设计理念和实践技能,理解三种主流协议的设计差异,学会如何选择合适的协议来解决实际问题。

📊 全文知识框架图

#mermaid-svg-R7DUxYPxx3nfX4gR{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-R7DUxYPxx3nfX4gR .error-icon{fill:#552222;}#mermaid-svg-R7DUxYPxx3nfX4gR .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-R7DUxYPxx3nfX4gR .marker{fill:#333333;stroke:#333333;}#mermaid-svg-R7DUxYPxx3nfX4gR .marker.cross{stroke:#333333;}#mermaid-svg-R7DUxYPxx3nfX4gR svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-R7DUxYPxx3nfX4gR p{margin:0;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge{stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 text{fill:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth–1{stroke-width:17;}#mermaid-svg-R7DUxYPxx3nfX4gR .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-0{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-0{stroke-width:14;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-1{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-1{stroke-width:11;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 text{fill:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-2{stroke-width:8;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-3{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-3{stroke-width:5;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-4{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-4{stroke-width:2;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-5{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-5{stroke-width:-1;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-6{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-6{stroke-width:-4;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-7{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-7{stroke-width:-7;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-8{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-8{stroke-width:-10;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-9{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-9{stroke-width:-13;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 polygon,#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 text{fill:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .node-icon-10{font-size:40px;color:black;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .edge-depth-10{stroke-width:-16;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled circle,#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:lightgray;}#mermaid-svg-R7DUxYPxx3nfX4gR .disabled text{fill:#efefef;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-root rect,#mermaid-svg-R7DUxYPxx3nfX4gR .section-root path,#mermaid-svg-R7DUxYPxx3nfX4gR .section-root circle,#mermaid-svg-R7DUxYPxx3nfX4gR .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-R7DUxYPxx3nfX4gR .section-root text{fill:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-root span{color:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .section-2 span{color:#ffffff;}#mermaid-svg-R7DUxYPxx3nfX4gR .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-R7DUxYPxx3nfX4gR .edge{fill:none;}#mermaid-svg-R7DUxYPxx3nfX4gR .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-R7DUxYPxx3nfX4gR :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

智能体通信协议

为何需要通信协议

单体智能体的三大局限

工具集成困境

能力扩展瓶颈

协作的缺失

通信协议的核心价值

标准化接口

统一访问方式

降低集成成本

三种主流协议

MCP

全称: Model Context Protocol

提出方: Anthropic

定位: 智能体↔工具

核心: 标准化工具访问 + 上下文共享

比喻: USB接口

A2A

全称: Agent-to-Agent Protocol

提出方: Google

定位: 智能体↔智能体

核心: 对等通信

比喻: 团队对话

ANP

全称: Agent Network Protocol

提出方: 开源社区

定位: 服务发现与路由

核心: 去中心化服务发现

比喻: 电话黄页

HelloAgents架构

协议实现层

工具封装层

智能体集成层

综合案例

智能文档助手

一、为什么需要通信协议?

1.1 单体智能体的三大局限

回顾我们在之前构建的ReAct智能体,它已经具备了强大的推理和工具调用能力。让我们看一个典型的使用场景:

from hello_agents import ReActAgent, HelloAgentsLLM
from hello_agents.tools import CalculatorTool, SearchTool

llm = HelloAgentsLLM()
agent = ReActAgent(name="AI助手", llm=llm)
agent.add_tool(CalculatorTool())
agent.add_tool(SearchTool())
# 智能体可以独立完成任务
response = agent.run("搜索最新的AI新闻,并计算相关公司的市值总和")

这个智能体工作得很好,但它面临着三个根本性的限制:

限制说明
工具集成的困境 每当需要访问新的外部服务(如GitHub API、数据库、文件系统),都必须编写专门的Tool类。这不仅工作量大,而且不同开发者编写的工具无法互相兼容
能力扩展的瓶颈 智能体的能力被限制在预先定义的工具集内,无法动态发现和使用新的服务
协作的缺失 当任务复杂到需要多个专业智能体协作时(如研究员+撰写员+编辑),只能通过手动编排来协调它们的工作

让我们通过一个更具体的例子来理解这些限制。假设你要构建一个智能研究助手,它需要访问GitHub、数据库、天气API等多种服务:

# 传统方式:手动集成每个服务
class GitHubTool(BaseTool):
"""需要手写GitHub API适配器"""
def run(self, repo_url):
# 大量的API调用代码…
pass

class DatabaseTool(BaseTool):
"""需要手写数据库适配器"""
def run(self, query):
# 数据库连接和查询代码…
pass

class WeatherTool(BaseTool):
"""需要手写天气API适配器"""
def run(self, location):
# 天气API调用代码…
pass

# 每个新服务都需要重复这个过程
agent.add_tool(GitHubTool())
agent.add_tool(DatabaseTool())
agent.add_tool(WeatherTool())

这种方式存在明显的问题:代码重复(每个工具都要处理HTTP请求、错误处理、认证等),难以维护(API变更需要修改所有相关工具),无法复用(其他开发者的工具无法直接使用),扩展性差(添加新服务需要大量编码工作)。

1.2 通信协议的核心价值

💡 通俗理解:通信协议就像互联网的TCP/IP协议——它让不同的设备能够相互通信,而不需要为每种设备编写专门的通信代码。

通信协议的核心价值在于,它提供了一套标准化的接口规范,让智能体能够以统一的方式访问各种外部服务,而无需为每个服务编写专门的适配器。

有了通信协议,上面的代码可以简化为:

from hello_agents.tools import MCPTool

# 连接到MCP服务器,自动获得所有工具
mcp_tool = MCPTool()
# 智能体通过统一的MCP接口访问所有服务
agent.add_tool(mcp_tool)

通信协议带来的变化是根本性的:

  • 标准化接口:不同服务提供统一的访问方式
  • 互操作性:不同开发者编写的工具可以无缝集成
  • 动态发现:智能体可以在运行时发现新的服务
  • 可扩展性:系统可以轻松添加新的功能模块

💡 通俗理解:通信协议就像是给智能体配备了一个“万能插座”——无论你接的是什么设备(文件系统、数据库、GitHub),只要它符合协议标准,智能体就能直接用,不需要为每个设备单独配一个转接头。

二、三种主流通信协议

智能体通信协议并非单一的解决方案,而是针对不同通信场景设计的一系列标准。本章以目前业界主流的三种协议——MCP、A2A和ANP为例进行实践。

2.1 MCP:智能体与工具的桥梁

MCP(Model Context Protocol) 由Anthropic团队提出,其核心设计理念是标准化智能体与外部工具/资源的通信方式。

💡 通俗理解:MCP就像是给AI智能体配备的“USB接口”——只要工具支持这个接口标准,智能体就能像插U盘一样即插即用。

MCP的设计哲学不仅是“标准化接口”,更重要的是上下文共享(context sharing) 。它不仅仅是RPC调用,而是让智能体和工具能够共享丰富的上下文信息。例如,当智能体访问代码仓库时,MCP服务器不仅提供文件内容,还能提供代码结构、依赖关系、提交历史等上下文信息,帮助智能体做出更智能的决策。

想象一下,你的智能体需要访问文件系统、数据库、GitHub、Slack等各种服务。传统做法是为每个服务编写专门的适配器,这不仅工作量大,而且难以维护。MCP通过定义统一的协议规范,让所有服务都能以相同的方式被访问。

MCP的完整交互流程:

#mermaid-svg-9zBQ3I8NIy6uSapS{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-9zBQ3I8NIy6uSapS .error-icon{fill:#552222;}#mermaid-svg-9zBQ3I8NIy6uSapS .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-9zBQ3I8NIy6uSapS .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-9zBQ3I8NIy6uSapS .marker{fill:#333333;stroke:#333333;}#mermaid-svg-9zBQ3I8NIy6uSapS .marker.cross{stroke:#333333;}#mermaid-svg-9zBQ3I8NIy6uSapS svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-9zBQ3I8NIy6uSapS p{margin:0;}#mermaid-svg-9zBQ3I8NIy6uSapS .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS .cluster-label text{fill:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS .cluster-label span{color:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS .cluster-label span p{background-color:transparent;}#mermaid-svg-9zBQ3I8NIy6uSapS .label text,#mermaid-svg-9zBQ3I8NIy6uSapS span{fill:#333;color:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS .node rect,#mermaid-svg-9zBQ3I8NIy6uSapS .node circle,#mermaid-svg-9zBQ3I8NIy6uSapS .node ellipse,#mermaid-svg-9zBQ3I8NIy6uSapS .node polygon,#mermaid-svg-9zBQ3I8NIy6uSapS .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-9zBQ3I8NIy6uSapS .rough-node .label text,#mermaid-svg-9zBQ3I8NIy6uSapS .node .label text,#mermaid-svg-9zBQ3I8NIy6uSapS .image-shape .label,#mermaid-svg-9zBQ3I8NIy6uSapS .icon-shape .label{text-anchor:middle;}#mermaid-svg-9zBQ3I8NIy6uSapS .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-9zBQ3I8NIy6uSapS .rough-node .label,#mermaid-svg-9zBQ3I8NIy6uSapS .node .label,#mermaid-svg-9zBQ3I8NIy6uSapS .image-shape .label,#mermaid-svg-9zBQ3I8NIy6uSapS .icon-shape .label{text-align:center;}#mermaid-svg-9zBQ3I8NIy6uSapS .node.clickable{cursor:pointer;}#mermaid-svg-9zBQ3I8NIy6uSapS .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-9zBQ3I8NIy6uSapS .arrowheadPath{fill:#333333;}#mermaid-svg-9zBQ3I8NIy6uSapS .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-9zBQ3I8NIy6uSapS .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-9zBQ3I8NIy6uSapS .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-9zBQ3I8NIy6uSapS .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-9zBQ3I8NIy6uSapS .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-9zBQ3I8NIy6uSapS .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-9zBQ3I8NIy6uSapS .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-9zBQ3I8NIy6uSapS .cluster text{fill:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS .cluster span{color:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-9zBQ3I8NIy6uSapS .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-9zBQ3I8NIy6uSapS rect.text{fill:none;stroke-width:0;}#mermaid-svg-9zBQ3I8NIy6uSapS .icon-shape,#mermaid-svg-9zBQ3I8NIy6uSapS .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-9zBQ3I8NIy6uSapS .icon-shape p,#mermaid-svg-9zBQ3I8NIy6uSapS .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-9zBQ3I8NIy6uSapS .icon-shape .label rect,#mermaid-svg-9zBQ3I8NIy6uSapS .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-9zBQ3I8NIy6uSapS .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-9zBQ3I8NIy6uSapS .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-9zBQ3I8NIy6uSapS :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

MCP交互流程

👤 用户问题

🖥️ Host应用如Claude Desktop

🧠 模型分析理解需求

🔌 MCP Client发起请求

📡 MCP Server执行操作

📊 返回结果

一个典型的MCP交互流程是:用户问题 → Claude Desktop(Host)→ Claude模型分析 → 需要文件信息 → MCP Client连接 → 文件系统MCP Server → 执行操作 → 返回结果 → Claude生成回答 → 显示在Claude Desktop上。

在实际使用中,MCP客户端可以:

  • 连接到MCP服务器(有多种连接方式)
  • 查询可用工具(通过list_tools()获取工具描述)
  • 调用工具
  • 访问服务器提供的资源和提示模板

实战示例:使用GitHub MCP服务:

# 完整示例:使用 GitHub MCP 服务
# 注意:需要设置环境变量
# Windows: $env:GITHUB_PERSONAL_ACCESS_TOKEN="your_token_here"
# Linux/macOS: export GITHUB_PERSONAL_ACCESS_TOKEN="your_token_here"

from hello_agents.tools import MCPTool

# 创建 GitHub MCP 工具
github_tool = MCPTool(
server_command=["npx", "-y", "@modelcontextprotocol/server-github"]
)

# 1. 列出可用工具
print("可用工具:")
result = github_tool.run({"action": "list_tools"})
print(result)

# 2. 搜索仓库
print("\\n搜索仓库:")
result = github_tool.run({
"action": "call_tool",
"tool_name": "search_repositories",
"arguments": {
"query": "AI agents language:python",
"page": 1,
"perPage": 3
}
})
print(result)

MCP vs 传统方式对比:

对比维度传统方式MCP方式
集成方式 为每个服务手写适配器 统一协议,自动适配
代码量 大量重复代码 少量配置代码
维护成本 API变更需逐个修改 只需维护协议层
可复用性 工具无法跨项目复用 服务可被任何MCP客户端使用
上下文共享 支持代码结构、依赖关系等丰富上下文

2.2 A2A:智能体间的对话

A2A(Agent-to-Agent Protocol) 由Google团队提出,其核心设计理念是实现智能体之间的点对点通信。

💡 通俗理解:如果说MCP是智能体的“USB接口”(连接工具),那A2A就是智能体的“微信”(连接其他智能体)。它让不同的AI能够互相“聊天”、分工协作。

与MCP关注智能体与工具的通信不同,A2A关注的是智能体之间如何相互协作。这种设计让智能体能够像人类团队一样进行对话、协商和协作。

A2A的设计哲学是“对等通信”(peer-to-peer communication) 。在A2A网络中,每个智能体既是服务提供者,也是服务消费者。智能体可以主动发起请求,也可以响应其他智能体的请求。这种对等的设计避免了中心化协调器的瓶颈,让智能体网络更加灵活和可扩展。

#mermaid-svg-DSf4LRjylIrShKvk{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-DSf4LRjylIrShKvk .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-DSf4LRjylIrShKvk .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-DSf4LRjylIrShKvk .error-icon{fill:#552222;}#mermaid-svg-DSf4LRjylIrShKvk .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-DSf4LRjylIrShKvk .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-DSf4LRjylIrShKvk .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-DSf4LRjylIrShKvk .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-DSf4LRjylIrShKvk .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-DSf4LRjylIrShKvk .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-DSf4LRjylIrShKvk .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-DSf4LRjylIrShKvk .marker{fill:#333333;stroke:#333333;}#mermaid-svg-DSf4LRjylIrShKvk .marker.cross{stroke:#333333;}#mermaid-svg-DSf4LRjylIrShKvk svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-DSf4LRjylIrShKvk p{margin:0;}#mermaid-svg-DSf4LRjylIrShKvk .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-DSf4LRjylIrShKvk .cluster-label text{fill:#333;}#mermaid-svg-DSf4LRjylIrShKvk .cluster-label span{color:#333;}#mermaid-svg-DSf4LRjylIrShKvk .cluster-label span p{background-color:transparent;}#mermaid-svg-DSf4LRjylIrShKvk .label text,#mermaid-svg-DSf4LRjylIrShKvk span{fill:#333;color:#333;}#mermaid-svg-DSf4LRjylIrShKvk .node rect,#mermaid-svg-DSf4LRjylIrShKvk .node circle,#mermaid-svg-DSf4LRjylIrShKvk .node ellipse,#mermaid-svg-DSf4LRjylIrShKvk .node polygon,#mermaid-svg-DSf4LRjylIrShKvk .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-DSf4LRjylIrShKvk .rough-node .label text,#mermaid-svg-DSf4LRjylIrShKvk .node .label text,#mermaid-svg-DSf4LRjylIrShKvk .image-shape .label,#mermaid-svg-DSf4LRjylIrShKvk .icon-shape .label{text-anchor:middle;}#mermaid-svg-DSf4LRjylIrShKvk .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-DSf4LRjylIrShKvk .rough-node .label,#mermaid-svg-DSf4LRjylIrShKvk .node .label,#mermaid-svg-DSf4LRjylIrShKvk .image-shape .label,#mermaid-svg-DSf4LRjylIrShKvk .icon-shape .label{text-align:center;}#mermaid-svg-DSf4LRjylIrShKvk .node.clickable{cursor:pointer;}#mermaid-svg-DSf4LRjylIrShKvk .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-DSf4LRjylIrShKvk .arrowheadPath{fill:#333333;}#mermaid-svg-DSf4LRjylIrShKvk .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-DSf4LRjylIrShKvk .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-DSf4LRjylIrShKvk .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-DSf4LRjylIrShKvk .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-DSf4LRjylIrShKvk .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-DSf4LRjylIrShKvk .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-DSf4LRjylIrShKvk .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-DSf4LRjylIrShKvk .cluster text{fill:#333;}#mermaid-svg-DSf4LRjylIrShKvk .cluster span{color:#333;}#mermaid-svg-DSf4LRjylIrShKvk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-DSf4LRjylIrShKvk .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-DSf4LRjylIrShKvk rect.text{fill:none;stroke-width:0;}#mermaid-svg-DSf4LRjylIrShKvk .icon-shape,#mermaid-svg-DSf4LRjylIrShKvk .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-DSf4LRjylIrShKvk .icon-shape p,#mermaid-svg-DSf4LRjylIrShKvk .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-DSf4LRjylIrShKvk .icon-shape .label rect,#mermaid-svg-DSf4LRjylIrShKvk .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-DSf4LRjylIrShKvk .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-DSf4LRjylIrShKvk .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-DSf4LRjylIrShKvk :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

A2A对等通信网络

对等通信

对等通信

对等通信

对等通信

🤖 智能体A服务提供者/消费者

🤖 智能体B服务提供者/消费者

🤖 智能体C服务提供者/消费者

🤖 智能体D服务提供者/消费者

A2A的核心价值在于:

  • 跨平台互操作性:不同框架开发的智能体可以相互通信
  • 任务协作:智能体可以相互委托任务、共享结果
  • 去中心化:无需中央协调器,智能体间直接通信

💡 通俗理解:A2A让不同公司、不同团队开发的AI能够像人类同事一样协同工作——你负责调研,我负责写作,他负责审核,大家各司其职又互通有无。

A2A在HelloAgents中基于Google官方的a2a-sdk实现,支持智能体间的能力发现(通过Agent Card机制)和任务委托。

2.3 ANP:智能体网络的基础设施

ANP(Agent Network Protocol) 是一个概念性的协议框架,目前由开源社区维护,尚未形成成熟生态。其核心设计理念是构建大规模智能体网络的基础设施。

如果说MCP解决的是“如何访问工具”,A2A解决的是“如何与其他智能体对话”,那么ANP解决的是“如何在大规模网络中发现和连接智能体”。

💡 通俗理解:ANP就像是智能体世界的“电话黄页+DNS服务器”——当网络中有成千上万个智能体时,一个智能体怎么知道谁可以提供它需要的服务?ANP就是解决这个“找谁帮忙”的问题。

ANP的设计哲学是“去中心化服务发现”(decentralized service discovery) 。在一个包含成百上千个智能体的网络中,如何让智能体能够找到它需要的服务?ANP提供了服务注册、发现和路由机制,让智能体能够动态地发现网络中的其他服务,而不需要预先配置所有的连接关系。

#mermaid-svg-IcNlWB4JnWpEHXPU{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-IcNlWB4JnWpEHXPU .error-icon{fill:#552222;}#mermaid-svg-IcNlWB4JnWpEHXPU .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-IcNlWB4JnWpEHXPU .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-IcNlWB4JnWpEHXPU .marker{fill:#333333;stroke:#333333;}#mermaid-svg-IcNlWB4JnWpEHXPU .marker.cross{stroke:#333333;}#mermaid-svg-IcNlWB4JnWpEHXPU svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-IcNlWB4JnWpEHXPU p{margin:0;}#mermaid-svg-IcNlWB4JnWpEHXPU .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU .cluster-label text{fill:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU .cluster-label span{color:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU .cluster-label span p{background-color:transparent;}#mermaid-svg-IcNlWB4JnWpEHXPU .label text,#mermaid-svg-IcNlWB4JnWpEHXPU span{fill:#333;color:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU .node rect,#mermaid-svg-IcNlWB4JnWpEHXPU .node circle,#mermaid-svg-IcNlWB4JnWpEHXPU .node ellipse,#mermaid-svg-IcNlWB4JnWpEHXPU .node polygon,#mermaid-svg-IcNlWB4JnWpEHXPU .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-IcNlWB4JnWpEHXPU .rough-node .label text,#mermaid-svg-IcNlWB4JnWpEHXPU .node .label text,#mermaid-svg-IcNlWB4JnWpEHXPU .image-shape .label,#mermaid-svg-IcNlWB4JnWpEHXPU .icon-shape .label{text-anchor:middle;}#mermaid-svg-IcNlWB4JnWpEHXPU .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-IcNlWB4JnWpEHXPU .rough-node .label,#mermaid-svg-IcNlWB4JnWpEHXPU .node .label,#mermaid-svg-IcNlWB4JnWpEHXPU .image-shape .label,#mermaid-svg-IcNlWB4JnWpEHXPU .icon-shape .label{text-align:center;}#mermaid-svg-IcNlWB4JnWpEHXPU .node.clickable{cursor:pointer;}#mermaid-svg-IcNlWB4JnWpEHXPU .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-IcNlWB4JnWpEHXPU .arrowheadPath{fill:#333333;}#mermaid-svg-IcNlWB4JnWpEHXPU .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-IcNlWB4JnWpEHXPU .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-IcNlWB4JnWpEHXPU .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-IcNlWB4JnWpEHXPU .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-IcNlWB4JnWpEHXPU .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-IcNlWB4JnWpEHXPU .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-IcNlWB4JnWpEHXPU .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-IcNlWB4JnWpEHXPU .cluster text{fill:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU .cluster span{color:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-IcNlWB4JnWpEHXPU .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-IcNlWB4JnWpEHXPU rect.text{fill:none;stroke-width:0;}#mermaid-svg-IcNlWB4JnWpEHXPU .icon-shape,#mermaid-svg-IcNlWB4JnWpEHXPU .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-IcNlWB4JnWpEHXPU .icon-shape p,#mermaid-svg-IcNlWB4JnWpEHXPU .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-IcNlWB4JnWpEHXPU .icon-shape .label rect,#mermaid-svg-IcNlWB4JnWpEHXPU .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-IcNlWB4JnWpEHXPU .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-IcNlWB4JnWpEHXPU .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-IcNlWB4JnWpEHXPU :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

ANP服务发现机制

1. 注册服务

2. 查询服务

3. 返回服务列表

4. 直接通信

🤖 智能体A

📋 服务注册中心

🤖 智能体B

🤖 智能体C

ANP的典型操作包括:

  • 注册服务:智能体向网络注册自己提供的能力
  • 发现服务:智能体查询网络中可用的服务
  • 服务路由:将请求路由到提供相应服务的智能体

在HelloAgents中,ANP是框架自研的轻量级实现,提供服务发现和网络管理功能。

2.4 三种协议设计理念比较

对比维度MCPA2AANP
全称 Model Context Protocol Agent-to-Agent Protocol Agent Network Protocol
提出方 Anthropic Google 开源社区
解决的问题 如何访问工具? 如何与其他智能体协作? 如何在大规模网络中发现服务?
设计哲学 标准化接口 + 上下文共享 对等通信 去中心化服务发现
成熟度 相对成熟,生态较完善 逐步发展 概念阶段,尚未形成成熟生态
通俗类比 🔌 USB接口 💬 团队对话 📞 电话黄页

三、HelloAgents通信协议架构

3.1 三层架构设计

HelloAgents的通信协议架构采用三层设计,从底层到上层分别是:协议实现层、工具封装层和智能体集成层。

#mermaid-svg-7xIC8QPqVvRPcfrX{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-7xIC8QPqVvRPcfrX .error-icon{fill:#552222;}#mermaid-svg-7xIC8QPqVvRPcfrX .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-7xIC8QPqVvRPcfrX .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-7xIC8QPqVvRPcfrX .marker{fill:#333333;stroke:#333333;}#mermaid-svg-7xIC8QPqVvRPcfrX .marker.cross{stroke:#333333;}#mermaid-svg-7xIC8QPqVvRPcfrX svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-7xIC8QPqVvRPcfrX p{margin:0;}#mermaid-svg-7xIC8QPqVvRPcfrX .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX .cluster-label text{fill:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX .cluster-label span{color:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX .cluster-label span p{background-color:transparent;}#mermaid-svg-7xIC8QPqVvRPcfrX .label text,#mermaid-svg-7xIC8QPqVvRPcfrX span{fill:#333;color:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX .node rect,#mermaid-svg-7xIC8QPqVvRPcfrX .node circle,#mermaid-svg-7xIC8QPqVvRPcfrX .node ellipse,#mermaid-svg-7xIC8QPqVvRPcfrX .node polygon,#mermaid-svg-7xIC8QPqVvRPcfrX .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-7xIC8QPqVvRPcfrX .rough-node .label text,#mermaid-svg-7xIC8QPqVvRPcfrX .node .label text,#mermaid-svg-7xIC8QPqVvRPcfrX .image-shape .label,#mermaid-svg-7xIC8QPqVvRPcfrX .icon-shape .label{text-anchor:middle;}#mermaid-svg-7xIC8QPqVvRPcfrX .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-7xIC8QPqVvRPcfrX .rough-node .label,#mermaid-svg-7xIC8QPqVvRPcfrX .node .label,#mermaid-svg-7xIC8QPqVvRPcfrX .image-shape .label,#mermaid-svg-7xIC8QPqVvRPcfrX .icon-shape .label{text-align:center;}#mermaid-svg-7xIC8QPqVvRPcfrX .node.clickable{cursor:pointer;}#mermaid-svg-7xIC8QPqVvRPcfrX .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-7xIC8QPqVvRPcfrX .arrowheadPath{fill:#333333;}#mermaid-svg-7xIC8QPqVvRPcfrX .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-7xIC8QPqVvRPcfrX .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-7xIC8QPqVvRPcfrX .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-7xIC8QPqVvRPcfrX .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-7xIC8QPqVvRPcfrX .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-7xIC8QPqVvRPcfrX .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-7xIC8QPqVvRPcfrX .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-7xIC8QPqVvRPcfrX .cluster text{fill:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX .cluster span{color:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-7xIC8QPqVvRPcfrX .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-7xIC8QPqVvRPcfrX rect.text{fill:none;stroke-width:0;}#mermaid-svg-7xIC8QPqVvRPcfrX .icon-shape,#mermaid-svg-7xIC8QPqVvRPcfrX .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-7xIC8QPqVvRPcfrX .icon-shape p,#mermaid-svg-7xIC8QPqVvRPcfrX .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-7xIC8QPqVvRPcfrX .icon-shape .label rect,#mermaid-svg-7xIC8QPqVvRPcfrX .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-7xIC8QPqVvRPcfrX .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-7xIC8QPqVvRPcfrX .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-7xIC8QPqVvRPcfrX :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

协议实现层

工具封装层

智能体集成层

🤖 智能体ReActAgent/SimpleAgent

🔧 MCPToolMCP协议封装

🔧 A2AToolA2A协议封装

🔧 ANPToolANP协议封装

📡 MCP Client协议实现

📡 A2A Client协议实现

📡 ANP Client协议实现

3.2 各层职责

层级职责核心组件
智能体集成层 智能体通过统一接口使用通信协议 ReActAgent、SimpleAgent
工具封装层 将协议能力封装为智能体可调用的工具,统一继承自BaseTool MCPTool、A2ATool、ANPTool
协议实现层 实现具体的协议客户端,处理底层通信 MCP Client、A2A Client(基于a2a-sdk)、ANP Client(自研)

这种分层设计的优势在于:

  • 关注点分离:每层只关注自己的职责
  • 可替换性:协议实现可以独立升级,不影响上层
  • 可扩展性:新增协议只需在协议层和工具层添加对应实现

3.3 基本功能体验

以下是三种协议的基本使用示例:

from hello_agents.tools import MCPTool, A2ATool, ANPTool

# 1. MCP:访问工具
mcp_tool = MCPTool()
result = mcp_tool.run({
"action": "call_tool",
"tool_name": "add",
"arguments": {"a": 10, "b": 20}
})
print(f"MCP计算结果: {result}") # 输出: 30.0

# 2. ANP:服务发现
anp_tool = ANPTool()
anp_tool.run({
"action": "register_service",
"service_id": "calculator",
"service_type": "math",
"endpoint": "http://localhost:8080"
})
services = anp_tool.run({"action": "discover_services"})
print(f"发现的服务: {services}")

# 3. A2A:智能体通信
a2a_tool = A2ATool("http://localhost:5000")
print("A2A工具创建成功")

四、综合案例:多智能体协作的智能文档助手

为了展示三种协议的协同工作,下面构建一个多Agent协作的智能文档助手:

业务目标:自动从GitHub搜索AI相关项目,并生成一份结构化文档报告。

团队分工:

#mermaid-svg-qtCpykudkx5kupZA{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-qtCpykudkx5kupZA .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-qtCpykudkx5kupZA .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-qtCpykudkx5kupZA .error-icon{fill:#552222;}#mermaid-svg-qtCpykudkx5kupZA .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-qtCpykudkx5kupZA .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-qtCpykudkx5kupZA .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-qtCpykudkx5kupZA .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-qtCpykudkx5kupZA .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-qtCpykudkx5kupZA .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-qtCpykudkx5kupZA .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-qtCpykudkx5kupZA .marker{fill:#333333;stroke:#333333;}#mermaid-svg-qtCpykudkx5kupZA .marker.cross{stroke:#333333;}#mermaid-svg-qtCpykudkx5kupZA svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-qtCpykudkx5kupZA p{margin:0;}#mermaid-svg-qtCpykudkx5kupZA .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-qtCpykudkx5kupZA .cluster-label text{fill:#333;}#mermaid-svg-qtCpykudkx5kupZA .cluster-label span{color:#333;}#mermaid-svg-qtCpykudkx5kupZA .cluster-label span p{background-color:transparent;}#mermaid-svg-qtCpykudkx5kupZA .label text,#mermaid-svg-qtCpykudkx5kupZA span{fill:#333;color:#333;}#mermaid-svg-qtCpykudkx5kupZA .node rect,#mermaid-svg-qtCpykudkx5kupZA .node circle,#mermaid-svg-qtCpykudkx5kupZA .node ellipse,#mermaid-svg-qtCpykudkx5kupZA .node polygon,#mermaid-svg-qtCpykudkx5kupZA .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-qtCpykudkx5kupZA .rough-node .label text,#mermaid-svg-qtCpykudkx5kupZA .node .label text,#mermaid-svg-qtCpykudkx5kupZA .image-shape .label,#mermaid-svg-qtCpykudkx5kupZA .icon-shape .label{text-anchor:middle;}#mermaid-svg-qtCpykudkx5kupZA .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-qtCpykudkx5kupZA .rough-node .label,#mermaid-svg-qtCpykudkx5kupZA .node .label,#mermaid-svg-qtCpykudkx5kupZA .image-shape .label,#mermaid-svg-qtCpykudkx5kupZA .icon-shape .label{text-align:center;}#mermaid-svg-qtCpykudkx5kupZA .node.clickable{cursor:pointer;}#mermaid-svg-qtCpykudkx5kupZA .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-qtCpykudkx5kupZA .arrowheadPath{fill:#333333;}#mermaid-svg-qtCpykudkx5kupZA .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-qtCpykudkx5kupZA .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-qtCpykudkx5kupZA .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-qtCpykudkx5kupZA .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-qtCpykudkx5kupZA .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-qtCpykudkx5kupZA .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-qtCpykudkx5kupZA .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-qtCpykudkx5kupZA .cluster text{fill:#333;}#mermaid-svg-qtCpykudkx5kupZA .cluster span{color:#333;}#mermaid-svg-qtCpykudkx5kupZA div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-qtCpykudkx5kupZA .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-qtCpykudkx5kupZA rect.text{fill:none;stroke-width:0;}#mermaid-svg-qtCpykudkx5kupZA .icon-shape,#mermaid-svg-qtCpykudkx5kupZA .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-qtCpykudkx5kupZA .icon-shape p,#mermaid-svg-qtCpykudkx5kupZA .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-qtCpykudkx5kupZA .icon-shape .label rect,#mermaid-svg-qtCpykudkx5kupZA .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-qtCpykudkx5kupZA .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-qtCpykudkx5kupZA .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-qtCpykudkx5kupZA :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

智能文档助手团队

👤 用户需求

🔍 Agent1GitHub搜索专家使用MCP

📝 Agent2文档生成专家使用A2A

📄 最终报告

角色职责使用的协议
Agent1:GitHub搜索专家 通过MCP访问GitHub服务,搜索AI相关仓库 MCP(智能体↔工具)
Agent2:文档生成专家 接收搜索结果,生成结构化报告 A2A(智能体↔智能体)

核心实现:

from hello_agents import SimpleAgent, HelloAgentsLLM
from hello_agents.tools import MCPTool
from dotenv import load_dotenv

load_dotenv()

print("="*70)
print("多Agent协作的智能文档助手")
print("="*70)

# Agent1: GitHub搜索专家(使用MCP访问GitHub)
github_tool = MCPTool(
server_command=["npx", "-y", "@modelcontextprotocol/server-github"]
)
search_agent = SimpleAgent(
name="GitHub搜索专家",
llm=HelloAgentsLLM(),
tools=[github_tool]
)

# Agent2: 文档生成专家(通过A2A接收数据)
doc_agent = SimpleAgent(
name="文档生成专家",
llm=HelloAgentsLLM()
)

# 工作流程:
# 1. Agent1搜索GitHub仓库(通过MCP)
# 2. 通过A2A的Agent Card机制发现对方能力,进行任务委托
# 3. Agent2生成最终报告

这个案例展示了三种协议的协同价值:

  • MCP让Agent1能够标准化地访问GitHub服务
  • A2A让两个智能体能够通过Agent Card机制发现对方能力,无缝传递任务和数据
  • ANP(如需扩展到更大网络)可让更多智能体通过服务发现机制动态加入协作

五、核心概念速查表

术语通俗解释
通信协议(Communication Protocol) 智能体之间、智能体与工具之间通信的“通用语言”和“标准接口”
MCP(Model Context Protocol) Anthropic提出的协议,让智能体像插USB一样访问各种工具和服务
A2A(Agent-to-Agent Protocol) Google提出的协议,让不同智能体像人类团队一样对话协作
ANP(Agent Network Protocol) 开源社区维护的概念性协议框架,解决大规模智能体网络中的服务发现与连接问题
协议实现层 HelloAgents三层架构的底层,负责具体协议客户端实现
工具封装层 HelloAgents三层架构的中间层,将协议能力封装为工具
智能体集成层 HelloAgents三层架构的顶层,智能体通过统一接口使用通信协议
对等通信(Peer-to-Peer) A2A的设计哲学,每个智能体既是服务提供者也是消费者
服务发现(Service Discovery) ANP的核心功能,让智能体在网络中找到需要的服务
上下文共享(Context Sharing) MCP的设计哲学之一,让智能体和工具共享丰富的上下文信息

六、思考题(帮助加深理解)

  • MCP、A2A和ANP三种协议分别解决了什么问题? 如果一个智能体系统只需要访问外部工具,应该使用哪种协议?如果需要多个智能体协作呢?如果需要构建大规模智能体网络呢?

  • 为什么说MCP像“USB接口”,A2A像“团队对话”,ANP像“电话黄页”? 这些比喻分别对应了协议的什么特点?

  • HelloAgents的三层架构设计(协议实现层→工具封装层→智能体集成层)有什么好处? 如果去掉中间的工具封装层,会有什么问题?

  • 在智能文档助手案例中,MCP和A2A是如何协同工作的? 如果还需要更多智能体加入(如审核专家、排版专家),ANP可以发挥什么作用?

  • 三种协议中,MCP是目前相对成熟、使用较广泛的。 你认为A2A和ANP在未来会有怎样的发展?什么样的应用场景会推动它们的普及?

  • 参考资料

  • Datawhale Hello-Agents 第十章《智能体通信协议》
    https://datawhalechina.github.io/hello-agents/#/./chapter10/第十章 智能体通信协议

  • hello-agents/docs/chapter10/Chapter10-Agent-Communication-Protocols.md
    https://github.com/datawhalechina/hello-agents/blob/main/docs/chapter10/Chapter10-Agent-Communication-Protocols.md

  • 结语

    在这一章中,我们系统学习了智能体通信协议这一关键基础设施:

    • 为什么需要通信协议——单体智能体面临工具集成困境、能力扩展瓶颈和协作缺失三大局限,通信协议通过标准化接口解决了这些问题
    • 三种主流协议——MCP(智能体↔工具,Anthropic)、A2A(智能体↔智能体,Google)、ANP(大规模网络服务发现,开源社区)
    • HelloAgents三层架构——协议实现层→工具封装层→智能体集成层
    • 综合案例——通过MCP+A2A协同,构建多智能体协作的智能文档助手

    三种协议各有侧重,共同构成了智能体通信的完整基础设施层。MCP解决“如何访问工具”,A2A解决“如何与其他智能体对话”,ANP解决“如何在大规模网络中发现和连接智能体”。

    掌握了这些协议的设计理念与实践技能,你就能够根据实际需求选择合适的协议,构建从单体智能体到多智能体协作网络的全方位解决方案。

    本文参考:Datawhale《Hello-Agents》教程第十章《智能体通信协议》的内容框架与核心知识点。本文在忠实呈现该教程内容的基础上,为便于新手理解进行了通俗化改写和图表化呈现。

    赞(0)
    未经允许不得转载:171主机测评 » 智能体通信协议:MCP、A2A与ANP,构建智能体协作网络
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址