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 {
"在采取行动前,使用此工具记录推理和分析过程。参数:reasoning - 你对问题的分析和计划。"
}
fn parameters(&self) -> Value {
serde_json::json!({
"type": "object",
"properties": {
"reasoning": {
"type": "string",
"description": "你的思考过程:分析问题、制定计划、推理步骤"
}
},
"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()))
})
}
}