Skip to main content

aidens_tool_kit/
custom.rs

1//! Custom tool executor trait for registering external executors.
2//!
3//! This allows kirsten (or any AiDENs consumer) to register tool executors
4//! that call semantic-memory or any other backend, without modifying the
5//! AiDENs tool-kit internals.
6
7use serde_json::Value;
8use std::sync::Arc;
9
10/// Trait for custom tool executors. Implement this for each kirsten tool.
11#[async_trait::async_trait]
12pub trait CustomToolExecutor: Send + Sync + std::fmt::Debug {
13    /// Execute the tool with the given input. Return the output text.
14    async fn execute(&self, tool_id: &str, input: Value) -> anyhow::Result<String>;
15
16    /// Clone into an Arc (for storing in ToolExecutorV1::Custom).
17    fn clone_box(&self) -> Arc<dyn CustomToolExecutor>;
18}
19
20/// A wrapper that makes CustomToolExecutor cloneable for the enum.
21#[derive(Clone)]
22pub struct CustomExecutorHandle {
23    pub inner: Arc<dyn CustomToolExecutor>,
24}
25
26impl std::fmt::Debug for CustomExecutorHandle {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        f.debug_struct("CustomExecutorHandle").finish()
29    }
30}
31
32impl CustomExecutorHandle {
33    pub fn new(exec: Arc<dyn CustomToolExecutor>) -> Self {
34        Self { inner: exec }
35    }
36}