ToolParser

Trait ToolParser 

Source
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 as_token_parser(&self) -> Option<&dyn TokenToolParser> { ... }
    fn get_unstreamed_tool_args(&self) -> Option<Vec<ToolCallItem>> { ... }
    fn reset(&mut self) { ... }
}
Expand description

Core trait for all tool parsers

Required Methods§

Source

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

Source

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 output
  • tools - List of available tools for validation
Source

fn has_tool_markers(&self, text: &str) -> bool

Check if text contains tool calls in this parser’s format

Provided Methods§

Source

fn as_token_parser(&self) -> Option<&dyn TokenToolParser>

Optionally expose a token-aware parser implementation. Default returns None, meaning the parser only supports text input.

Source

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

Source

fn reset(&mut self)

Reset the parser state for reuse across requests. This should clear all buffers and reset state to initial values.

Implementors§