pub trait TurnMiddleware: Send + Sync {
// Provided methods
fn before_model_call(
&self,
_request: &mut ProviderRequest,
) -> Result<(), CoreError> { ... }
fn after_model_call(
&self,
_request: &ProviderRequest,
_response: &mut ModelTurn,
) -> Result<(), CoreError> { ... }
fn pre_tool_call(
&self,
_context: &ToolContext,
_call: &mut ToolCall,
) -> Result<(), CoreError> { ... }
fn post_tool_call(
&self,
_context: &ToolContext,
_result: &mut ToolResult,
) -> Result<(), CoreError> { ... }
fn on_run_finished(&self, _output: &mut RunOutput) -> Result<(), CoreError> { ... }
}Expand description
Middleware for a single agent turn.
Unlike the legacy Middleware trait, turn middleware receives mutable
access to requests, tool calls, tool results, and the final run output so
the chain can both veto and transform a turn.