Skip to content

fix(ai): 修复 Orchestrator 模式多轮对话的 5 个关联 bug #249

@hrygo

Description

@hrygo

问题描述

Orchestrator 模式多轮对话存在 5 个关联 bug,导致用户体验问题:

  1. Block 未创建 - 第二轮对话无 block_id
  2. UserID 丢失 - user_id=0 导致 BM25 搜索失败
  3. 粘性路由失效 - 非确认词输入未复用粘性
  4. 标题重复生成 - 非首轮仍触发标题生成
  5. 上下文未复用 - 第二轮重新搜索,结果为 0

根本原因

问题 根因
Block 未创建 executeWithOrchestrator 绕过了 executeAgent 中的 block 创建逻辑
UserID 丢失 ParrotExpertRegistry 创建时硬编码 user_id=0,未从 context 获取
粘性路由失效 粘性检查仅对简短确认词(好/ok/是的)生效
标题重复生成 依赖问题1:未创建 block 导致 len(blocks)==1 判断错误
上下文未复用 executeWithOrchestrator 未构建历史,history=nil

修复方案

采用面向未来的架构:通过 context 隐式传递 userID 和 history,避免逐层修改接口签名。

架构设计

Request Context
├── user_id: int32      # 用户身份
├── history: []string   # 对话历史
└── conversation_id    # 会话标识

Handler Layer
├── executeWithOrchestrator
│   ├── BuildHistory() → context
│   └── CreateBlock() → block_id

Orchestrator Layer  
├── Process(ctx, input, callback)
│   └── 从 ctx 读取 history 和 userID
│
└── ExpertRegistry
    └── ExecuteExpert(ctx, ...)
        └── 从 ctx 提取 userID 创建 Expert

修改清单

  1. ai/context/provider.go - 扩展 ContextProvider 支持 userID/history
  2. handler.go - executeWithOrchestrator 从 context 读取并构建 history
  3. orchestrator.go - Process 从 ctx 读取 history
  4. expert_registry.go - 从 ctx 提取 userID 创建 Expert
  5. chat_router_metadata.go - 放宽粘性检查条件

依赖关系

  • 问题1(Block未创建) → 问题4(标题重复)
  • 问题1 → 问题5(上下文持久化)

相关文档

  • @docs/research/DEBUG_LESSONS.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions