Reject reasoning text in session titles

This commit is contained in:
wuyang6
2026-06-16 15:10:41 +08:00
parent c8b5b0659d
commit 712bccf814
2 changed files with 72 additions and 1 deletions
+28 -1
View File
@@ -1725,6 +1725,9 @@ def create_app(state: AgentState) -> FastAPI:
):
continue
title = session_metadata.get('title')
title_source = session_metadata.get('title_source')
if isinstance(title, str) and title_source != 'manual':
title = _clean_session_title(title)
if not isinstance(title, str) or not title.strip():
title = None
preview = ''
@@ -3917,6 +3920,8 @@ def _read_session_title(directory: Path, session_id: str | None) -> str | None:
return None
title = metadata.get('title')
if isinstance(title, str) and title.strip():
if metadata.get('title_source') != 'manual':
return _clean_session_title(title)
return title.strip()
return None
@@ -4044,8 +4049,30 @@ def _generate_session_title(
def _clean_session_title(value: str) -> str | None:
title = ' '.join(value.strip().strip('"\'“”‘’`').split())
raw = value.strip()
if not raw:
return None
raw = re.sub(r'(?is)<analysis>.*?</analysis>', '', raw)
raw = re.sub(r'(?is)<think>.*?</think>', '', raw)
if re.search(r'(?i)<\s*(analysis|think)\b', raw):
return None
lines = [line.strip() for line in raw.replace('\r', '\n').split('\n')]
title = next((line for line in reversed(lines) if line), '')
title = re.sub(r'^\s*(?:[-*#>\d.、\s]+)', '', title)
title = re.sub(
r'^(?:会话标题|标题|短标题|生成标题|session title)\s*[:]\s*',
'',
title,
flags=re.IGNORECASE,
)
title = title.strip().strip('"\'“”‘’`*_ ')
title = re.sub(r'\*\*(.*?)\*\*', r'\1', title)
title = ' '.join(title.split())
title = title.rstrip('。.!?')
if re.search(r'(?i)\b(generating|generate|thinking|reasoning)\b', title):
return None
if '<' in title or '>' in title:
return None
if not title:
return None
return title[:24].rstrip()