pub fn parse_tool_args<T>(call: &ToolCall) -> Result<T, ToolArgsError>where
T: DeserializeOwned,Expand description
Parses and deserializes tool call arguments into the specified type.
Uses serde for deserialization, so the target type must implement DeserializeOwned.
Returns a descriptive error if JSON parsing or deserialization fails.
§Example
ⓘ
use serde::Deserialize;
use modelrelay::parse_tool_args;
#[derive(Deserialize)]
struct WeatherArgs {
location: String,
#[serde(default = "default_unit")]
unit: String,
}
fn default_unit() -> String { "celsius".to_string() }
// In your tool handler:
let args: WeatherArgs = parse_tool_args(&tool_call)?;
println!("Location: {}", args.location);