Skip to main content

Handler

Trait Handler 

Source
pub trait Handler:
    Send
    + Sync
    + 'static {
    type Input: DeserializeOwned + JsonSchema + Send + 'static;
    type Output: Serialize + JsonSchema + Send + 'static;
    type Error: Into<Error> + Send + 'static;

    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        input: Self::Input,
        context: Context,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn display_name(&self) -> Option<&str> { ... }
    fn hints(&self) -> Hints { ... }
}
Expand description

Implemented by one typed tool inside an advanced capability.

Input values are deserialized after the model calls the tool. Output values are serialized as JSON without a String intermediary. Both types also provide schemas, allowing hosts and documentation to inspect the full protocol even though the current model protocol consumes only the input schema.

Required Associated Types§

Source

type Input: DeserializeOwned + JsonSchema + Send + 'static

Typed tool arguments.

Source

type Output: Serialize + JsonSchema + Send + 'static

Typed, JSON-serializable tool result.

Source

type Error: Into<Error> + Send + 'static

Structured handler error. Custom error enums can implement Into<Error>.

Required Methods§

Source

fn name(&self) -> &str

Stable model-facing tool name.

Source

fn description(&self) -> &str

Model-facing description of when and how to use the tool.

Source

fn execute<'life0, 'async_trait>( &'life0 self, input: Self::Input, context: Context, ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute one call.

Awaited work is cancelled by dropping this future when the turn stops. Use Context::cancellation for child tasks or resources that can outlive this future, and Context::progress for correlated status.

Provided Methods§

Source

fn display_name(&self) -> Option<&str>

Optional human-readable display name for clients.

Source

fn hints(&self) -> Hints

Semantic and host-owned tool metadata.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§