use futures::future::BoxFuture;
use crate::error::ToolError;
use crate::tools::{Tool, ToolParameters, ToolResult};
use serde_json::Value;
use tracing::info;
pub struct ThinkTool;
impl Tool for ThinkTool {
fn name(&self) -> &str {
"think"
}
fn description(&self) -> &str {
"Before taking action, use this tool to record your reasoning and analysis process. Parameter: reasoning - your analysis and plan for the problem."
}
fn parameters(&self) -> Value {
serde_json::json!({
"type": "object",
"properties": {
"reasoning": {
"type": "string",
"description": "Your reasoning process: analyze the problem, formulate a plan, reasoning steps"
}
},
"required": ["reasoning"]
})
}
fn execute(
&self,
parameters: ToolParameters,
) -> BoxFuture<'_, crate::error::Result<ToolResult>> {
Box::pin(async move {
let reasoning = parameters
.get("reasoning")
.and_then(|v| v.as_str())
.ok_or_else(|| ToolError::MissingParameter("reasoning".to_string()))?;
info!("Think: {}", reasoning);
Ok(ToolResult::success(reasoning.to_string()))
})
}
}