thinking_tool.rs

 1use agent_client_protocol as acp;
 2use anyhow::Result;
 3use gpui::{App, SharedString, Task};
 4use schemars::JsonSchema;
 5use serde::{Deserialize, Serialize};
 6use std::sync::Arc;
 7
 8use crate::{AgentTool, ToolCallEventStream};
 9
10/// A tool for thinking through problems, brainstorming ideas, or planning without executing any actions.
11/// Use this tool when you need to work through complex problems, develop strategies, or outline approaches before taking action.
12#[derive(Debug, Serialize, Deserialize, JsonSchema)]
13pub struct ThinkingToolInput {
14    /// Content to think about. This should be a description of what to think about or a problem to solve.
15    content: String,
16}
17
18pub struct ThinkingTool;
19
20impl AgentTool for ThinkingTool {
21    type Input = ThinkingToolInput;
22    type Output = String;
23
24    fn name() -> &'static str {
25        "thinking"
26    }
27
28    fn kind() -> acp::ToolKind {
29        acp::ToolKind::Think
30    }
31
32    fn initial_title(
33        &self,
34        _input: Result<Self::Input, serde_json::Value>,
35        _cx: &mut App,
36    ) -> SharedString {
37        "Thinking".into()
38    }
39
40    fn run(
41        self: Arc<Self>,
42        input: Self::Input,
43        event_stream: ToolCallEventStream,
44        _cx: &mut App,
45    ) -> Task<Result<String>> {
46        event_stream.update_fields(acp::ToolCallUpdateFields {
47            content: Some(vec![input.content.into()]),
48            ..Default::default()
49        });
50        Task::ready(Ok("Finished thinking.".to_string()))
51    }
52}