assistant_tool.rs

 1mod tool_registry;
 2
 3use std::sync::Arc;
 4
 5use anyhow::Result;
 6use gpui::{AppContext, Task, WeakView, WindowContext};
 7use workspace::Workspace;
 8
 9pub use tool_registry::*;
10
11pub fn init(cx: &mut AppContext) {
12    ToolRegistry::default_global(cx);
13}
14
15/// A tool that can be used by a language model.
16pub trait Tool: 'static + Send + Sync {
17    /// Returns the name of the tool.
18    fn name(&self) -> String;
19
20    /// Returns the description of the tool.
21    fn description(&self) -> String;
22
23    /// Returns the JSON schema that describes the tool's input.
24    fn input_schema(&self) -> serde_json::Value {
25        serde_json::Value::Object(serde_json::Map::default())
26    }
27
28    /// Runs the tool with the provided input.
29    fn run(
30        self: Arc<Self>,
31        input: serde_json::Value,
32        workspace: WeakView<Workspace>,
33        cx: &mut WindowContext,
34    ) -> Task<Result<String>>;
35}