pub enum Tool {
Custom(CustomTool),
Builtin(BuiltinTool),
}Expand description
A tool definition the model can call during generation.
The wire form is untagged:
custom tools are recognized by the presence of an input_schema field;
anything else is treated as a built-in tool.
Variants§
Custom(CustomTool)
A user-defined tool with a JSON Schema for input validation.
Builtin(BuiltinTool)
A server-side built-in tool (web search, computer use, code execution, etc.).
Typed via KnownBuiltinTool with an Other(Value) arm for
forward-compatibility with new tools / new tool versions.
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn custom(name: impl Into<String>, input_schema: Value) -> Self
pub fn custom(name: impl Into<String>, input_schema: Value) -> Self
Convenience constructor for a custom tool with a manually provided JSON Schema.
Sourcepub fn builtin(value: Value) -> Self
pub fn builtin(value: Value) -> Self
Escape hatch: build a Tool::Builtin from raw JSON. Use the typed
constructors (Self::web_search, Self::computer, Self::bash,
Self::text_editor, Self::code_execution) instead when the
tool type is known to the SDK; this is for unknown / future tools.
use claude_api::messages::tools::Tool;
// Unknown future tool -- round-trips through Builtin::Other.
let t = Tool::builtin(serde_json::json!({
"type": "future_tool_2099",
"name": "future"
}));
assert!(matches!(t, Tool::Builtin(_)));Sourcepub fn web_search() -> Self
pub fn web_search() -> Self
Default-config web search tool (web_search_20250305).
Sourcepub fn computer(display_width_px: u32, display_height_px: u32) -> Self
pub fn computer(display_width_px: u32, display_height_px: u32) -> Self
Computer-use tool with the given display dimensions
(computer_20250124).
Sourcepub fn text_editor() -> Self
pub fn text_editor() -> Self
Default-config text editor tool (text_editor_20250124).
Sourcepub fn code_execution() -> Self
pub fn code_execution() -> Self
Default-config code execution tool (code_execution_20250825).
Sourcepub fn from_schemars<T: JsonSchema>(name: impl Into<String>) -> Self
Available on crate feature schemars-tools only.
pub fn from_schemars<T: JsonSchema>(name: impl Into<String>) -> Self
schemars-tools only.Build a custom tool whose input schema is derived from a Rust type via schemars.
§Panics
Panics only if the generated RootSchema fails to JSON-serialize,
which schemars guarantees not to happen for any type that implements
schemars::JsonSchema.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tool
impl<'de> Deserialize<'de> for Tool
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Tool
Auto Trait Implementations§
impl Freeze for Tool
impl RefUnwindSafe for Tool
impl Send for Tool
impl Sync for Tool
impl Unpin for Tool
impl UnsafeUnpin for Tool
impl UnwindSafe for Tool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more