pub struct TurnToolLimitMiddleware { /* private fields */ }Expand description
Middleware that enforces a hard limit on tool calls per turn.
Mounted on on_post_llm hook. When the turn’s tool call count reaches
max_tool_calls_per_turn, this middleware:
- Clears
ctx.tool_calls(discards pending tool calls) - Injects a
follow_up_messageforcing the LLM to summarize
This is a hard constraint — unlike prompt rules, the model cannot bypass it.
Implementations§
Source§impl TurnToolLimitMiddleware
impl TurnToolLimitMiddleware
pub fn new(max_tool_calls_per_turn: usize) -> Self
pub fn from_config(config: &SafetyConfig) -> Self
Trait Implementations§
Source§impl Middleware for TurnToolLimitMiddleware
impl Middleware for TurnToolLimitMiddleware
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_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_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 TurnToolLimitMiddleware
impl RefUnwindSafe for TurnToolLimitMiddleware
impl Send for TurnToolLimitMiddleware
impl Sync for TurnToolLimitMiddleware
impl Unpin for TurnToolLimitMiddleware
impl UnsafeUnpin for TurnToolLimitMiddleware
impl UnwindSafe for TurnToolLimitMiddleware
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