descry-tool-core 0.3.1

Core traits and types for descry-tool framework
Documentation
//! Macro example demonstrating #[tool] function-style macro

use descry_tool_core::{call_tool, tool_exists, tool_names, ToolContext, ToolError};
use descry_tool_macros::tool;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

// Define parameter type
#[derive(Deserialize, JsonSchema)]
struct MultiplyParams {
    a: i32,
    b: i32,
}

// Define output type
#[derive(Serialize, JsonSchema)]
struct MultiplyOutput {
    result: i32,
}

// Use #[tool] macro on function!
#[tool(
    name = "multiply",
    description = "Multiply two numbers"
)]
async fn multiply(_ctx: Arc<ToolContext>, params: MultiplyParams) -> Result<MultiplyOutput, ToolError> {
    Ok(MultiplyOutput {
        result: params.a * params.b,
    })
}

#[tokio::main]
async fn main() {
    println!("=== Descry 2.0 Macro Example ===\n");

    // Show all registered tools
    let names = tool_names();
    println!("Registered tools: {:?}", names);
    println!("Tool count: {}\n", names.len());

    // Check if tool exists
    println!("Tool 'multiply' exists: {}", tool_exists("multiply"));

    // Call tool
    let ctx = Arc::new(ToolContext::new());
    let params = serde_json::json!({"a": 6, "b": 7});
    
    println!("\nCalling multiply(6, 7)...");
    match call_tool("multiply", params, ctx).await {
        Ok(result) => {
            println!("Result: {}", serde_json::to_string_pretty(&result).unwrap());
        }
        Err(e) => {
            eprintln!("Error: {}", e);
        }
    }

    // Get tool schema
    if let Some(schema) = descry_tool_core::get_tool_schema("multiply") {
        println!("\nTool schema:");
        println!("{}", serde_json::to_string_pretty(schema).unwrap());
    }
}