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 needs_confirmation(&self) -> bool {
26 false
27 }
28
29 fn description(&self) -> String {
30 include_str!("./thinking_tool/description.md").to_string()
31 }
32
33 fn input_schema(&self) -> serde_json::Value {
34 let schema = schemars::schema_for!(ThinkingToolInput);
35 serde_json::to_value(&schema).unwrap()
36 }
37
38 fn ui_text(&self, _input: &serde_json::Value) -> String {
39 "Thinking".to_string()
40 }
41
42 fn run(
43 self: Arc<Self>,
44 input: serde_json::Value,
45 _messages: &[LanguageModelRequestMessage],
46 _project: Entity<Project>,
47 _action_log: Entity<ActionLog>,
48 _cx: &mut App,
49 ) -> Task<Result<String>> {
50 // This tool just "thinks out loud" and doesn't perform any actions.
51 Task::ready(match serde_json::from_value::<ThinkingToolInput>(input) {
52 Ok(_input) => Ok("Finished thinking.".to_string()),
53 Err(err) => Err(anyhow!(err)),
54 })
55 }
56}