pub struct TurnFactMiddleware { /* private fields */ }Expand description
Turn fact summary middleware — injects structured facts from the previous turn’s tool results into the next user message.
This prevents long-conversation attention drift: the LLM sees deterministic facts (tool call names) instead of relying on fuzzy memory of tool outputs buried 20+ turns ago.
§Design
- After each LLM turn with tool calls, collects which tools were called and stores them in a buffer.
- At the start of the next user message, prepends the buffered facts as a structured prefix, then clears the buffer.
- Facts are derived from tool names only (not parsing output text), keeping the logic simple and model-agnostic.
- The prefix language can be configured via
Language; defaults toLanguage::Zhfor backward compatibility.
Implementations§
Source§impl TurnFactMiddleware
impl TurnFactMiddleware
Sourcepub fn with_language(language: Language) -> Self
pub fn with_language(language: Language) -> Self
Create a new middleware with the specified language for the prefix text.
Trait Implementations§
Source§impl Default for TurnFactMiddleware
impl Default for TurnFactMiddleware
Source§impl Middleware for TurnFactMiddleware
impl Middleware for TurnFactMiddleware
fn on_user_message<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut UserMessageCtx,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_post_llm<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut PostLlmCtx,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_pre_llm<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut PreLlmCtx,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for TurnFactMiddleware
impl RefUnwindSafe for TurnFactMiddleware
impl Send for TurnFactMiddleware
impl Sync for TurnFactMiddleware
impl Unpin for TurnFactMiddleware
impl UnsafeUnpin for TurnFactMiddleware
impl UnwindSafe for TurnFactMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more