Skip to main content

HumanInTheLoopClassifier

Trait HumanInTheLoopClassifier 

Source
pub trait HumanInTheLoopClassifier:
    Send
    + Sync
    + 'static {
    // Required method
    fn classify<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 BeforeToolCallEvent,
    ) -> Pin<Box<dyn Future<Output = Result<ClassifierResult, BoxError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Decides whether a tool call needs human approval (HumanInTheLoopClassifier).

Implemented for async closures over the event:

use strands::hooks::BeforeToolCallEvent;
use strands::vended_interventions::hitl::{ClassifierResult, HumanInTheLoopClassifier};

let classifier = |event: &BeforeToolCallEvent| {
    let deploy = event.tool_use().name == "deploy";
    async move { Ok(ClassifierResult::new(deploy).with_reason("deployment requires approval")) }
};
fn takes(_: impl HumanInTheLoopClassifier) {}
takes(classifier);

Required Methods§

Source

fn classify<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 BeforeToolCallEvent, ) -> Pin<Box<dyn Future<Output = Result<ClassifierResult, BoxError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Classifies the tool call.

§Errors

Any error; the handler then requires approval.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, Fut> HumanInTheLoopClassifier for F
where F: Fn(&BeforeToolCallEvent) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<ClassifierResult, BoxError>> + Send + 'static,