//! Title generation middleware — auto-generates conversation titles after the first turn. //! //! Inspired by DeerFlow's TitleMiddleware: after the first user-assistant exchange, //! generates a short descriptive title using the LLM instead of defaulting to //! "新对话" or truncating the user's first message. //! //! Priority 180 — runs after compaction (100) and memory (150), before skill index (200). use async_trait::async_trait; use zclaw_types::Result; use crate::middleware::{AgentMiddleware, MiddlewareContext}; /// Middleware that auto-generates conversation titles after the first exchange. pub struct TitleMiddleware { /// Whether a title has been generated for the current session. titled: std::sync::atomic::AtomicBool, } impl TitleMiddleware { pub fn new() -> Self { Self { titled: std::sync::atomic::AtomicBool::new(false), } } } impl Default for TitleMiddleware { fn default() -> Self { Self::new() } } #[async_trait] impl AgentMiddleware for TitleMiddleware { fn name(&self) -> &str { "title" } fn priority(&self) -> i32 { 180 } }