1use anyhow::Result;
2use async_trait::async_trait;
3use serde_json::Value;
4
5pub use anyhow;
6pub use serde_json;
7pub use toml;
8
9pub struct ToolOutput {
11 pub success: bool,
12 pub output: String,
13}
14
15#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
17pub struct ToolDefinition {
18 #[serde(rename = "type")]
19 pub kind: String,
20 pub function: FunctionDefinition,
21}
22
23#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
24pub struct FunctionDefinition {
25 pub name: String,
26 pub description: String,
27 pub parameters: Value,
28}
29
30impl ToolDefinition {
31 pub fn function(
33 name: impl Into<String>,
34 description: impl Into<String>,
35 parameters: Value,
36 ) -> Self {
37 Self {
38 kind: "function".to_string(),
39 function: FunctionDefinition {
40 name: name.into(),
41 description: description.into(),
42 parameters,
43 },
44 }
45 }
46}
47
48#[async_trait]
52pub trait Tool: Send + Sync {
53 fn name(&self) -> &'static str;
54 fn definition(&self) -> ToolDefinition;
55 async fn execute(&self, args: &Value) -> Result<ToolOutput>;
56}
57
58#[async_trait]
60pub trait Skill: Send + Sync {
61 fn name(&self) -> &'static str;
63
64 async fn build_tools(&self, config: Option<&toml::Value>) -> Result<Vec<Box<dyn Tool>>>;
68}