pub struct ToolDefinition {
pub tool_type: String,
pub function: Option<FunctionDefinition>,
pub web_search: Option<Value>,
pub defer_loading: Option<bool>,
pub namespace: Option<ToolNamespace>,
/* private fields */
}Expand description
Universal tool definition that matches OpenAI/Anthropic/Gemini specifications Based on official API documentation from Context7
Fields§
§tool_type: StringThe type of tool: “function”, “apply_patch” (GPT-5.1), “shell” (GPT-5.1), or “custom” (GPT-5 freeform) Also supports provider-native and hosted tool types like:
- “tool_search” (OpenAI hosted tool search)
- “file_search” and “mcp” (OpenAI Responses hosted tools)
- Anthropic tool search revisions:
- “tool_search_tool_regex_20251119”, “tool_search_tool_bm25_20251119”
- “web_search_20260209” (and other web_search_* revisions)
- “code_execution_20250825” (and other code_execution_* revisions)
- “memory_20250818” (and other memory_* revisions)
function: Option<FunctionDefinition>Function definition containing name, description, and parameters Used for “function”, “apply_patch”, and “custom” types
web_search: Option<Value>Provider-native web search configuration payload (e.g. Z.AI web_search tool).
defer_loading: Option<bool>When true, the tool is deferred and only loaded when discovered via tool search (Anthropic advanced-tool-use beta) This enables dynamic tool discovery for large tool catalogs (10k+ tools)
namespace: Option<ToolNamespace>Optional namespace grouping for deferred tools. When present and
defer_loading is true, only this namespace metadata is sent upfront
instead of the full tool definition.
Implementations§
Source§impl ToolDefinition
impl ToolDefinition
Sourcepub fn function(name: String, description: String, parameters: Value) -> Self
pub fn function(name: String, description: String, parameters: Value) -> Self
Create a new tool definition with function type
Sourcepub fn with_strict(self, strict: bool) -> Self
pub fn with_strict(self, strict: bool) -> Self
Set whether the tool should be considered strict (Anthropic structured tool use)
Sourcepub fn with_defer_loading(self, defer: bool) -> Self
pub fn with_defer_loading(self, defer: bool) -> Self
Set whether the tool should be deferred (Anthropic tool search)
Sourcepub fn with_namespace(self, namespace: ToolNamespace) -> Self
pub fn with_namespace(self, namespace: ToolNamespace) -> Self
Assign this tool to a namespace for grouped deferred loading.
When both defer_loading and namespace are set, only the namespace
metadata is sent upfront; the full definition is loaded on search.
Sourcepub fn tool_search(algorithm: ToolSearchAlgorithm) -> Self
pub fn tool_search(algorithm: ToolSearchAlgorithm) -> Self
Create a tool search tool definition for Anthropic’s advanced-tool-use beta Supports regex and bm25 search algorithms
Sourcepub fn hosted_tool_search() -> Self
pub fn hosted_tool_search() -> Self
Create an OpenAI hosted tool search definition.
Sourcepub fn anthropic_memory() -> Self
pub fn anthropic_memory() -> Self
Create an Anthropic native memory tool definition.
Sourcepub fn apply_patch(description: String) -> Self
pub fn apply_patch(description: String) -> Self
Create a new apply_patch tool definition (GPT-5.1 specific) The apply_patch tool lets models create, update, and delete files using VT Code structured diffs
Sourcepub fn custom(name: String, description: String) -> Self
pub fn custom(name: String, description: String) -> Self
Create a new custom tool definition for freeform function calling (GPT-5 specific) Allows raw text payloads without JSON wrapping
Sourcepub fn grammar(syntax: String, definition: String) -> Self
pub fn grammar(syntax: String, definition: String) -> Self
Create a new grammar tool definition for context-free grammar constraints (GPT-5 specific) Ensures model output matches predefined syntax
Sourcepub fn web_search(config: Value) -> Self
pub fn web_search(config: Value) -> Self
Create a provider-native web search tool definition.
Sourcepub fn google_maps(config: Value) -> Self
pub fn google_maps(config: Value) -> Self
Create a Gemini Google Maps grounding tool definition.
Sourcepub fn url_context(config: Value) -> Self
pub fn url_context(config: Value) -> Self
Create a Gemini URL Context tool definition.
Sourcepub fn function_name(&self) -> &str
pub fn function_name(&self) -> &str
Get the function name for easy access
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Get the description for easy access
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate that this tool definition is properly formed
Sourcepub fn is_tool_search(&self) -> bool
pub fn is_tool_search(&self) -> bool
Returns true if this is a tool search tool type
Sourcepub fn is_anthropic_web_search(&self) -> bool
pub fn is_anthropic_web_search(&self) -> bool
Returns true when the tool is an Anthropic native web search tool revision.
Trait Implementations§
Source§impl Clone for ToolDefinition
impl Clone for ToolDefinition
Source§impl Debug for ToolDefinition
impl Debug for ToolDefinition
Source§impl<'de> Deserialize<'de> for ToolDefinition
impl<'de> Deserialize<'de> for ToolDefinition
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>,
Source§impl PartialEq for ToolDefinition
impl PartialEq for ToolDefinition
Source§impl Serialize for ToolDefinition
impl Serialize for ToolDefinition
impl StructuralPartialEq for ToolDefinition
Auto Trait Implementations§
impl Freeze for ToolDefinition
impl RefUnwindSafe for ToolDefinition
impl Send for ToolDefinition
impl Sync for ToolDefinition
impl Unpin for ToolDefinition
impl UnsafeUnpin for ToolDefinition
impl UnwindSafe for ToolDefinition
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> 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