pub struct ToolCallParser {
pub schemas: HashMap<String, ToolSchema>,
}Expand description
Parses tool calls from LLM text and validates them against registered schemas.
Fields§
§schemas: HashMap<String, ToolSchema>Registered schemas keyed by tool name.
Implementations§
Source§impl ToolCallParser
impl ToolCallParser
Sourcepub fn register_tool(&mut self, schema: ToolSchema)
pub fn register_tool(&mut self, schema: ToolSchema)
Registers a tool schema so calls to that tool can be validated.
Sourcepub fn parse_tool_calls(&self, text: &str) -> Vec<Result<ToolCall, ParseError>>
pub fn parse_tool_calls(&self, text: &str) -> Vec<Result<ToolCall, ParseError>>
Finds all JSON tool-call objects in text and attempts to parse each.
Matches {"tool": "...", "arguments": {...}} patterns. Arguments are
flattened to HashMap<String, String> by converting every value to its
JSON string representation.
Sourcepub fn validate_call(&self, call: &ToolCall) -> Result<(), ParseError>
pub fn validate_call(&self, call: &ToolCall) -> Result<(), ParseError>
Validates a parsed ToolCall against registered schemas.
Returns Ok(()) if the tool is known and all required params are present.
Sourcepub fn extract_json_objects<'a>(&self, text: &'a str) -> Vec<&'a str>
pub fn extract_json_objects<'a>(&self, text: &'a str) -> Vec<&'a str>
Extracts all top-level balanced {…} blocks from text.
Handles nested braces correctly; does not cross string boundaries in a fully general way but is sufficient for typical LLM JSON output.
Sourcepub fn format_tool_result(tool_name: &str, result: &str) -> String
pub fn format_tool_result(tool_name: &str, result: &str) -> String
Formats a tool result in the expected XML-like envelope.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToolCallParser
impl RefUnwindSafe for ToolCallParser
impl Send for ToolCallParser
impl Sync for ToolCallParser
impl Unpin for ToolCallParser
impl UnsafeUnpin for ToolCallParser
impl UnwindSafe for ToolCallParser
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request