Discover MCPs & agents
Loading MCPs and agents…
Loading MCPs and agents…
Complete demo of Multi-Remote-Agent-Microservices (A2A+MCP+Agent Framework)
Fetched from the repository for this visit.
基于 .NET Aspire、Microsoft Agent Framework、A2A 和 MCP 协议构建的多智能体微服务系统。
在现代企业环境中,项目管理涉及多个专业领域的协作,包括技术评估、人力资源配置、财务预算控制、质量风险管理和项目进度规划等。传统的单体智能体系统存在以下问题:
通用性 vs 专业性的矛盾
维护和更新困难
不符合组织结构
基于康威定律在 AI 时代的应用,本项目提出了多智能体微服务架构:
"设计系统的架构应该映射组织的沟通结构。"
每个专业团队维护自己的智能体服务,实现:
graph TB
subgraph "用户交互层"
User[👤 用户/客户端<br/>Blazor Web UI]
end
subgraph "智能编排层"
PM[🎯 项目经理智能体<br/>ProjectManagerAgent<br/>━━━━━━━━━━━<br/>统一协调与决策<br/>3阶段工作流编排]
end
subgraph "专业服务层 - 并行分析"
Tech[💻 技术团队服务<br/>Tech Agent<br/>━━━━━━━━━━━<br/>MCP工具 + A2A端点]
HR[👥 HR团队服务<br/>HR Agent<br/>━━━━━━━━━━━<br/>MCP工具 + A2A端点]
Finance[💰 财务团队服务<br/>Finance Agent<br/>━━━━━━━━━━━<br/>MCP工具 + A2A端点]
QA[🔍 QA团队服务<br/>QA Agent<br/>━━━━━━━━━━━<br/>MCP工具 + A2A端点<br/>内部4阶段工作流]
end
subgraph "专业服务层 - 规划整合"
PMO[📅 PMO团队服务<br/>PMO Agent<br/>━━━━━━━━━━━<br/>MCP工具 + A2A端点<br/>内部4阶段工作流]
end
subgraph "基础设施层"
Aspire[.NET Aspire<br/>服务编排 & 配置管理]
MCP[MCP 协议层<br/>工具与资源访问]
A2A[A2A 协议层<br/>智能体间通信]
AF[Agent Framework<br/>工作流编排引擎]
end
User --> PM
PM -->|Stage 1: 并行分析| Tech
PM -->|Stage 1: 并行分析| HR
PM -->|Stage 1: 并行分析| Finance
PM -->|Stage 1: 并行分析| QA
PM -->|Stage 2: 规划整合| PMO
PM -.->|Stage 3: 最终决策| PM
Tech --> MCP
HR --> MCP
Finance --> MCP
QA --> MCP
PMO --> MCP
PM --> A2A
Tech --> A2A
HR --> A2A
Finance --> A2A
QA --> A2A
PMO --> A2A
QA --> AF
PMO --> AF
PM --> AF
Aspire -.->|编排| PM
Aspire -.->|编排| Tech
Aspire -.->|编排| HR
Aspire -.->|编排| Finance
Aspire -.->|编排| QA
Aspire -.->|编排| PMO
style User fill:#e1f5ff,stroke:#333,stroke-width:2px
style PM fill:#fff3cd,stroke:#333,stroke-width:3px
style Tech fill:#d4edda,stroke:#333,stroke-width:2px
style HR fill:#d4edda,stroke:#333,stroke-width:2px
style Finance fill:#d4edda,stroke:#333,stroke-width:2px
style QA fill:#d4edda,stroke:#333,stroke-width:2px
style PMO fill:#cce5ff,stroke:#333,stroke-width:2px
style Aspire fill:#f8d7da,stroke:#333,stroke-width:2px
style MCP fill:#e2e3e5,stroke:#333,stroke-width:1px
style A2A fill:#e2e3e5,stroke:#333,stroke-width:1px
style AF fill:#e2e3e5,stroke:#333,stroke-width:1px
项目经理智能体使用 3 阶段工作流编排:
sequenceDiagram
participant User as 用户
participant PM as 项目经理智能体
participant Tech as 技术团队
participant HR as HR团队
participant Finance as 财务团队
participant QA as QA团队
participant PMO as PMO团队
User->>PM: 提交项目需求
Note over PM: Stage 1: 并行分析阶段
par 并行调用
PM->>Tech: A2A调用:技术需求分析
Tech-->>PM: 技术评估报告
and
PM->>HR: A2A调用:人力资源评估
HR-->>PM: 资源分析报告
and
PM->>Finance: A2A调用:预算分析
Finance-->>PM: 财务评估报告
and
PM->>QA: A2A调用:风险分析
QA-->>PM: 风险评估报告
end
Note over PM: Stage 2: 详细规划阶段
PM->>PMO: A2A调用:基于前期分析进行规划
Note over PMO: 内部工作流:<br/>任务分解→依赖分析<br/>→资源匹配→时间优化
PMO-->>PM: 详细项目计划
Note over PM: Stage 3: 整合决策阶段
PM->>PM: 综合所有分析结果<br/>生成最终决策
PM-->>User: 完整项目计划与建议
系统采用四层智能体架构设计:
graph TD
subgraph "第四层:编排智能体层"
L4[项目经理智能体<br/>━━━━━━━━━━━<br/>跨团队协调<br/>复杂工作流编排<br/>最终决策]
end
subgraph "第三层:专家智能体层"
L3A[QA 风险管理专家<br/>━━━━━━━━━━━<br/>内部工作流:<br/>识别→评估→缓解→监控]
L3B[PMO 进度规划专家<br/>━━━━━━━━━━━<br/>内部工作流:<br/>分解→依赖→匹配→优化]
end
subgraph "第二层:简单智能体层"
L2A[Tech 需求分析<br/>━━━━━━━━━━━<br/>单一职责<br/>直接调用工具]
L2B[HR 资源评估<br/>━━━━━━━━━━━<br/>单一职责<br/>直接调用工具]
L2C[Finance 预算分析<br/>━━━━━━━━━━━<br/>单一职责<br/>直接调用工具]
end
subgraph "第一层:MCP 工具层"
L1A[EstimateTechnicalComplexity<br/>ValidateTechStack<br/>GetArchitectureTemplate]
L1B[GetTeamCapabilities<br/>CheckTeamAvailability<br/>EstimateResourceCost]
L1C[ValidateBudget<br/>GetHistoricalCosts<br/>CalculateROI]
L1D[AnalyzeRiskPatterns<br/>GetComplianceRequirements<br/>ValidateDeliverables]
L1E[GetProjectTemplate<br/>ValidateSchedule<br/>CalculateCriticalPath]
end
L4 --> L3A
L4 --> L3B
L4 --> L2A
L4 --> L2B
L4 --> L2C
L3A --> L1D
L3B --> L1E
L2A --> L1A
L2B --> L1B
L2C --> L1C
style L4 fill:#ff6b6b,stroke:#333,stroke-width:3px,color:#fff
style L3A fill:#feca57,stroke:#333,stroke-width:2px
style L3B fill:#feca57,stroke:#333,stroke-width:2px
style L2A fill:#48dbfb,stroke:#333,stroke-width:2px
style L2B fill:#48dbfb,stroke:#333,stroke-width:2px
style L2C fill:#48dbfb,stroke:#333,stroke-width:2px
style L1A fill:#dfe6e9,stroke:#333,stroke-width:1px
style L1B fill:#dfe6e9,stroke:#333,stroke-width:1px
style L1C fill:#dfe6e9,stroke:#333,stroke-width:1px
style L1D fill:#dfe6e9,stroke:#333,stroke-width:1px
style L1E fill:#dfe6e9,stroke:#333,stroke-width:1px
层次说明:
| 类别 | 技术 | 版本 | 说明 |
|---|---|---|---|
| 框架 | .NET | 9.0 | 最新的 .NET 平台 |
| Web | ASP.NET Core | 9.0 | 微服务框架 |
| 前端 | Blazor Server | 9.0 | 服务端渲染 UI |
| 编排 | .NET Aspire | Latest | 云原生应用编排 |
| AI 框架 | Microsoft Agent Framework | Preview | 智能体工作流引擎 |
| 协议 | A2A (Agent-to-Agent) | Latest | 智能体间通信协议 (Google Cloud) |
| 协议 | MCP (Model Context Protocol) | Preview | 模型上下文协议 (Anthropic) |
| AI 服务 | OpenAI API | GPT-4 | 大语言模型 |
| 监控 | OpenTelemetry | Latest | 可观测性 |
AgentFrameworkAspire/
├── AgentFrameworkAspire.AppHost/ # Aspire 编排主机
├── AgentFrameworkAspire.Web/ # Web 前端
├── AgentFrameworkAspire.ServiceDefaults/ # 共享服务配置
├── Finance/ # 财务服务 (MCP + A2A Agent)
├── Tech/ # 技术架构服务 (MCP + A2A Agent)
├── HumanResource/ # 人力资源服务 (MCP + A2A Agent)
├── QA/ # QA服务 (MCP + Workflow Agent)
└── PMO/ # PMO服务 (MCP + Workflow Agent)
/finance/mcp/finance/budget-analyzer/tech/mcp/tech/requirement-analyst/hr/mcp/hr/resource-estimator/qa/mcp/qa/risk-expert/pmo/mcp/pmo/schedule-expertgit clone https://github.com/MadLongTom/A2AMicroserviceSample.git
cd A2AMicroserviceSample
编辑 AgentFrameworkAspire.AppHost/appsettings.json 文件,配置 OpenAI 参数:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
},
"Parameters": {
"openai-endpoint": "",
"openai-apikey": "your-api-key-here",
"openai-deployment": "gpt-4o-mini"
}
}
配置说明:
| 参数 | 说明 | 示例 |
|---|---|---|
openai-endpoint | API 端点(可选) - 留空:使用 OpenAI 官方 API - 填写:使用第三方兼容 API | """https://api.openai.com/v1""https://your-proxy.com/v1" |
openai-apikey | API 密钥(必填) 从 OpenAI 或第三方服务获取 | "sk-..." |
openai-deployment | 模型名称(必填) 选择要使用的模型 | "gpt-4o-mini""gpt-4""gpt-3.5-turbo" |
💡 提示:如果你使用的是 Azure OpenAI,endpoint 应该类似
https://your-resource.openai.azure.com/,deployment 是你在 Azure 中部署的模型名称。
dotnet restore
cd AgentFrameworkAspire.AppHost
dotnet run
Aspire Dashboard 会自动在浏览器中打开(默认 http://localhost:15000),显示所有服务的状态和日志。
在 Aspire Dashboard 中找到 webfrontend 服务,点击其 URL(通常是 http://localhost:5xxx)即可访问项目经理智能体的聊天界面。
尝试输入以下问题:
我们要开发一个在线教育平台,预算200万,需要多久能完成?
系统会自动调用所有专业智能体进行分析,并给出综合建议。
主要配置文件位于 AgentFrameworkAspire.AppHost/appsettings.json,这是推荐的配置方式。
如果需要针对开发环境的特殊配置,可以创建 AgentFrameworkAspire.AppHost/appsettings.Development.json:
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"Parameters": {
"openai-endpoint": "https://your-dev-api.com/v1",
"openai-apikey": "your-dev-key",
"openai-deployment": "gpt-4"
}
}
注意:
appsettings.Development.json会覆盖appsettings.json中的配置。
你也可以通过环境变量覆盖配置(优先级最高):
# Windows PowerShell
$env:Parameters__openai-endpoint = "https://api.openai.com/v1"
$env:Parameters__openai-apikey = "your-api-key"
$env:Parameters__openai-deployment = "gpt-4"
# 然后启动
dotnet run
启动后,各服务的端点如下(端口由 Aspire 动态分配,可在 Dashboard 中查看):
| 服务 | MCP 端点 | A2A 端点 | 说明 |
|---|---|---|---|
| Finance | /finance/mcp | /finance/budget-analyzer | 财务分析智能体 |
| Tech | /tech/mcp | /tech/requirement-analyst | 技术需求分析智能体 |
| HumanResource | /hr/mcp | /hr/resource-estimator | 人力资源评估智能体 |
| QA | /qa/mcp | /qa/risk-expert | 风险管理专家智能体 |
| PMO | /pmo/mcp | /pmo/schedule-expert | 进度规划专家智能体 |
| Web Frontend | - | - | 项目经理智能体 UI |
了解项目的关键文件和代码结构:
| 路径 | 说明 | 重要性 |
|---|---|---|
AgentFrameworkAspire.AppHost/Program.cs | Aspire 编排配置,参数注入 | ⭐⭐⭐ |
AgentFrameworkAspire.Web/Services/ProjectManagerAgent.cs | 项目经理智能体核心逻辑 | ⭐⭐⭐ |
AgentFrameworkAspire.ServiceDefaults/AgentHelpers.cs | ChatClient 和 MCP 工厂方法 | ⭐⭐⭐ |
Finance/Program.cs | 财务服务:MCP 工具 + A2A 端点 | ⭐⭐ |
Tech/Program.cs | 技术服务:MCP 工具 + A2A 端点 | ⭐⭐ |
HumanResource/Program.cs | HR 服务:MCP 工具 + A2A 端点 | ⭐⭐ |
QA/Program.cs | QA 服务:4 阶段工作流 | ⭐⭐ |
PMO/Program.cs | PMO 服务:4 阶段工作流 | ⭐⭐ |
在任何微服务的 Program.cs 中添加新工具:
[McpServerToolType]
public class YourCustomTools
{
[McpServerTool(Description = "工具描述")]
public Task<CallToolResult> YourMethod(
[ToolParameter(Required = true)] string param1,
[ToolParameter(Required = false)] int? param2)
{
// 实现你的业务逻辑
var result = new {
status = "success",
data = "your data"
};
return Task.FromResult(new CallToolResult
{
Content = [new TextContentBlock {
Text = JsonSerializer.Serialize(result)
}]
});
}
}
// 注册到 MCP Server
mcpServer.AddToolType<YourCustomTools>();
[McpServerResourceType]
public class YourCustomResources
{
[McpServerResource(
UriTemplate = "your://resource/{id}",
Name = "Resource Name",
Description = "Resource Description")]
public Task<ReadResourceResult> GetResource(string id)
{
var data = FetchYourData(id);
return Task.FromResult(new ReadResourceResult
{
Contents = [new TextResourceContents
{
Uri = $"your://resource/{id}",
MimeType = "application/json",
Text = JsonSerializer.Serialize(data)
}]
});
}
}
// 注册到 MCP Server
mcpServer.AddResourceType<YourCustomResources>();
简单智能体使用 ChatClient 直接集成 MCP 工具:
public class YourSimpleAgent
{
private readonly IChatClient _chatClient;
private readonly McpClient _toolsClient;
public YourSimpleAgent(IChatClient chatClient, McpClient toolsClient)
{
_chatClient = chatClient;
_toolsClient = toolsClient;
}
public void Attach(ITaskManager taskManager)
{
taskManager.OnMessageReceived = ProcessMessageAsync;
}
private async Task<A2AResponse> ProcessMessageAsync(
MessageSendParams messageSendParams,
CancellationToken cancellationToken)
{
var userMessage = messageSendParams.Message.Content.FirstOrDefault()?.Text ?? "";
// 构建聊天上下文
var messages = new List<ChatMessage>
{
new ChatMessage(ChatRole.System, "你是一个专业的XX助手..."),
new ChatMessage(ChatRole.User, userMessage)
};
// 调用 AI(自动使用 MCP 工具)
var response = await _chatClient.CompleteAsync(
messages,
cancellationToken: cancellationToken);
return new A2AResponse
{
Message = new Message
{
Role = "assistant",
Content = [new TextContent { Text = response.Message.Text }]
}
};
}
}
专家智能体使用 Agent Framework 的 Workflow 实现多阶段分析:
public class YourExpertAgent
{
private readonly Workflow _analysisWorkflow;
public YourExpertAgent(IChatClient chatClient, McpClient toolsClient)
{
// 定义多个子智能体
var stage1Agent = new ChatClientAgent(
chatClient,
"第一阶段专家指令...");
var stage2Agent = new ChatClientAgent(
chatClient,
"第二阶段专家指令...");
var stage3Agent = new ChatClientAgent(
chatClient,
"第三阶段专家指令...");
// 构建工作流:stage1 → stage2 → stage3
_analysisWorkflow = new WorkflowBuilder(stage1Agent)
.AddEdge(stage1Agent, stage2Agent)
.AddEdge(stage2Agent, stage3Agent)
.Build();
}
public void Attach(ITaskManager taskManager)
{
taskManager.OnMessageReceived = ProcessMessageAsync;
}
private async Task<A2AResponse> ProcessMessageAsync(
MessageSendParams messageSendParams,
CancellationToken cancellationToken)
{
var userMessage = messageSendParams.Message.Content.FirstOrDefault()?.Text ?? "";
// 执行工作流
var result = await _analysisWorkflow.ExecuteAsync(
userMessage,
cancellationToken);
return new A2AResponse
{
Message = new Message
{
Role = "assistant",
Content = [new TextContent { Text = result }]
}
};
}
}
dotnet new webapi -n YourNewService
cd YourNewService
dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.AI.Agents
dotnet add package ModelContextProtocol
dotnet add package A2A.Protocol
AgentFrameworkAspire.AppHost/Program.cs):var yourService = builder.AddProject<Projects.YourNewService>("yournewservice")
.WithEnvironment("OpenAI__Endpoint", openAiEndpoint)
.WithEnvironment("OpenAI__ApiKey", openAiApiKey)
.WithEnvironment("OpenAI__DeploymentName", openAiDeploymentName);
// 在 webfrontend 中引用
builder.AddProject<Projects.AgentFrameworkAspire_Web>("webfrontend")
// ... 其他配置
.WithReference(yourService)
.WaitFor(yourService);
Program.cs)http://localhost:<port>/<service>/mcp 查看可用工具# 测试单个微服务
cd Finance
dotnet test
# 测试整个解决方案
dotnet test
# 运行特定测试
dotnet test --filter "FullyQualifiedName~FinanceTests"
async/await 处理异步操作Description 和参数说明详细文档:查看 /docs 目录下的系列文档
入门手册-Multi-Agent-Microservices快速上手.md:适合初学者进阶手册-Multi-Agent-Microservices深度实战.md:适合进阶开发博客1-从业务痛点出发.md:理解项目背景博客2-三大协议深度解析.md:理解 MCP、A2A、Agent Framework博客3-Aspire实战演练.md:Aspire 编排实战博客4-从Demo到生产.md:生产环境部署参考文档:
源码参考:/component_source_code_reference 目录包含第三方库的源码,方便学习
欢迎贡献代码、文档或提出问题!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目采用 WTFPL License - 详见 LICENSE 文件。
简单来说:你可以对这个项目做任何你想做的事情。
如果这个项目对你有帮助,请给个 Star ⭐ 支持一下!
Made with ❤️ by MadLongTom
项目地址:https://github.com/MadLongTom/A2AMicroserviceSample
本项目遵循 MIT 许可证。
GitHub checked 16h ago - refresh overdue. Recently viewed repositories target hourly refresh.