专家市场 (Expert Marketplace) 设计
将专家能力作为独立服务,让不同行业应用可以注册、发现、调用、组合专家。
1. 概述
1.1 什么是专家市场?
┌─────────────────────────────────────────────────────────────────────┐
│ 专家市场 (Expert Marketplace) │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ 专家注册 │ │ 专家发现 │ │ 专家调用 │ │
│ │ Registry │ │ Discovery │ │ Invocation │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ 专家评价 │ │ 专家组合 │ │ 专家监控 │ │
│ │ Rating │ │ Composition │ │ Monitoring │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 教育应用 │ │ 客服应用 │ │ 游戏应用 │
│ 提供/使用专家 │ │ 提供/使用专家 │ │ 提供/使用专家 │
└─────────────┘ └─────────────┘ └─────────────┘
1.2 为什么要拆分?
| 问题 |
拆分后解决方案 |
| 专家能力分散在各应用 |
集中管理,统一发现 |
| 无法复用其他应用的专家 |
跨应用调用 |
| 专家质量难以评估 |
统一评价和排名 |
| 专家组合依赖硬编码 |
动态组合、智能路由 |
| 无法按需付费 |
计费和配额管理 |
2. 核心概念
2.1 专家 (Expert)
{
"id": "edu.math.algebra.solver",
"name": "代数方程求解器",
"version": "1.2.0",
"provider": "education-app",
"description": "求解线性和二次方程,提供详细步骤",
"category": "education.math",
"tags": ["数学", "代数", "方程"],
"interface": {
"input_schema": {
"type": "object",
"properties": {
"equation": {"type": "string"},
"show_steps": {"type": "boolean"}
}
},
"output_schema": {
"type": "object",
"properties": {
"solutions": {"type": "array"},
"steps": {"type": "array"}
}
}
},
"capabilities": ["solve", "explain", "verify"],
"supported_domains": ["algebra", "linear_equations", "quadratic"],
"metrics": {
"avg_latency_ms": 45,
"success_rate": 0.98,
"rating": 4.7,
"call_count": 12500
},
"pricing": {
"model": "per_call",
"price_per_1k": 0.5
}
}
2.2 专家类别
expert_categories/
├── core/ # MBE 核心专家(免费)
│ ├── surprise # 惊讶度计算
│ ├── routing # 智能路由
│ └── memory # 记忆管理
│
├── education/ # 教育专家
│ ├── math/ # 数学
│ │ ├── algebra
│ │ ├── geometry
│ │ └── calculus
│ ├── language/ # 语言
│ └── science/ # 科学
│
├── customer_service/ # 客服专家
│ ├── intent_recognition
│ ├── sentiment_analysis
│ └── response_generation
│
└── creative/ # 创意专家
├── writing
├── design
└── brainstorming
3. 架构设计
3.1 系统架构
┌────────────────────────────────────────────────────────────────────────────┐
│ Expert Marketplace │
├────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ API Gateway │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Auth │ │ Rate │ │ Billing │ │ Load │ │ │
│ │ │ │ │ Limit │ │ │ │ Balance │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────────────┼───────────────────────────────────┐ │
│ │ Core Services │ │
│ │ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐│┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Registry │ │ Discovery │││ Invoker │ │ Composer │ │ │
│ │ │ Service │ │ Service │││ Service │ │ Service │ │ │
│ │ └──────┬──────┘ └──────┬──────┘│└──────┬──────┘ └──────┬──────┘ │ │
│ │ │ │ │ │ │ │ │
│ │ ┌──────┴────────────────┴───────┴────────┴────────────────┴──────┐ │ │
│ │ │ Expert Runtime │ │ │
│ │ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │ │
│ │ │ │Expert 1│ │Expert 2│ │Expert 3│ │Expert N│ ... │ │ │
│ │ │ └────────┘ └────────┘ └────────┘ └────────┘ │ │ │
│ │ └────────────────────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Data Layer │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Expert DB │ │ Metrics DB │ │ Usage DB │ │ │
│ │ │ (Registry) │ │ (InfluxDB) │ │ (Billing) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────────┘
3.2 专家运行时
┌─────────────────────────────────────────────────────────────────┐
│ Expert Runtime │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 专家类型: │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ 1. 内置专家 (Built-in) │ │
│ │ - 运行在市场服务内 │ │
│ │ - 如: MBE 核心专家 │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ 2. 远程专家 (Remote) │ │
│ │ - 通过 HTTP/gRPC 调用 │ │
│ │ - 如: 教育应用提供的专家 │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ 3. 容器专家 (Container) │ │
│ │ - 以 Docker 容器运行 │ │
│ │ - 支持任意语言/环境 │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ 4. Serverless 专家 (FaaS) │ │
│ │ - AWS Lambda / Cloud Functions │ │
│ │ - 按需启动,弹性伸缩 │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
4. MCP 工具设计
4.1 专家市场工具
| 工具名 |
描述 |
expert_search |
搜索专家 |
expert_info |
获取专家详情 |
expert_invoke |
调用专家 |
expert_compose |
组合专家 |
expert_rate |
评价专家 |
expert_register |
注册专家 |
expert_recommend |
推荐专家 |
4.2 工具示例
// expert_search
{
"name": "expert_search",
"description": "搜索专家市场中的专家。可按类别、标签、能力、评分等条件筛选。",
"inputSchema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "搜索关键词"
},
"category": {
"type": "string",
"description": "专家类别(如 education.math)"
},
"capabilities": {
"type": "array",
"items": {"type": "string"},
"description": "所需能力"
},
"min_rating": {
"type": "number",
"description": "最低评分"
},
"max_latency_ms": {
"type": "integer",
"description": "最大延迟"
}
}
}
}
// expert_invoke
{
"name": "expert_invoke",
"description": "调用指定专家。支持单个调用或批量调用。",
"inputSchema": {
"type": "object",
"properties": {
"expert_id": {
"type": "string",
"description": "专家ID"
},
"input": {
"type": "object",
"description": "专家输入(符合专家 input_schema)"
},
"options": {
"type": "object",
"properties": {
"timeout_ms": {"type": "integer"},
"retry": {"type": "integer"},
"fallback_expert_id": {"type": "string"}
}
}
},
"required": ["expert_id", "input"]
}
}
// expert_compose
{
"name": "expert_compose",
"description": "组合多个专家形成工作流。支持顺序、并行、条件分支执行。",
"inputSchema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "组合名称"
},
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"expert_id": {"type": "string"},
"input_mapping": {"type": "object"},
"condition": {"type": "string"}
}
}
},
"execution_mode": {
"type": "string",
"enum": ["sequential", "parallel", "conditional"]
}
}
}
}
5. API 设计
5.1 REST API
/api/v1/experts:
GET: # 搜索专家
POST: # 注册专家
/api/v1/experts/{expert_id}:
GET: # 获取专家详情
PUT: # 更新专家
DELETE: # 下线专家
/api/v1/experts/{expert_id}/invoke:
POST: # 调用专家
/api/v1/experts/{expert_id}/ratings:
GET: # 获取评价
POST: # 提交评价
/api/v1/compositions:
GET: # 列出组合
POST: # 创建组合
/api/v1/compositions/{composition_id}/execute:
POST: # 执行组合
/api/v1/recommendations:
POST: # 获取专家推荐
5.2 响应示例
// GET /api/v1/experts?category=education.math&min_rating=4.0
{
"experts": [
{
"id": "edu.math.algebra.solver",
"name": "代数方程求解器",
"rating": 4.7,
"call_count": 12500,
"avg_latency_ms": 45
},
{
"id": "edu.math.geometry.proof",
"name": "几何证明助手",
"rating": 4.5,
"call_count": 8300,
"avg_latency_ms": 120
}
],
"total": 15,
"page": 1
}
// POST /api/v1/experts/edu.math.algebra.solver/invoke
{
"result": {
"solutions": ["x = 3", "x = -2"],
"steps": [
"原方程: x² - x - 6 = 0",
"因式分解: (x-3)(x+2) = 0",
"解得: x = 3 或 x = -2"
]
},
"metadata": {
"latency_ms": 42,
"expert_version": "1.2.0",
"cost": 0.0005
}
}
6. 专家组合示例
6.1 教育场景:自适应学习管道
{
"name": "adaptive_learning_pipeline",
"steps": [
{
"id": "analyze",
"expert_id": "mbe.core.surprise",
"input_mapping": {
"input": "$.user_input",
"history": "$.learning_history"
}
},
{
"id": "route",
"expert_id": "mbe.core.routing",
"input_mapping": {
"surprise_score": "$.analyze.surprise_score",
"user_level": "$.user_profile.level"
}
},
{
"id": "teach",
"expert_id": "$.route.selected_expert",
"condition": "route.confidence > 0.7"
},
{
"id": "record",
"expert_id": "mbe.core.memory",
"input_mapping": {
"user_id": "$.user_id",
"content": "$.teach.result"
}
}
],
"execution_mode": "sequential"
}
6.2 客服场景:智能回复组合
{
"name": "smart_reply_pipeline",
"steps": [
{
"id": "intent",
"expert_id": "cs.intent_recognition"
},
{
"id": "sentiment",
"expert_id": "cs.sentiment_analysis"
},
{
"id": "response",
"expert_id": "cs.response_generation",
"input_mapping": {
"intent": "$.intent.result",
"sentiment": "$.sentiment.result",
"priority": "$.sentiment.score < 0.3 ? 'high' : 'normal'"
}
}
],
"execution_mode": "parallel_then_sequential"
}
7. 与 MBE Core 的关系
┌─────────────────────────────────────────────────────────────────────────┐
│ MBE 生态系统 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ MBE Core (基础能力) │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Surprise │ │ Route │ │ Memory │ │ │
│ │ │ (惊讶度) │ │ (路由) │ │ (记忆) │ │ │
│ │ └────────────┘ └────────────┘ └────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ ▲ │
│ │ 内置 │
│ ┌─────────────────────────────────┼───────────────────────────────┐ │
│ │ Expert Marketplace (专家市场) │ │
│ │ │ │ │
│ │ ┌─────────────────────────────┴─────────────────────────────┐ │ │
│ │ │ Core Experts │ │ │
│ │ │ (MBE Core 作为内置专家自动注册) │ │ │
│ │ └───────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ Third-Party Experts │ │ │
│ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │
│ │ │ │ 教育专家 │ │ 客服专家 │ │ 游戏专家 │ ... │ │ │
│ │ │ └──────────┘ └──────────┘ └──────────┘ │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ 使用 │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ Industry Applications │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ 教育应用 │ │ 客服应用 │ │ 游戏应用 │ │ 其他... │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
8. 实施计划
| 阶段 |
任务 |
| Phase 1 |
实现专家注册和发现 API |
| Phase 2 |
实现专家调用和监控 |
| Phase 3 |
添加专家组合功能 |
| Phase 4 |
实现 MCP Server |
| Phase 5 |
添加计费和配额管理 |
| Phase 6 |
构建专家市场 UI |