thinking_tool.rs

 1use std::sync::Arc;
 2
 3use anyhow::{anyhow, Result};
 4use assistant_tool::{ActionLog, Tool};
 5use gpui::{App, Entity, Task};
 6use language_model::LanguageModelRequestMessage;
 7use project::Project;
 8use schemars::JsonSchema;
 9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Serialize, Deserialize, JsonSchema)]
12pub struct ThinkingToolInput {
13    /// Content to think about. This should be a description of what to think about or
14    /// a problem to solve.
15    content: String,
16}
17
18pub struct ThinkingTool;
19
20impl Tool for ThinkingTool {
21    fn name(&self) -> String {
22        "thinking".to_string()
23    }
24
25    fn description(&self) -> String {
26        include_str!("./thinking_tool/description.md").to_string()
27    }
28
29    fn input_schema(&self) -> serde_json::Value {
30        let schema = schemars::schema_for!(ThinkingToolInput);
31        serde_json::to_value(&schema).unwrap()
32    }
33
34    fn ui_text(&self, _input: &serde_json::Value) -> String {
35        "Thinking".to_string()
36    }
37
38    fn run(
39        self: Arc<Self>,
40        input: serde_json::Value,
41        _messages: &[LanguageModelRequestMessage],
42        _project: Entity<Project>,
43        _action_log: Entity<ActionLog>,
44        _cx: &mut App,
45    ) -> Task<Result<String>> {
46        // This tool just "thinks out loud" and doesn't perform any actions.
47        Task::ready(match serde_json::from_value::<ThinkingToolInput>(input) {
48            Ok(_input) => Ok("Finished thinking.".to_string()),
49            Err(err) => Err(anyhow!(err)),
50        })
51    }
52}