agentscope-ai / agentscope-ai/QwenPaw

[Feature]: Auto-refresh session title after auto-memory update

未关闭
#6,881 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
34.9k
派生
3.1k
平均合并
1 天 15 小时
30 天内合并 PR
225

描述

---
name: Feature Request
about: Suggest a new feature or enhancement
title: "[Feature]: Auto-refresh session title after auto-memory update"
labels: ["enhancement", "triage"]
assignees: []
---

## Summary

Automatically refresh the session (chat) title to reflect the current topic after every auto-memory consolidation. Today the title is generated once at session start; as the conversation evolves, the title becomes stale while the memory keeps updating. This feature keeps the title always in sync with what the conversation is actually about.

## Component(s) Affected

- [x] Core / Backend (app, agents, config, providers, utils, local_models)
- [ ] Console (frontend web UI)
- [ ] Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
- [ ] Skills
- [ ] CLI
- [ ] Documentation (website)
- [ ] Tests
- [ ] CI/CD
- [ ] Scripts / Deploy

## Problem / Motivation

Two symptoms users hit in long-running sessions:

1. **Stale titles** – The chat list shows "开启新旅程" (or whatever the opening topic was) long after the conversation moved on to a completely different subject. Users must manually rename, or the list becomes uninformative.
2. **Title generation is single-shot** – `title_generator.py` only runs when the chat is first created. There is no mechanism to refresh it later, even though auto-memory consolidation already re-evaluates what is worth remembering (the perfect moment to re-title).

Also related: #6813 reports that chat auto-title generation can fail on `agentscope 2.x ChatResponse` – even the initial title path is fragile; a refresh-on-memory path reuses the same generation logic, so improving it benefits both.

## Proposed Solution

Add an opt-in config flag and a refresh hook wired into the existing auto-memory pipeline:

**1. Config (agent.json)**
```json
"auto_title_config": {
"enabled": true,
"timeout_seconds": 300.0,
"refresh_on_auto_memory": false
}
```
`AutoTitleConfig` gains a `refresh_on_auto_memory: bool = False` field. Default off keeps current behavior; users opt in explicitly.

**2. Refresh hook in MemoryMiddleware**
After a successful auto-memory consolidation (`auto_memory()` call on the memory manager), invoke a `refresh_title_after_auto_memory(workspace)` callback:

- `chats/manager.py`: add `find_chat_by_session_id(session_id)` and `set_auto_title(chat_id, title)`
- `title_generator.py`: add `refresh_title_after_auto_memory` (~160 lines) that: triggers a background title generation for the current session, and **compare-and-set** the title only if the chat name is unchanged since generation started (so it never stomps a user's manual rename).
- Memory managers (`adbpg_memory_manager`, `base_memory_manager`, `reme_light_memory_manager`) expose `on_auto_memory` / `manager_ready` hooks so the middleware can subscribe without importing concrete classes.

**3. Wiring in workspace.py**
`Workspace` builds the callback in `make_auto_title_refresh_callback(ws)`; the middleware receives it via init args. When `refresh_on_auto_memory` is false the callback is `None` (zero overhead).

### Concurrency safety (important design point)
The refresh uses a compare-and-set on the chat name: it records the current name before running generation, then writes the new title only if the name still matches. This prevents a slow generation from overwriting a rename the user did mid-flight.

## Alternatives Considered

- **Refresh on every N turns** – adds timing complexity and regenerates titles even when memory didn't change; auto-memory consolidation is a natural, semantic trigger point.
- **Polling watcher** – wasteful and racy; hook-based is simpler.
- **Frontend-only rename** – doesn't scale to many sessions and keeps no audit trail.

## Additional Context

- The auto-memory pipeline already exists (`MemoryMiddleware._flush_auto_memory`, every N turns) – this feature only *adds* a post-consolidation step.
- Full reference implementation is available locally (8 files, ~+333/-15 lines, commit `f7257b6` on branch `feature/auto-title-sync`): `middlewares.py`, `title_generator.py`, `chats/manager.py`, `workspace/workspace.py`, `config/config.py`, and 3 memory managers. Happy to turn it into a PR after discussion.

## Willing to Contribute

- [x] I am willing to open a PR for this feature (after discussion).

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。