rucora_tools/basic/
echo.rs1use async_trait::async_trait;
6use rucora_core::{
7 error::ToolError,
8 tool::{Tool, ToolCategory},
9};
10use serde_json::{Value, json};
11
12pub struct EchoTool;
29
30#[async_trait]
31impl Tool for EchoTool {
32 fn name(&self) -> &str {
34 "echo"
35 }
36
37 fn description(&self) -> Option<&str> {
39 Some("回显输入参数,用于测试和调试")
40 }
41
42 fn categories(&self) -> &'static [ToolCategory] {
44 &[ToolCategory::Basic]
45 }
46
47 fn input_schema(&self) -> Value {
49 json!({
50 "type": "object",
51 "properties": {
52 "text": {
53 "type": "string",
54 "description": "要回显的文本内容"
55 }
56 },
57 "required": ["text"]
58 })
59 }
60
61 async fn call(&self, input: Value) -> Result<Value, ToolError> {
63 if input.get("text").is_none() {
65 return Err(ToolError::Message("缺少必需的 'text' 字段".to_string()));
66 }
67
68 Ok(input)
69 }
70}