pub struct Tool { /* private fields */ }Expand description
A tool definition. Built with Tool::function, Tool::dynamic,
Tool::provider_defined or Tool::provider_executed.
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn function<I: DeserializeOwned + JsonSchema + 'static>() -> ToolBuilder<I>
pub fn function<I: DeserializeOwned + JsonSchema + 'static>() -> ToolBuilder<I>
A function tool whose input schema is derived from I
(draft-07, additionalProperties: false on objects).
Sourcepub fn function_with_schema(
input_schema: Schema<JsonValue>,
) -> ToolBuilder<JsonValue>
pub fn function_with_schema( input_schema: Schema<JsonValue>, ) -> ToolBuilder<JsonValue>
A function tool with an explicit JSON schema; the execute closure receives the raw JSON input.
Sourcepub fn dynamic(input_schema: Schema<JsonValue>) -> ToolBuilder<JsonValue>
pub fn dynamic(input_schema: Schema<JsonValue>) -> ToolBuilder<JsonValue>
A dynamic tool (runtime-defined schema, untyped input and output).
Sourcepub fn provider_defined(
id: impl Into<String>,
args: JsonObject,
) -> ToolBuilder<JsonValue>
pub fn provider_defined( id: impl Into<String>, args: JsonObject, ) -> ToolBuilder<JsonValue>
A provider-defined tool executed by the application. The input schema defaults to “any”; provider crates set the real one.
Sourcepub fn provider_executed(
id: impl Into<String>,
args: JsonObject,
) -> ToolBuilder<JsonValue>
pub fn provider_executed( id: impl Into<String>, args: JsonObject, ) -> ToolBuilder<JsonValue>
A provider-executed tool.
Source§impl Tool
impl Tool
Sourcepub fn description(&self) -> Option<&Description>
pub fn description(&self) -> Option<&Description>
The description declaration.
Sourcepub fn input_schema(&self) -> &Schema<JsonValue>
pub fn input_schema(&self) -> &Schema<JsonValue>
The input schema (erased to JSON).
Sourcepub fn output_schema(&self) -> Option<&Schema<JsonValue>>
pub fn output_schema(&self) -> Option<&Schema<JsonValue>>
The output schema, if declared.
Sourcepub fn context_schema(&self) -> Option<&Schema<JsonValue>>
pub fn context_schema(&self) -> Option<&Schema<JsonValue>>
The context schema, if declared.
Sourcepub fn executor(&self) -> Option<&Arc<dyn ToolExecute>>
pub fn executor(&self) -> Option<&Arc<dyn ToolExecute>>
The executor, if the tool is executed by the application.
Sourcepub fn is_executable(&self) -> bool
pub fn is_executable(&self) -> bool
Returns true when the tool has an executor.
Sourcepub fn needs_approval(&self) -> &NeedsApproval
pub fn needs_approval(&self) -> &NeedsApproval
The approval declaration.
Sourcepub fn input_examples(&self) -> &[JsonObject] ⓘ
pub fn input_examples(&self) -> &[JsonObject] ⓘ
Example inputs.
Sourcepub fn metadata(&self) -> Option<&JsonObject>
pub fn metadata(&self) -> Option<&JsonObject>
Metadata propagated to tool calls (not sent to the model).
Sourcepub fn provider_options(&self) -> Option<&ProviderOptions>
pub fn provider_options(&self) -> Option<&ProviderOptions>
Provider options sent with the tool definition.
Sourcepub fn to_model_output(&self) -> Option<&ToModelOutputFn>
pub fn to_model_output(&self) -> Option<&ToModelOutputFn>
Custom model-output conversion.
Sourcepub fn caller_definition(&self) -> Option<&ToolCallerDefinition>
pub fn caller_definition(&self) -> Option<&ToolCallerDefinition>
Caller definition, when this tool can call other tools.
Sourcepub fn with_provider_options(
self,
provider_options: Option<ProviderOptions>,
) -> Self
pub fn with_provider_options( self, provider_options: Option<ProviderOptions>, ) -> Self
Returns a copy with different provider options.
Sourcepub async fn resolve_description(
&self,
ctx: DescriptionContext,
) -> Option<String>
pub async fn resolve_description( &self, ctx: DescriptionContext, ) -> Option<String>
Resolves the description for a call (None when the tool has none).
Sourcepub fn definition(
&self,
name: ToolName,
description: Option<String>,
) -> ToolDefinition
pub fn definition( &self, name: ToolName, description: Option<String>, ) -> ToolDefinition
Builds the provider-facing definition under name.
Sourcepub fn validate_input(
&self,
name: &ToolName,
input: JsonValue,
) -> Result<JsonValue, TypeValidationError>
pub fn validate_input( &self, name: &ToolName, input: JsonValue, ) -> Result<JsonValue, TypeValidationError>
Validates an input against the input schema.
§Errors
Returns the validation error with field: "tool input" and the tool
name as entity.
Sourcepub fn validate_context(
&self,
name: &ToolName,
context: Option<JsonValue>,
) -> Result<Option<JsonValue>, TypeValidationError>
pub fn validate_context( &self, name: &ToolName, context: Option<JsonValue>, ) -> Result<Option<JsonValue>, TypeValidationError>
Validates the tool context against the context schema. Tools without
a context schema receive None.
§Errors
Returns the validation error with field: "tool context".
Sourcepub fn execute(
&self,
input: JsonValue,
ctx: ToolContext,
) -> Option<ToolOutputStream>
pub fn execute( &self, input: JsonValue, ctx: ToolContext, ) -> Option<ToolOutputStream>
Starts an execution; None when the tool has no executor.