Function parse_args
pub fn parse_args<A>(tool: &str, args: Value) -> Result<A, ToolOutput>where
A: DeserializeOwned,Expand description
Read the model’s argument object into A.
The model’s JSON is not trusted to match the schema, so a mismatch is not
an error of the run: it is a ToolOutput::error naming the tool and the
problem (invalid arguments for ask_user: missing field question``),
which the model reads and corrects. Return it as the tool’s output.
null is read as an empty object, because models often send it for a tool
without parameters. Never panics.
use adam_llm_agent::parse_args;
use serde::Deserialize;
use serde_json::json;
#[derive(Debug, Deserialize)]
struct Args { question: String }
let args: Args = parse_args("ask_user", json!({"question": "why?"})).unwrap();
assert_eq!(args.question, "why?");
let refusal = parse_args::<Args>("ask_user", json!({})).unwrap_err();
assert!(refusal.is_error);
assert!(refusal.content.contains("missing field `question`"));