thinking_tool.rs

 1use std::sync::Arc;
 2
 3use crate::schema::json_schema_for;
 4use anyhow::Result;
 5use assistant_tool::{ActionLog, Tool, ToolResult};
 6use gpui::{AnyWindowHandle, App, Entity, Task};
 7use language_model::{LanguageModel, LanguageModelRequest, LanguageModelToolSchemaFormat};
 8use project::Project;
 9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11use ui::IconName;
12
13#[derive(Debug, Serialize, Deserialize, JsonSchema)]
14pub struct ThinkingToolInput {
15    /// Content to think about. This should be a description of what to think about or
16    /// a problem to solve.
17    content: String,
18}
19
20pub struct ThinkingTool;
21
22impl Tool for ThinkingTool {
23    type Input = ThinkingToolInput;
24
25    fn name(&self) -> String {
26        "thinking".to_string()
27    }
28
29    fn needs_confirmation(&self, _: &Self::Input, _: &App) -> bool {
30        false
31    }
32
33    fn may_perform_edits(&self) -> bool {
34        false
35    }
36
37    fn description(&self) -> String {
38        include_str!("./thinking_tool/description.md").to_string()
39    }
40
41    fn icon(&self) -> IconName {
42        IconName::LightBulb
43    }
44
45    fn input_schema(&self, format: LanguageModelToolSchemaFormat) -> Result<serde_json::Value> {
46        json_schema_for::<ThinkingToolInput>(format)
47    }
48
49    fn ui_text(&self, _input: &Self::Input) -> String {
50        "Thinking".to_string()
51    }
52
53    fn run(
54        self: Arc<Self>,
55        _input: Self::Input,
56        _request: Arc<LanguageModelRequest>,
57        _project: Entity<Project>,
58        _action_log: Entity<ActionLog>,
59        _model: Arc<dyn LanguageModel>,
60        _window: Option<AnyWindowHandle>,
61        _cx: &mut App,
62    ) -> ToolResult {
63        // This tool just "thinks out loud" and doesn't perform any actions.
64        Task::ready(Ok("Finished thinking.".to_string().into())).into()
65    }
66}