ToolService

Trait ToolService 

Source
pub trait ToolService: Send + Sync {
    // Required method
    fn tools(&self) -> Vec<Arc<dyn CallableFunction>>;
}
Expand description

A provider of callable functions with shared state/dependencies.

Implement this trait on structs that need to provide tools with access to shared resources like databases, APIs, or configuration. This enables dependency injection for tool functions.

§Example

use genai_rs::{CallableFunction, ToolService, FunctionDeclaration};
use std::sync::Arc;

struct WeatherService {
    api_key: String,
}

impl ToolService for WeatherService {
    fn tools(&self) -> Vec<Arc<dyn CallableFunction>> {
        vec![
            Arc::new(GetWeatherTool { api_key: self.api_key.clone() }),
        ]
    }
}

// Use with InteractionBuilder:
let service = Arc::new(WeatherService { api_key: "...".into() });
client.interaction()
    .with_tool_service(service)
    .create_with_auto_functions()
    .await?;

Required Methods§

Source

fn tools(&self) -> Vec<Arc<dyn CallableFunction>>

Returns the callable functions provided by this service.

Each function can hold references to shared state from the service.

Implementors§