Skip to content

fix(ai): 修复多轮对话上下文丢失、通用代理和标题生成问题#258

Merged
hrygo merged 13 commits into
mainfrom
feat/256-general-agent
Feb 17, 2026
Merged

fix(ai): 修复多轮对话上下文丢失、通用代理和标题生成问题#258
hrygo merged 13 commits into
mainfrom
feat/256-general-agent

Conversation

@hrygo

@hrygo hrygo commented Feb 17, 2026

Copy link
Copy Markdown
Owner

Summary

本 PR 解决了从日志分析中发现的三个 AI 相关问题,并优化了简单 LLM 任务的 Provider 配置:

  1. fix(ai): 多轮对话上下文丢失 - history_out=0 #255 多轮对话上下文丢失 - Block 完成时未设置 assistant_timestamp,导致消息排序错误
  2. feat(ai): 新增通用智能代理处理纯 LLM 任务 #256 通用智能代理缺失 - 新增 General Parrot 处理纯 LLM 任务(总结、翻译、改写等)
  3. fix(ai): 会话标题生成任务未触发 #257 会话标题生成未触发 - Orchestrator 模式缺少标题生成调用
  4. 简单 LLM 任务优化 - 标题生成、摘要、标签等轻量任务使用独立 SiliconFlow Provider,降低成本

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 服务工厂,支持回退到主 LLM
  • ai/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 ./... 通过
  • golangci-lint 通过
  • 手动测试:多轮对话上下文保持
  • 手动测试:"总结这些笔记" 路由到 general agent
  • 手动测试:新会话标题自动生成
  • 手动测试:简单任务使用 SiliconFlow Provider(检查日志)

hotplex-ai and others added 8 commits February 17, 2026 20:52
在 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>
@hrygo hrygo force-pushed the feat/256-general-agent branch from a271d51 to bec9dbd Compare February 17, 2026 14:09
hotplex-ai and others added 3 commits February 17, 2026 22:14
- 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>
@hrygo hrygo force-pushed the feat/256-general-agent branch from eb6a3c6 to bf7a446 Compare February 17, 2026 15:04
hotplex-ai and others added 2 commits February 17, 2026 23:08
- 新增 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>
@hrygo hrygo merged commit 5145989 into main Feb 17, 2026
9 checks passed
@hrygo hrygo deleted the feat/256-general-agent branch February 17, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants