Use this file to discover all available pages before exploring further.
Tools are the agent’s hands — they let it interact with the world. Create custom tools to give your agent new capabilities like API access, file operations, or hardware control.
use anyhow::Result;use async_trait::async_trait;use serde_json::{json, Value};use crate::tools::traits::{Tool, ToolResult};/// A tool that fetches URLs and returns HTTP statuspub struct HttpGetTool;
4
Implement Tool Metadata
5
Provide name, description, and parameter schema:
6
#[async_trait]impl Tool for HttpGetTool { fn name(&self) -> &str { "http_get" } fn description(&self) -> &str { "Fetch a URL and return the HTTP status code and content length" } fn parameters_schema(&self) -> Value { json!({ "type": "object", "properties": { "url": { "type": "string", "description": "URL to fetch" } }, "required": ["url"] }) }}
7
Implement Execute Logic
8
Handle parameter validation and execution:
9
async fn execute(&self, args: Value) -> Result<ToolResult> { // Extract and validate parameters let url = args["url"] .as_str() .ok_or_else(|| anyhow::anyhow!("Missing 'url' parameter"))?; // Execute the tool logic match reqwest::get(url).await { Ok(resp) => { let status = resp.status().as_u16(); let len = resp.content_length().unwrap_or(0); Ok(ToolResult { success: status < 400, output: format!("HTTP {status} — {len} bytes"), error: None, }) } Err(e) => Ok(ToolResult { success: false, output: String::new(), error: Some(format!("Request failed: {e}")) }), } }
10
Register Your Tool
11
Add your tool to src/tools/mod.rs:
12
pub fn default_tools() -> Vec<Box<dyn Tool>> { vec![ Box::new(ShellTool), Box::new(FileReadTool), Box::new(HttpGetTool), // Your new tool // ... other tools ]}
13
Test Your Tool
14
Create a test to verify behavior:
15
#[tokio::test]async fn test_http_get_tool() { let tool = HttpGetTool; let args = json!({ "url": "https://httpbin.org/status/200" }); let result = tool.execute(args).await.unwrap(); assert!(result.success); assert!(result.output.contains("200"));}