MBE 核心能力与行业应用拆分方案

将 MBE 打造成通用的行为引擎平台,行业应用(教育、客服、游戏等)通过 API 调用核心能力

1. 架构总览

┌─────────────────────────────────────────────────────────────────────────────┐
│                           行业应用层 (Industry Applications)                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   ┌─────────────┐   ┌─────────────┐   ┌─────────────┐   ┌─────────────┐    │
│   │   教育系统   │   │   客服系统   │   │   游戏 AI   │   │  健康管理   │    │
│   │  Education  │   │  Customer   │   │    Game     │   │   Health    │    │
│   │             │   │   Service   │   │             │   │             │    │
│   └──────┬──────┘   └──────┬──────┘   └──────┬──────┘   └──────┬──────┘    │
│          │                 │                 │                 │            │
│          └─────────────────┼─────────────────┼─────────────────┘            │
│                            │                 │                              │
│                            ▼                 ▼                              │
├─────────────────────────────────────────────────────────────────────────────┤
│                              MBE API Gateway                                 │
│                        (统一 API 网关 + 认证鉴权)                            │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│                        MBE 核心能力层 (Core Capabilities)                    │
│                                                                              │
│   ┌──────────────────────────────────────────────────────────────────────┐  │
│   │                        MOE 专家系统 (Mixture of Experts)              │  │
│   │  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐             │  │
│   │  │ 智能路由 │  │ 专家调度 │  │ 结果合成 │  │ 负载均衡 │             │  │
│   │  └──────────┘  └──────────┘  └──────────┘  └──────────┘             │  │
│   └──────────────────────────────────────────────────────────────────────┘  │
│                                                                              │
│   ┌────────────────┐  ┌────────────────┐  ┌────────────────┐               │
│   │   HOPE 学习    │  │    TITANS      │  │     MIRAS      │               │
│   │  (惊讶度驱动)  │  │  (记忆系统)    │  │  (检索系统)    │               │
│   │                │  │                │  │                │               │
│   │ • 快速适应     │  │ • 短期记忆     │  │ • 局部检索     │               │
│   │ • 稳定记忆     │  │ • 长期记忆     │  │ • 上下文检索   │               │
│   │ • 模式识别     │  │ • 工作记忆     │  │ • 全局检索     │               │
│   │ • 遗忘控制     │  │                │  │                │               │
│   └────────────────┘  └────────────────┘  └────────────────┘               │
│                                                                              │
│   ┌────────────────┐  ┌────────────────┐  ┌────────────────┐               │
│   │  嵌套学习组件   │  │   LLM 抽象层   │  │   存储抽象层   │               │
│   │                │  │                │  │                │               │
│   │ • 梯度控制     │  │ • 多模型支持   │  │ • Redis        │               │
│   │ • 记忆压缩     │  │ • Token 计费   │  │ • PostgreSQL   │               │
│   │ • 专家均衡     │  │ • 重试/熔断    │  │ • 向量数据库   │               │
│   │ • 惊讶路由     │  │                │  │                │               │
│   └────────────────┘  └────────────────┘  └────────────────┘               │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

2. 核心能力清单

2.1 MBE 核心能力 (领域无关)

能力模块 API 端点 功能描述 适用场景
惊讶度计算 /api/mbe/surprise 计算输入的"惊讶度"(新颖程度) 学习追踪、异常检测、推荐
智能路由 /api/mbe/route 根据输入特征选择最佳专家 任务分发、负载均衡
记忆读写 /api/mbe/memory 存储和检索长短期记忆 上下文管理、个性化
模式识别 /api/mbe/pattern 从历史数据中发现模式 行为预测、趋势分析
遗忘控制 /api/mbe/forget 选择性遗忘不重要信息 隐私保护、资源优化
专家调度 /api/mbe/expert 调用和组合多个专家 复杂任务处理
嵌入生成 /api/mbe/embed 生成语义向量 相似度搜索、聚类
LLM 调用 /api/mbe/llm 统一的 LLM 调用接口 文本生成、理解

2.2 行业应用能力 (领域相关)

行业 应用模块 调用的核心能力
教育 学习追踪 惊讶度 + 记忆
自适应教学 智能路由 + LLM
间隔复习 遗忘控制 + 记忆
能力评估 模式识别
客服 意图识别 智能路由 + 嵌入
对话管理 记忆 + LLM
情绪检测 惊讶度 + 模式识别
游戏 NPC 行为 专家调度 + 记忆
难度调节 惊讶度 + 模式识别
玩家建模 记忆 + 模式识别

3. 项目结构拆分

3.1 目录结构

