enact_core/tool/trait.rs
1//! Tool trait definition
2
3use async_trait::async_trait;
4use serde_json::Value;
5use std::sync::Arc;
6
7/// Tool trait - all tools implement this
8#[async_trait]
9pub trait Tool: Send + Sync {
10 /// Tool name
11 fn name(&self) -> &str;
12
13 /// Tool description
14 fn description(&self) -> &str;
15
16 /// JSON schema for tool parameters
17 fn parameters_schema(&self) -> Value {
18 serde_json::json!({})
19 }
20
21 /// Whether this tool requires network access.
22 /// Default is `true` (conservative).
23 /// Override to `false` for local-only tools (e.g., file, calculator).
24 fn requires_network(&self) -> bool {
25 true
26 }
27
28 /// Execute the tool with the given arguments
29 async fn execute(&self, args: Value) -> anyhow::Result<Value>;
30}
31
32/// Boxed tool for dynamic dispatch
33pub type DynTool = Arc<dyn Tool>;