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 run(
35 self: Arc<Self>,
36 input: serde_json::Value,
37 _messages: &[LanguageModelRequestMessage],
38 _project: Entity<Project>,
39 _action_log: Entity<ActionLog>,
40 _cx: &mut App,
41 ) -> Task<Result<String>> {
42 // This tool just "thinks out loud" and doesn't perform any actions.
43 Task::ready(match serde_json::from_value::<ThinkingToolInput>(input) {
44 Ok(_input) => Ok("Finished thinking.".to_string()),
45 Err(err) => Err(anyhow!(err)),
46 })
47 }
48}