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
15    /// a problem to solve.
16    content: String,
17}
18
19pub struct ThinkingTool;
20
21impl AgentTool for ThinkingTool {
22    type Input = ThinkingToolInput;
23    type Output = String;
24
25    fn name(&self) -> SharedString {
26        "thinking".into()
27    }
28
29    fn kind(&self) -> acp::ToolKind {
30        acp::ToolKind::Think
31    }
32
33    fn initial_title(&self, _input: Result<Self::Input, serde_json::Value>) -> SharedString {
34        "Thinking".into()
35    }
36
37    fn run(
38        self: Arc<Self>,
39        input: Self::Input,
40        event_stream: ToolCallEventStream,
41        _cx: &mut App,
42    ) -> Task<Result<String>> {
43        event_stream.update_fields(acp::ToolCallUpdateFields {
44            content: Some(vec![input.content.into()]),
45            ..Default::default()
46        });
47        Task::ready(Ok("Finished thinking.".to_string()))
48    }
49}