1mod tool_registry;
2mod tool_working_set;
3
4use std::sync::Arc;
5
6use anyhow::Result;
7use gpui::{App, Entity, SharedString, Task};
8use language_model::LanguageModelRequestMessage;
9use project::Project;
10
11pub use crate::tool_registry::*;
12pub use crate::tool_working_set::*;
13
14pub fn init(cx: &mut App) {
15 ToolRegistry::default_global(cx);
16}
17
18#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
19pub enum ToolSource {
20 /// A native tool built-in to Zed.
21 Native,
22 /// A tool provided by a context server.
23 ContextServer { id: SharedString },
24}
25
26/// A tool that can be used by a language model.
27pub trait Tool: 'static + Send + Sync {
28 /// Returns the name of the tool.
29 fn name(&self) -> String;
30
31 /// Returns the description of the tool.
32 fn description(&self) -> String;
33
34 /// Returns the source of the tool.
35 fn source(&self) -> ToolSource {
36 ToolSource::Native
37 }
38
39 /// Returns the JSON schema that describes the tool's input.
40 fn input_schema(&self) -> serde_json::Value {
41 serde_json::Value::Object(serde_json::Map::default())
42 }
43
44 /// Runs the tool with the provided input.
45 fn run(
46 self: Arc<Self>,
47 input: serde_json::Value,
48 messages: &[LanguageModelRequestMessage],
49 project: Entity<Project>,
50 cx: &mut App,
51 ) -> Task<Result<String>>;
52}