llmoxide-tools 0.1.0

Tool-calling runner for llmoxide (schemas, dispatch, streaming callbacks)
Documentation
use llmoxide_tools::{RunConfig, ToolMeta, ToolRegistry, ToolRunnerText};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

fn env(name: &str) -> String {
    std::env::var(name).unwrap_or_default()
}

#[derive(Debug, Clone, Deserialize, JsonSchema)]
struct AddArgs {
    a: i64,
    b: i64,
}

#[derive(Debug, Clone, Serialize, JsonSchema)]
struct AddResult {
    sum: i64,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = env("OPENAI_API_KEY");
    if key.is_empty() {
        eprintln!("Set OPENAI_API_KEY (or switch this example to Anthropic/Gemini).");
        return Ok(());
    }

    let client = llmoxide::openai(key);

    let mut tools = ToolRegistry::new();
    tools.register::<AddArgs, AddResult, _, _>(
        ToolMeta::new("add").description("Add two integers."),
        |args| async move {
            Ok(AddResult {
                sum: args.a + args.b,
            })
        },
    );

    let resp = client
        .run_with_tools_text(
            "Use the add tool to compute 19 + 23. Then reply with the number only.",
            &tools,
            RunConfig { max_rounds: 4 },
        )
        .await?;

    if let Some(t) = resp.text() {
        println!("{t}");
    }

    Ok(())
}