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    const NAME: &'static str = "thinking";
25
26    fn kind() -> acp::ToolKind {
27        acp::ToolKind::Think
28    }
29
30    fn initial_title(
31        &self,
32        _input: Result<Self::Input, serde_json::Value>,
33        _cx: &mut App,
34    ) -> SharedString {
35        "Thinking".into()
36    }
37
38    fn run(
39        self: Arc<Self>,
40        input: Self::Input,
41        event_stream: ToolCallEventStream,
42        _cx: &mut App,
43    ) -> Task<Result<String>> {
44        event_stream
45            .update_fields(acp::ToolCallUpdateFields::new().content(vec![input.content.into()]));
46        Task::ready(Ok("Finished thinking.".to_string()))
47    }
48}