Skip to main content

Crate tool_arg_defaults

Crate tool_arg_defaults 

Source
Expand description

tool-arg-defaults: fill in missing kwargs on LLM-generated tool calls.

LLMs often omit optional args. ToolDefaults merges per-tool default values into the LLM’s args before execution. Caller-supplied keys always win — including explicit null.

use serde_json::json;
use tool_arg_defaults::ToolDefaults;

let mut defaults = ToolDefaults::new();
defaults.register("search_web", json!({"timeout": 30, "max_results": 10}));

// LLM only passed "q"
let merged = defaults.apply("search_web", &json!({"q": "anthropic"}), false).unwrap();
assert_eq!(merged["timeout"], json!(30));
assert_eq!(merged["max_results"], json!(10));
assert_eq!(merged["q"], json!("anthropic"));

// Caller-supplied value wins
let merged = defaults.apply("search_web", &json!({"q": "x", "timeout": 5}), false).unwrap();
assert_eq!(merged["timeout"], json!(5));

Structs§

ToolDefaults
Per-tool default kwargs for LLM-generated tool calls.
ToolNotRegisteredError