mises-behavior-engine/
│
├── mbe-core/                    # 🔷 MBE 核心(独立部署)
│   ├── src/
│   │   ├── moe/                 # MOE 专家系统
│   │   │   ├── base.py          # 基础类
│   │   │   ├── router.py        # 路由器
│   │   │   ├── experts.py       # 专家定义
│   │   │   └── combiner.py      # 结果合成
│   │   │
│   │   ├── core/                # 核心模块
│   │   │   ├── hope_moe.py      # HOPE 学习
│   │   │   ├── titans.py        # 记忆系统
│   │   │   └── miras.py         # 检索系统
│   │   │
│   │   ├── nested/              # 嵌套学习组件
│   │   │   ├── gradient.py      # 梯度控制
│   │   │   ├── memory.py        # 记忆压缩
│   │   │   ├── balancer.py      # 专家均衡
│   │   │   └── surprise.py      # 惊讶路由
│   │   │
│   │   ├── llm/                 # LLM 抽象层
│   │   ├── storage/             # 存储抽象层
│   │   └── api/                 # 核心 API
│   │       ├── surprise.py
│   │       ├── route.py
│   │       ├── memory.py
│   │       └── expert.py
│   │
│   ├── Dockerfile
│   ├── requirements.txt
│   └── README.md
│
├── mbe-apps/                    # 🔶 行业应用(可独立部署)
│   │
│   ├── education/               # 教育应用
│   │   ├── src/
│   │   │   ├── student_tracker.py
│   │   │   ├── adaptive_tutor.py
│   │   │   ├── review_scheduler.py
│   │   │   ├── course_manager.py
│   │   │   ├── social/          # 社交功能
│   │   │   ├── fun/             # 趣味功能
│   │   │   └── creative/        # 创造性思维
│   │   ├── api/                 # 教育 API
│   │   ├── admin-ui/            # 教育管理界面
│   │   ├── Dockerfile
│   │   └── requirements.txt
│   │
│   ├── customer-service/        # 客服应用
│   │   ├── src/
│   │   │   ├── intent_router.py
│   │   │   ├── dialog_manager.py
│   │   │   └── sentiment.py
│   │   └── ...
│   │
│   └── game-ai/                 # 游戏 AI 应用
│       ├── src/
│       │   ├── npc_behavior.py
│       │   ├── difficulty.py
│       │   └── player_model.py
│       └── ...
│
├── mbe-gateway/                 # 🔵 API 网关
│   ├── src/
│   │   ├── auth.py              # 认证鉴权
│   │   ├── rate_limit.py        # 限流
│   │   ├── routing.py           # 请求路由
│   │   └── billing.py           # 计费
│   └── ...
│
└── mbe-sdk/                     # 🟢 客户端 SDK
    ├── python/
    │   └── mbe_client/
    ├── typescript/
    │   └── mbe-client/
    └── go/
        └── mbe-client/

4. 核心 API 设计

4.1 惊讶度计算 API

# POST /api/mbe/surprise
{
    "input": "递归是函数调用自身的技术",
    "context": {
        "user_id": "user_001",
        "domain": "programming",
        "history": ["变量", "循环", "函数"]  # 已学过的概念
    },
    "config": {
        "threshold": 0.5,
        "use_memory": true
    }
}

# Response
{
    "surprise_score": 0.85,       # 惊讶度 (0-1)
    "is_novel": true,             # 是否是新概念
    "related_concepts": ["函数", "栈"],
    "learning_mode": "fast_adaptation",  # 建议的学习模式
    "metadata": {
        "computation_time_ms": 45,
        "model_version": "1.0.0"
    }
}

4.2 智能路由 API

# POST /api/mbe/route
{
    "input": "请解释什么是递归",
    "task_type": "explanation",
    "user_profile": {
        "level": "beginner",
        "style": "visual"
    },
    "available_experts": ["detailed", "example", "analogy", "practice"]
}

# Response
{
    "selected_experts": [
        {"id": "analogy", "weight": 0.6, "reason": "适合初学者"},
        {"id": "example", "weight": 0.4, "reason": "视觉学习者"}
    ],
    "routing_confidence": 0.92,
    "metadata": {...}
}

4.3 记忆操作 API

# POST /api/mbe/memory/write
{
    "user_id": "user_001",
    "memory_type": "long_term",  # short_term, working, long_term
    "content": {
        "concept": "递归",
        "understanding_level": 0.3,
        "last_accessed": "2024-01-15T10:00:00Z"
    },
    "importance": 0.8,
    "ttl": null  # 永久存储
}

# POST /api/mbe/memory/read
{
    "user_id": "user_001",
    "query": "与递归相关的概念",
    "memory_types": ["long_term"],
    "top_k": 5
}

# Response
{
    "memories": [
        {"concept": "函数", "relevance": 0.9, ...},
        {"concept": "栈", "relevance": 0.8, ...}
    ]
}

4.4 专家调度 API

# POST /api/mbe/expert/invoke
{
    "expert_id": "hope_learning",
    "method": "process",
    "params": {
        "input_data": {...},
        "surprise_threshold": 0.5
    }
}

# POST /api/mbe/expert/combine
{
    "experts": [
        {"id": "fast_adaptation", "weight": 0.6},
        {"id": "stable_memory", "weight": 0.4}
    ],
    "inputs": {...},
    "combine_strategy": "weighted_average"
}

5. 教育应用调用示例

5.1 学习追踪 (调用惊讶度 API)

# mbe-apps/education/src/student_tracker.py

from mbe_sdk import MBEClient

