Skip to main content

Module rig

Module rig 

Source
Expand description

rig tools whose arguments are validated by vld.

Implement VldToolHandler (name, description, a vld Args type and call) and register VldTool::new(handler)? as a rig Tool: its parameters() is the vld schema prepared for the chosen Provider, and arguments that fail validation return ToolExecutionError::invalid_args whose model-visible text is VldError::llm_feedback, so the model can retry the call.

ⓘ
use vld_web::rig::{VldTool, VldToolHandler};

vld::schema! {
    #[derive(Debug)]
    pub struct AddArgs { pub a: i64 => vld::i64(), pub b: i64 => vld::i64().min(0) }
}

struct Add;
impl VldToolHandler for Add {
    const NAME: &'static str = "add";
    type Args = AddArgs;
    type Output = i64;
    type Error = std::convert::Infallible;
    fn description(&self) -> String { "Add two numbers".into() }
    async fn call(&self, args: AddArgs) -> Result<i64, Self::Error> { Ok(args.a + args.b) }
}

let tool = VldTool::new(Add)?; // a rig `Tool`

Structs§

VldTool
A VldToolHandler as a rig Tool.

Traits§

VldToolHandler
A rig tool with vld-validated arguments; wrap it in VldTool.

Functions§

parse_args
Parse tool arguments as T; a failure is an invalid_args error whose model-visible text is the feedback (unknown keys hinted from schema).