pub trait StreamingPromptHook<M>:
Clone
+ Send
+ Syncwhere
M: CompletionModel,{
// Provided methods
fn on_completion_call(
&self,
_prompt: &Message,
_history: &[Message],
) -> impl Future<Output = HookAction> + Send { ... }
fn on_text_delta(
&self,
_text_delta: &str,
_aggregated_text: &str,
) -> impl Future<Output = HookAction> + Send { ... }
fn on_tool_call_delta(
&self,
_tool_call_id: &str,
_internal_call_id: &str,
_tool_name: Option<&str>,
_tool_call_delta: &str,
) -> impl Future<Output = HookAction> + Send { ... }
fn on_stream_completion_response_finish(
&self,
_prompt: &Message,
_response: &<M as CompletionModel>::StreamingResponse,
) -> impl Future<Output = HookAction> + Send { ... }
fn on_tool_call(
&self,
_tool_name: &str,
_tool_call_id: Option<String>,
_internal_call_id: &str,
_args: &str,
) -> impl Future<Output = ToolCallHookAction> + Send { ... }
fn on_tool_result(
&self,
_tool_name: &str,
_tool_call_id: Option<String>,
_internal_call_id: &str,
_args: &str,
_result: &str,
) -> impl Future<Output = HookAction> + Send { ... }
}Expand description
Trait for per-request hooks to observe tool call events.
Provided Methods§
Sourcefn on_completion_call(
&self,
_prompt: &Message,
_history: &[Message],
) -> impl Future<Output = HookAction> + Send
fn on_completion_call( &self, _prompt: &Message, _history: &[Message], ) -> impl Future<Output = HookAction> + Send
Called before the prompt is sent to the model
Sourcefn on_text_delta(
&self,
_text_delta: &str,
_aggregated_text: &str,
) -> impl Future<Output = HookAction> + Send
fn on_text_delta( &self, _text_delta: &str, _aggregated_text: &str, ) -> impl Future<Output = HookAction> + Send
Called when receiving a text delta
Sourcefn on_tool_call_delta(
&self,
_tool_call_id: &str,
_internal_call_id: &str,
_tool_name: Option<&str>,
_tool_call_delta: &str,
) -> impl Future<Output = HookAction> + Send
fn on_tool_call_delta( &self, _tool_call_id: &str, _internal_call_id: &str, _tool_name: Option<&str>, _tool_call_delta: &str, ) -> impl Future<Output = HookAction> + Send
Called when receiving a tool call delta.
tool_name is Some on the first delta for a tool call, None on subsequent deltas.
Sourcefn on_stream_completion_response_finish(
&self,
_prompt: &Message,
_response: &<M as CompletionModel>::StreamingResponse,
) -> impl Future<Output = HookAction> + Send
fn on_stream_completion_response_finish( &self, _prompt: &Message, _response: &<M as CompletionModel>::StreamingResponse, ) -> impl Future<Output = HookAction> + Send
Called after the model provider has finished streaming a text response from their completion API to the client.
Sourcefn on_tool_call(
&self,
_tool_name: &str,
_tool_call_id: Option<String>,
_internal_call_id: &str,
_args: &str,
) -> impl Future<Output = ToolCallHookAction> + Send
fn on_tool_call( &self, _tool_name: &str, _tool_call_id: Option<String>, _internal_call_id: &str, _args: &str, ) -> impl Future<Output = ToolCallHookAction> + Send
Called before a tool is invoked.
§Returns
ToolCallHookAction::Continue- Allow tool execution to proceedToolCallHookAction::Skip { reason }- Reject tool execution;reasonwill be returned to the LLM as the tool result
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.