feat: auto-generate session titles after first exchange

After the first user→assistant exchange, Hermes now generates a short
descriptive session title via the auxiliary LLM (compression task config).
Title generation runs in a background thread so it never delays the
user-facing response.

Key behaviors:
- Fires only on the first 1-2 exchanges (checks user message count)
- Skips if a title already exists (user-set titles are never overwritten)
- Uses call_llm with compression task config (cheapest/fastest model)
- Truncates long messages to keep the title generation request small
- Cleans up LLM output: strips quotes, 'Title:' prefixes, enforces 80 char max
- Works in both CLI and gateway (Telegram/Discord/etc.)

Also updates /title (no args) to show the session ID alongside the title
in both CLI and gateway.

Implements #1426
This commit is contained in:
teknium1 2026-03-17 04:14:40 -07:00
parent 7049dba778
commit e5fc916814
4 changed files with 321 additions and 6 deletions

21
cli.py
View file

@ -3452,13 +3452,14 @@ class HermesCLI:
else:
_cprint(" Usage: /title <your session title>")
else:
# Show current title if no argument given
# Show current title and session ID if no argument given
if self._session_db:
_cprint(f" Session ID: {self.session_id}")
session = self._session_db.get_session(self.session_id)
if session and session.get("title"):
_cprint(f" Session title: {session['title']}")
_cprint(f" Title: {session['title']}")
elif self._pending_title:
_cprint(f" Session title (pending): {self._pending_title}")
_cprint(f" Title (pending): {self._pending_title}")
else:
_cprint(f" No title set. Usage: /title <your session title>")
else:
@ -5384,6 +5385,20 @@ class HermesCLI:
# Get the final response
response = result.get("final_response", "") if result else ""
# Auto-generate session title after first exchange (non-blocking)
if response and result and not result.get("failed") and not result.get("partial"):
try:
from agent.title_generator import maybe_auto_title
maybe_auto_title(
self._session_db,
self.session_id,
message,
response,
self.conversation_history,
)
except Exception:
pass
# Handle failed or partial results (e.g., non-retryable errors, rate limits,
# truncated output, invalid tool calls). Both "failed" and "partial" with
# an empty final_response mean the agent couldn't produce a usable answer.