fix(ai): 修复多轮对话上下文丢失、通用代理和标题生成问题#258
Merged
Merged
Conversation
在 Orchestrator 模式的 Block 完成后添加 maybeGenerateConversationTitle 调用, 与非 Orchestrator 模式保持一致。 修复:Block 完成后检查是否为首个成功 Block,若是则异步生成会话标题。 Resolves #257
根因: - Block 完成时未设置 assistant_timestamp 字段 - 导致排序后 assistant 消息时间戳为 0,排在 user 消息之前 - BuildHistory 无法处理 [assistant, user] 顺序,返回空数组 修复: 1. UpdateAIBlock 结构体添加 AssistantTs 字段 2. postgres UpdateAIBlock 函数处理 assistant_timestamp 更新 3. BlockManager.UpdateBlockStatus 设置 AssistantTs Resolves #255
添加 General Parrot 配置,处理总结、翻译、改写、问答等不需要特定工具的任务。 修改: - config/parrots/general.yaml: General Parrot 配置文件 - strategy: direct(直接执行,无工具) - 路由关键词:总结、翻译、改写、解释等 - ai/agents/chat_router.go: - 添加 RouteTypeGeneral 常量 - 添加 general_task 关键词映射 - ai/agents/orchestrator/expert_registry.go: - 添加 general -> general_task 映射 - 添加 general 默认描述 - ai/routing/interface.go: - 添加 IntentGeneralTask 常量 Resolves #256
为标题生成、Memo摘要、标签生成等简单 LLM 任务创建专用的 IntentLLMService: - 新增 ai/simple_task_llm.go:简单任务 LLM 服务工厂,带回退逻辑 - 修改 ai/config.go:IntentClassifierConfig 添加 Provider 字段 - 修改 ai_service.go:添加 IntentLLMService 字段,enrichment 使用专用服务 - 修改 v1.go:创建并注入 IntentLLMService 配置说明: - 使用 DIVINESENSE_AI_INTENT_* 配置(默认 siliconflow) - 未配置 AIIntentAPIKey 时回退到主 LLM - 简单任务参数:MaxTokens=1024, Temperature=0.3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
审查发现的问题修复: - routeTypeToExpertName: 添加 RouteTypeGeneral -> "general" 映射 - mapIntentToRouteType: 添加 AgentTypeGeneral -> RouteTypeGeneral 映射 - ExtractIntent: 添加 RouteTypeGeneral -> "general_task" 映射 - interface.go: 添加 AgentTypeGeneral 常量 这些修复确保 general agent 可以正确路由和 sticky routing。 Refs #256
修复代码审查发现的 3 个问题: 1. simple_task_llm.go: 添加 Profile nil 检查防止 panic 2. simple_task_llm.go: 添加 Timeout 配置 (30秒) 3. config.go: 添加 IntentClassifier 配置验证 同时更新文档说明返回值可能为 nil。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- rule_matcher: general expert 映射到 IntentGeneralTask - general.yaml: 扩展 patterns 匹配规则,priority 设为 8 - memo.yaml: sticky routing 关键词聚焦 follow-up 场景 - schedule.yaml: excludes 排除通用 LLM 任务关键词 - chat_router.go: intentKeywords 与配置文件保持一致 Resolves #260 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
priority: general=15, memo=10, schedule=10 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a271d51 to
bec9dbd
Compare
- intent_registry.go: RegisterDefaults() 添加 IntentGeneralTask 注册 - intent_registry.go: actionToIntent() 添加 AgentTypeGeneral 处理 - chat_router.go: general_task 关键词与 general.yaml 对齐 - simple_task_llm.go: Intent 创建失败日志添加 model 字段 Resolves #258
- 添加服务启动时异步预热 Router service (语义索引) - 添加 Orchestrator decompose_start/end 事件解决 Block 页面卡顿 - 移除 Chat router 日志中误导性的 model 字段 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
前端修改: - 添加 DECOMPOSE_START/END 事件类型和处理逻辑 - 添加 scheduleTitleRefresh 方法延迟获取后端生成的标题 - Block 0 完成后 3 秒刷新会话列表获取自动生成的标题 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
eb6a3c6 to
bf7a446
Compare
- 新增 agent-mention-feature-research.md 调研报告 - CLAUDE.md 添加 GitHub 仓库配置和 gh 命令注意事项 - 更新 research README 索引 Refs #259 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 将 git add 移到 git root 目录执行,确保路径正确匹配 - 添加 xargs -r 避免空输入报错 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
本 PR 解决了从日志分析中发现的三个 AI 相关问题,并优化了简单 LLM 任务的 Provider 配置:
assistant_timestamp,导致消息排序错误Resolves #255
Resolves #256
Resolves #257
Changes
#255: 多轮对话上下文丢失
store/ai_block.go: 添加AssistantTs *int64字段store/db/postgres/ai_block.go: 处理assistant_timestamp更新server/router/api/v1/ai/block_manager.go: 设置AssistantTs#256: 通用智能代理
config/parrots/general.yaml: 新建 General Parrot 配置 (strategy: direct)ai/agents/chat_router.go: 添加RouteTypeGeneral+general_task关键词ai/agents/orchestrator/expert_registry.go: 添加 general 映射和描述ai/routing/interface.go: 添加IntentGeneralTask#257: 会话标题生成
server/router/api/v1/ai/handler.go: Orchestrator 模式 Block 完成后调用maybeGenerateConversationTitle简单 LLM 任务优化
ai/simple_task_llm.go: 新建简单任务 LLM 服务工厂,支持回退到主 LLMai/config.go: 添加 IntentClassifier 验证逻辑server/router/api/v1/ai_service.go: 添加IntentLLMService字段server/router/api/v1/v1.go: 创建并注入 IntentLLMService影响范围:Memo 标题/摘要/标签生成、会话标题生成等轻量任务
Test plan
go build ./...通过go test ./...通过