astrid_plugins/tool.rs
1//! Plugin tool trait.
2//!
3//! Mirrors the `BuiltinTool` trait from `astrid-tools` but with dynamic
4//! (non-`'static`) names and a plugin-specific context.
5
6use async_trait::async_trait;
7use serde_json::Value;
8
9use crate::context::PluginToolContext;
10use crate::error::PluginResult;
11
12/// A tool provided by a plugin.
13///
14/// Similar to `BuiltinTool` but returns `&str` instead of `&'static str`
15/// because plugin tool names are loaded at runtime. Uses `PluginToolContext`
16/// instead of `ToolContext` to provide scoped KV storage and restrict access.
17#[async_trait]
18pub trait PluginTool: Send + Sync {
19 /// Tool name (unique within the plugin).
20 ///
21 /// The fully qualified name exposed to the LLM is
22 /// `plugin:{plugin_id}:{tool_name}`.
23 fn name(&self) -> &str;
24
25 /// Human-readable description for the LLM.
26 fn description(&self) -> &str;
27
28 /// JSON schema for tool input parameters.
29 fn input_schema(&self) -> Value;
30
31 /// Execute the tool with the given arguments.
32 async fn execute(&self, args: Value, ctx: &PluginToolContext) -> PluginResult<String>;
33}
34
35impl std::fmt::Debug for dyn PluginTool {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 f.debug_struct("PluginTool")
38 .field("name", &self.name())
39 .finish_non_exhaustive()
40 }
41}