Skip to main content

rig_core/tool/builtin/
think.rs

1use serde::{Deserialize, Serialize};
2use serde_json::json;
3
4use crate::tool::PortableTool;
5
6/// Arguments for the Think tool
7#[derive(Deserialize)]
8pub struct ThinkArgs {
9    /// The thought to think about
10    pub thought: String,
11}
12
13/// Error type for the Think tool.
14#[derive(Debug, thiserror::Error)]
15#[error("Think tool error: {0}")]
16pub struct ThinkError(String);
17
18/// Returns the supplied thought unchanged, without I/O or state mutation.
19#[derive(Deserialize, Serialize)]
20pub struct ThinkTool;
21
22impl PortableTool for ThinkTool {
23    const NAME: &'static str = "think";
24    type Error = ThinkError;
25    type Args = ThinkArgs;
26    type Output = String;
27
28    fn description(&self) -> String {
29        "Use the tool to think about something. It will not obtain new information
30            or change the database, but just append the thought to the log. Use it when complex
31            reasoning or some cache memory is needed."
32            .to_string()
33    }
34
35    fn parameters(&self) -> serde_json::Value {
36        json!({
37            "type": "object",
38            "properties": {
39                "thought": {
40                    "type": "string",
41                    "description": "A thought to think about."
42                }
43            },
44            "required": ["thought"]
45        })
46    }
47
48    async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
49        Ok(args.thought)
50    }
51}
52
53#[cfg(test)]
54mod tests;