use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use crate::Result;
use crate::llm::ToolDefinition;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResult {
pub tool_call_id: String,
pub content: String,
#[serde(default)]
pub ephemeral: bool,
}
impl ToolResult {
pub fn new(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self {
Self {
tool_call_id: tool_call_id.into(),
content: content.into(),
ephemeral: false,
}
}
pub fn with_ephemeral(mut self, ephemeral: bool) -> Self {
self.ephemeral = ephemeral;
self
}
}
#[async_trait]
pub trait Tool: Send + Sync {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn definition(&self) -> ToolDefinition;
async fn execute(&self, args: serde_json::Value) -> Result<ToolResult>;
fn ephemeral(&self) -> EphemeralConfig {
EphemeralConfig::None
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum EphemeralConfig {
#[default]
None,
Single,
Count(usize),
}