Skip to content

fix(ai): 多轮对话上下文丢失 - history_out=0 #255

@hrygo

Description

@hrygo

问题描述

在多轮对话中,第二轮对话无法获取第一轮的历史上下文。

现象

20:36:58.474 Service.BuildHistory session_id=conv_185 messages_in=2 history_out=0
  • 第一轮 Block 416: assistant_content_len=2854
  • 第二轮 Block 417: messages_count=1 (仅当前用户输入)

日志证据

time=2026-02-17T20:36:58.474 level=DEBUG msg=context.GetRecentMessages conversation_id=185 blocks_count=1 messages_count=2 limit=10
time=2026-02-17T20:36:58.474 level=DEBUG msg=context.GetRecentMessages.block index=0 block_id=416 round=0 has_assistant_content=true assistant_content_len=2854 user_inputs_count=1
time=2026-02-17T20:36:58.474 level=DEBUG msg=Service.BuildHistory session_id=conv_185 messages_in=2 history_out=0

影响

  • 多轮对话无法保持上下文连贯性
  • 用户无法基于前文进行追问或总结

可能原因

  1. BuildHistory 函数过滤逻辑问题
  2. Token 限制导致历史被截断
  3. Block 到 Message 的转换逻辑错误

相关文件

  • ai/context/ - 上下文构建
  • ai/orchestrator/ - 任务编排

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions