pub trait PromptHook<M>:
Clone
+ WasmCompatSend
+ WasmCompatSyncwhere
M: CompletionModel,{
// Provided methods
fn on_completion_call(
&self,
_prompt: &Message,
_history: &[Message],
) -> impl Future<Output = HookAction> + WasmCompatSend { ... }
fn on_completion_response(
&self,
_prompt: &Message,
_response: &CompletionResponse<M::Response>,
) -> impl Future<Output = HookAction> + WasmCompatSend { ... }
fn on_tool_call(
&self,
_tool_name: &str,
_tool_call_id: Option<String>,
_internal_call_id: &str,
_args: &str,
) -> impl Future<Output = ToolCallHookAction> + WasmCompatSend { ... }
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> + WasmCompatSend { ... }
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 { ... }
}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> + WasmCompatSend
fn on_completion_call( &self, _prompt: &Message, _history: &[Message], ) -> impl Future<Output = HookAction> + WasmCompatSend
Called before the prompt is sent to the model
Sourcefn on_completion_response(
&self,
_prompt: &Message,
_response: &CompletionResponse<M::Response>,
) -> impl Future<Output = HookAction> + WasmCompatSend
fn on_completion_response( &self, _prompt: &Message, _response: &CompletionResponse<M::Response>, ) -> impl Future<Output = HookAction> + WasmCompatSend
Called after the prompt is sent to the model and a response is received.
Sourcefn on_tool_call(
&self,
_tool_name: &str,
_tool_call_id: Option<String>,
_internal_call_id: &str,
_args: &str,
) -> impl Future<Output = ToolCallHookAction> + WasmCompatSend
fn on_tool_call( &self, _tool_name: &str, _tool_call_id: Option<String>, _internal_call_id: &str, _args: &str, ) -> impl Future<Output = ToolCallHookAction> + WasmCompatSend
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
Sourcefn on_tool_result(
&self,
_tool_name: &str,
_tool_call_id: Option<String>,
_internal_call_id: &str,
_args: &str,
_result: &str,
) -> impl Future<Output = HookAction> + WasmCompatSend
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> + WasmCompatSend
Called after a tool is invoked (and a result has been returned).
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 (streaming responses only)
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 (streaming_responses_only).
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.
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.