//! 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). //! //! NOTE: This is a structural placeholder. Full implementation requires an LLM driver //! reference to generate titles asynchronously, which will be wired through the //! middleware context in a future iteration. For now it simply passes through. use async_trait::async_trait; use crate::middleware::{AgentMiddleware, MiddlewareDecision}; /// Middleware that auto-generates conversation titles after the first exchange. /// /// When fully implemented, this will: /// 1. Detect the first user-assistant exchange (via message count) /// 2. Call the LLM with a short prompt to generate a descriptive title /// 3. Update the session title via the middleware context /// /// For now, it serves as a registered placeholder in the middleware chain. pub struct TitleMiddleware { _reserved: (), } impl TitleMiddleware { pub fn new() -> Self { Self { _reserved: () } } } 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 } // All hooks default to Continue — placeholder until LLM driver is wired in. async fn before_completion(&self, _ctx: &mut crate::middleware::MiddlewareContext) -> zclaw_types::Result { Ok(MiddlewareDecision::Continue) } }