1use std::{future::Future, pin::Pin};
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::{ToolContext, ToolDescriptor, ToolError};
7
8pub type ToolFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
10
11#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
13pub struct ToolOutput {
14 pub value: Value,
16 pub model_visible: bool,
18}
19
20impl ToolOutput {
21 pub const fn model_visible(value: Value) -> Self {
23 Self {
24 value,
25 model_visible: true,
26 }
27 }
28}
29
30pub trait Tool: Send + Sync {
32 fn descriptor(&self) -> &ToolDescriptor;
34
35 fn invoke(
37 &self,
38 input: Value,
39 context: ToolContext,
40 ) -> ToolFuture<'_, Result<ToolOutput, ToolError>>;
41}