Skip to content

feat: auto-generate concise thread titles on first turn - #579

Open
angri450 wants to merge 1 commit into
TencentCloud:developfrom
angri450:feature/auto-thread-titles
Open

feat: auto-generate concise thread titles on first turn#579
angri450 wants to merge 1 commit into
TencentCloud:developfrom
angri450:feature/auto-thread-titles

Conversation

@angri450

@angri450 angri450 commented Sep 6, 2026

Copy link
Copy Markdown

背景

Octop 当前用首条用户消息全文当线程标题(set_title_if_null(thread_id, msg.text))——Recents 里显示一长段,难以辨认。吸收 openresearch-cli 的 one-shot 标题分级设计(title.rs:cheap 模型 30s 超时、≤6 词、sanitize),改为模型生成简洁标题。

改动

  • octop/infra/agents/title_gen.py(新):httpx 直发首个可用 provider(OpenAI 兼容 chat.completions,30s 超时、60 max_tokens、temperature 0.3)+ _sanitize_title(引号包裹/尾句号剥两次/80 字符上限,照 openresearch title.rs)+ _fallback_title(首行截断)
  • processor.py _touch_thread_after_turn:首轮(标题为 NULL)异步 fire-and-forget 生成——不阻塞 turn;失败/超时/上游限流回落截断首行;set_title_if_null 幂等,未完成下次 turn 重试
  • 调用点传 agent_id(生成用首个可用 provider 模型,标题不绑 agent)
  • 测试:tests/unit/agents/test_title_gen.py(sanitize/fallback/prompt 6 用例)
  • CHANGELOG [Unreleased] 记录

设计要点

  • 异步不阻塞:标题生成发生在 turn 完成后(create_task),用户回复不受模型调用延迟影响
  • 回落兜底:模型 429/超时/解析失败 → None → 截断首行(比现状全文标题更好);标题为空不炸主流程
  • 幂等重试:进程退出时 task 未完成 → title 仍 NULL → 下次 turn 再生成

测试计划

  • 本地等价断言全过(sanitize 6 用例 + 真实模型调用 429 回落验证——上游限流环境下回落路径实测)
  • ruff check/format 全过
  • 完整 make all 待 CI

Replace the full-first-message-as-title behavior with an async one-shot
model call (<=6 words, 30s budget, no tools) that never blocks the turn.
Fall back to a truncated first line on failure, timeout, or upstream rate
limit. set_title_if_null is idempotent, so a title that did not finish is
retried on the next turn.

- title_gen.py: httpx call to the first usable provider model + sanitizer
  (wrapping quotes / trailing periods / 80-char cap, mirrors openresearch)
- processor.py: _touch_thread_after_turn spawns the async generation with
  the turn's agent_id; call sites pass agent_id
- tests: sanitizer/fallback/prompt unit tests
- CHANGELOG: [Unreleased] entry
Copilot AI lite review requested due to automatic review settings September 6, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

当前实现存在会把“仅空白首条消息”写成空字符串标题并阻断后续重试的风险,且标题长度上限与实际落库裁剪规则不一致需要对齐。

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

该 PR 旨在改进 Recents/线程列表的可读性:不再把“首条用户消息全文”直接落库为线程标题,而是在首轮 turn 结束后异步调用一个廉价 chat 模型生成 ≤6 词的简洁标题,并在失败/超时时回落到“首行截断”,从而避免长标题污染侧边栏显示。

Changes:

  • 新增 title_gen.py:通过 httpx 直连 OpenAI 兼容 chat.completions 生成标题,并提供 sanitize / fallback 逻辑。
  • GlobalProcessor._touch_thread_after_turn 中改为首轮异步 fire-and-forget 生成标题,不阻塞 turn 主流程。
  • 新增单测覆盖 sanitize/fallback/prompt 关键行为,并在 CHANGELOG 记录该特性。
File summaries
File Description
tests/unit/agents/test_title_gen.py 为标题 sanitize / fallback / prompt 提供单元测试用例
src/octop/infra/gateway/process/processor.py 首轮 turn 后异步触发标题生成并回落,避免阻塞响应
src/octop/infra/agents/title_gen.py 实现 one-shot 标题生成、清洗与回退逻辑
CHANGELOG.md 在 Unreleased 中记录自动生成简洁会话标题的新增特性
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 1182 to +1185
self._thread_registry.touch_last_active(thread_id)
if title_source:
self._thread_registry.set_title_if_null(thread_id, title_source)
if not title_source:
return
try:
Comment on lines +23 to +29
#: Input cap fed to the model (a title only needs the opening intent).
_TITLE_INPUT_CAP = 2000
#: Longest title we store (sidebar truncates past this anyway).
_TITLE_MAX_CHARS = 80
#: One-shot budget — generous for a cold provider, short enough that a wedged
#: call does not linger (the fallback title is already acceptable).
_TITLE_TIMEOUT_SECONDS = 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants