基于.NET Aspire、Microsoft Agent Framework、A2A 和 MCP 协议构建的多智能体微服务系统。
在现代企业环境中,项目管理涉及多个专业领域的协作,包括技术评估、人力资源分配、财务预算控制、质量风险管理以及项目进度规划。传统的单体智能代理系统存在以下问题:
通用性和专业性的矛盾
维护和更新困难
不符合组织结构
基于康威定律,在这个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
项目经理的智能代理使用三阶段工作流程编排:
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 | 微服务框架 |
| 前端 | FHIR Server | 9.0 | 服务器渲染UI |
| 编排 | .NET Aspire | 最新 | 云原生应用程序编排 |
| AI框架 | Microsoft Agent Framework | 预览版 | 智能代理工作流引擎 |
| 协议 | A2A (Agent to Agent) | 最新 | 代理间通信协议(Google Cloud) |
| 协议 | MCP (Model Context Protocol) | 预览版 | Anthropic (模型上下文协议) |
| AI服务 | OpenAI API | GPT-4 | 大型语言模型 |
| 监控 | OpenTelemetry | 最新 | 可观察性 |
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端点(可选)<br/>- 空白:使用OpenAI官方API<br/>- 填写:使用第三方兼容API | ""<br/>"https://api.openai.com/v1"<br/>"https://your-proxy.com/v1" |
openai-apikey | API密钥(必需)<br/>从OpenAI或第三方服务获取 | "sk-..." |
openai-deployment | 模型名称(必需)<br/>选择要使用的模型 | "gpt-4o-mini"<br/>"gpt-4"<br/>"gpt-3.5-turbo" |
💡 提示 如果您使用Azure OpenAI,端点应类似于
https://your-resource.openai.azure.com/,部署是您在Azure中部署的模型名称。
dotnet restore
cd AgentFrameworkAspire.AppHost
dotnet run
Aspire仪表板将在浏览器中自动打开(默认 `http://localhost:15