Skip to main content

apollo/tools/
traits.rs

1//! Core Tool trait — defines agent capabilities.
2
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7/// Tool specification for LLM function calling.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ToolSpec {
10    pub name: String,
11    pub description: String,
12    pub parameters: Value, // JSON Schema
13}
14
15/// Result of executing a tool.
16#[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/// The core Tool trait. Each tool implements this.
38#[async_trait]
39pub trait Tool: Send + Sync {
40    /// Tool name (must match the ToolSpec name)
41    fn name(&self) -> &str;
42
43    /// Get the tool specification for LLM function calling
44    fn spec(&self) -> ToolSpec;
45
46    /// Execute the tool with the given arguments (JSON string)
47    async fn execute(&self, arguments: &str) -> anyhow::Result<ToolResult>;
48}