1use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ToolSpec {
10 pub name: String,
11 pub description: String,
12 pub parameters: Value, }
14
15#[derive(Debug, Clone)]
17pub struct ToolResult {
18 pub output: String,
19 pub is_error: bool,
20}
21
22impl ToolResult {
23 pub fn success(output: impl Into<String>) -> Self {
24 Self {
25 output: crate::redaction::redact_text(&output.into()),
26 is_error: false,
27 }
28 }
29 pub fn error(output: impl Into<String>) -> Self {
30 Self {
31 output: crate::redaction::redact_text(&output.into()),
32 is_error: true,
33 }
34 }
35}
36
37#[async_trait]
39pub trait Tool: Send + Sync {
40 fn name(&self) -> &str;
42
43 fn spec(&self) -> ToolSpec;
45
46 async fn execute(&self, arguments: &str) -> anyhow::Result<ToolResult>;
48}