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