pub trait ToolParser: Send + Sync {
// Required methods
fn parse_complete<'life0, 'life1, 'async_trait>(
&'life0 self,
output: &'life1 str,
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn parse_incremental<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
chunk: &'life1 str,
tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<StreamingParseResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn has_tool_markers(&self, text: &str) -> bool;
// Provided methods
fn parse_complete_with_tools<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
output: &'life1 str,
_tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>> { ... }
fn reset(&mut self) { ... }
}Expand description
Core trait for all tool parsers
Required Methods§
Sourcefn parse_complete<'life0, 'life1, 'async_trait>(
&'life0 self,
output: &'life1 str,
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse_complete<'life0, 'life1, 'async_trait>(
&'life0 self,
output: &'life1 str,
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Parse complete tool calls from final output Returns (remaining_normal_text, tool_calls) tuple
Sourcefn parse_incremental<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
chunk: &'life1 str,
tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<StreamingParseResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn parse_incremental<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
chunk: &'life1 str,
tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<StreamingParseResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Parse tool calls from model output (streaming) Parsers now maintain internal state, so self is mutable
§Arguments
chunk- New text chunk from model outputtools- List of available tools for validation
Sourcefn has_tool_markers(&self, text: &str) -> bool
fn has_tool_markers(&self, text: &str) -> bool
Check if text contains tool calls in this parser’s format
Provided Methods§
Sourcefn parse_complete_with_tools<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
output: &'life1 str,
_tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn parse_complete_with_tools<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
output: &'life1 str,
_tools: &'life2 [Tool],
) -> Pin<Box<dyn Future<Output = ParserResult<(String, Vec<ToolCall>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Like Self::parse_complete, but with the request’s tool schemas so
schema-aware parsers coerce arg values by declared type. The default
ignores tools and delegates to parse_complete.
Sourcefn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>>
fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>>
Get unstreamed tool call arguments Returns tool call items for arguments that have been parsed but not yet streamed
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".