class StudentTracker:
    def __init__(self, mbe_client: MBEClient):
        self.mbe = mbe_client
    
    async def track_learning(
        self,
        student_id: str,
        knowledge_point: str,
        content: str,
    ):
        # 1. 调用 MBE 核心:计算惊讶度
        surprise_result = await self.mbe.surprise.calculate(
            input=content,
            context={
                "user_id": student_id,
                "domain": "education",
                "history": await self._get_learning_history(student_id)
            }
        )
        
        # 2. 调用 MBE 核心:写入记忆
        await self.mbe.memory.write(
            user_id=student_id,
            memory_type="long_term",
            content={
                "knowledge_point": knowledge_point,
                "surprise_score": surprise_result.surprise_score,
                "learned_at": datetime.now().isoformat()
            }
        )
        
        # 3. 教育业务逻辑
        return self._determine_learning_mode(surprise_result)

5.2 自适应教学 (调用路由 + LLM API)

# mbe-apps/education/src/adaptive_tutor.py

class AdaptiveTutor:
    async def teach(
        self,
        student: Student,
        knowledge_point: KnowledgePoint,
        surprise_score: float,
    ):
        # 1. 调用 MBE 核心:选择教学专家
        routing_result = await self.mbe.route(
            input=knowledge_point.description,
            task_type="teaching",
            user_profile={
                "level": student.level,
                "style": student.learning_style,
                "surprise": surprise_score
            },
            available_experts=[
                "detailed_explanation",
                "example_illustration", 
                "pattern_summary",
                "practice_questions"
            ]
        )
        
        # 2. 调用 MBE 核心:LLM 生成内容
        content = await self.mbe.llm.generate(
            prompt=self._build_teaching_prompt(
                knowledge_point,
                routing_result.selected_experts
            ),
            model="deepseek-chat",
            temperature=0.7
        )
        
        # 3. 教育业务逻辑:添加游戏化元素
        return self._enhance_with_gamification(content, student)

6. 部署架构

6.1 微服务部署

# docker-compose.yml
version: '3.8'

services:
  # MBE 核心服务
  mbe-core:
    image: mbe-core:latest
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=postgres://...
      - REDIS_URL=redis://...
    deploy:
      replicas: 3
      
  # API 网关
  mbe-gateway:
    image: mbe-gateway:latest
    ports:
      - "80:80"
    depends_on:
      - mbe-core
      
  # 教育应用
  mbe-education:
    image: mbe-education:latest
    ports:
      - "8001:8001"
    environment:
      - MBE_API_URL=http://mbe-gateway
      - MBE_API_KEY=xxx
    depends_on:
      - mbe-gateway
      
  # 客服应用
  mbe-customer-service:
    image: mbe-customer-service:latest
    ports:
      - "8002:8002"
    environment:
      - MBE_API_URL=http://mbe-gateway
      - MBE_API_KEY=xxx

6.2 调用流程

┌────────────────┐     ┌────────────────┐     ┌────────────────┐
│   教育前端      │     │  教育后端       │     │   MBE Core     │
│   (React)      │     │  (FastAPI)     │     │   (FastAPI)    │
└───────┬────────┘     └───────┬────────┘     └───────┬────────┘
        │                      │                      │
        │  1. 开始学习          │                      │
        │─────────────────────>│                      │
        │                      │                      │
        │                      │  2. 计算惊讶度        │
        │                      │─────────────────────>│
        │                      │                      │
        │                      │  3. {surprise: 0.85} │
        │                      │<─────────────────────│
        │                      │                      │
        │                      │  4. 选择教学专家      │
        │                      │─────────────────────>│
        │                      │                      │
        │                      │  5. {experts: [...]} │
        │                      │<─────────────────────│
        │                      │                      │
        │  6. 教学内容 + 游戏化 │                      │
        │<─────────────────────│                      │
        │                      │                      │

7. 计费模型

7.1 API 调用计费

API 计费单位 价格
/surprise 每 1000 次 ¥10
/route 每 1000 次 ¥5
/memory/write 每 MB ¥0.5
/memory/read 每 1000 次 ¥2
/llm/* 按 token 透传

7.2 订阅套餐

套餐 价格 包含
免费版 ¥0/月 10K 次调用
基础版 ¥99/月 100K 次调用
专业版 ¥499/月 1M 次调用 + 优先支持
企业版 定制 私有部署 + SLA

8. 迁移计划

Phase 1: 抽象接口 (1周)

  • 定义核心能力接口
  • 创建 MBE SDK

Phase 2: 拆分代码 (2周)

  • 将核心代码移到 mbe-core/
  • 将教育代码移到 mbe-apps/education/
  • 教育模块改用 SDK 调用

Phase 3: 独立部署 (1周)

  • 核心服务容器化
  • 配置 API 网关
  • 测试端到端流程

Phase 4: 扩展应用 (持续)

  • 开发客服应用
  • 开发游戏 AI 应用
  • 完善 SDK 文档

9. 收益

维度 收益
可复用性 核心能力可被多个行业应用使用
可扩展性 新行业应用只需调用 API
可维护性 核心和应用独立迭代
可商业化 核心能力可独立售卖/订阅
团队分工 核心团队 vs 行业团队分开