Skip to main content

ToolBuilder

Struct ToolBuilder 

Source
pub struct ToolBuilder<I> { /* private fields */ }
Expand description

Builds a Tool. I is the input type handed to the execute closure.

Implementations§

Source§

impl<I> ToolBuilder<I>

Source

pub fn description(self, description: impl Into<String>) -> Self

Fixed description.

Source

pub fn description_fn<F, Fut>(self, function: F) -> Self
where F: Fn(DescriptionContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = String> + Send + 'static,

Description computed per call.

Source

pub fn title(self, title: impl Into<String>) -> Self

Title.

Source

pub fn input_schema(self, schema: Schema<JsonValue>) -> Self

Replaces the input schema (keeps the closure input type).

Source

pub fn output_schema(self, schema: Schema<JsonValue>) -> Self

Output schema.

Source

pub fn context_schema(self, schema: Schema<JsonValue>) -> Self

Context schema.

Source

pub fn needs_approval(self, needs_approval: NeedsApproval) -> Self

Approval declaration.

Source

pub fn needs_approval_if<F, Fut>(self, function: F) -> Self
where F: Fn(JsonValue, ToolContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = bool> + Send + 'static,

Approval decided per call from the validated input.

Source

pub fn strict(self, strict: bool) -> Self

Strict-mode request.

Source

pub fn input_example(self, example: JsonObject) -> Self

Adds an example input.

Source

pub fn input_examples( self, examples: impl IntoIterator<Item = JsonObject>, ) -> Self

Adds example inputs.

Source

pub fn metadata(self, metadata: JsonObject) -> Self

Metadata propagated to tool calls.

Source

pub fn provider_options(self, options: ProviderOptions) -> Self

Provider options sent with the definition.

Source

pub fn on_input_start<F, Fut>(self, function: F) -> Self
where F: Fn(ToolContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Hook called when the model starts producing input.

Source

pub fn on_input_delta<F, Fut>(self, function: F) -> Self
where F: Fn(String, ToolContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Hook called for each input delta.

Source

pub fn on_input_available<F, Fut>(self, function: F) -> Self
where F: Fn(JsonValue, ToolContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Hook called once the input is complete and valid.

Source

pub fn to_model_output<F>(self, function: F) -> Self
where F: Fn(ModelOutputArgs<'_>) -> ToolResultOutput + Send + Sync + 'static,

Custom conversion of the output into what the model receives.

Source

pub fn caller(self, definition: ToolCallerDefinition) -> Self

Declares how this tool calls other tools.

Source

pub fn supports_deferred_results(self, supported: bool) -> Self

Marks a provider-executed tool as supporting deferred results. Ignored for other kinds.

Source

pub fn execute_with(self, executor: Arc<dyn ToolExecute>) -> Self

Uses a custom executor.

Source

pub fn build(self) -> Tool

Finishes the tool.

Source§

impl<I: DeserializeOwned + Send + 'static> ToolBuilder<I>

Source

pub fn execute<F, Fut, O>(self, function: F) -> Self
where F: Fn(I, ToolContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<O, ToolError>> + Send + 'static, O: Serialize + 'static,

Executes with an async closure returning a single result.

Source

pub fn execute_stream<F, S, O>(self, function: F) -> Self
where F: Fn(I, ToolContext) -> S + Send + Sync + 'static, S: Stream<Item = Result<O, ToolError>> + Send + 'static, O: Serialize + 'static,

Executes with a closure returning a stream; every item becomes a preliminary output and the last one is repeated as the final output.

Trait Implementations§

Source§

impl<I> Debug for ToolBuilder<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I> !RefUnwindSafe for ToolBuilder<I>

§

impl<I> !UnwindSafe for ToolBuilder<I>

§

impl<I> Freeze for ToolBuilder<I>
where PhantomData<fn() -> I>: Freeze,

§

impl<I> Send for ToolBuilder<I>
where PhantomData<fn() -> I>: Send,

§

impl<I> Sync for ToolBuilder<I>
where PhantomData<fn() -> I>: Sync,

§

impl<I> Unpin for ToolBuilder<I>
where PhantomData<fn() -> I>: Unpin,

§

impl<I> UnsafeUnpin for ToolBuilder<I>
where PhantomData<fn() -> I>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.