restflow_core/tools/
time_tool.rs1use anyhow::Result;
2use chrono::{DateTime, Local};
3use rig::completion::ToolDefinition;
4use rig::tool::Tool;
5use serde::{Deserialize, Serialize};
6use serde_json::json;
7use tracing::debug;
8
9#[derive(Deserialize)]
10pub struct TimeArgs {
11 }
13
14#[derive(Debug, thiserror::Error)]
15#[error("Time error")]
16pub struct TimeError;
17
18#[derive(Deserialize, Serialize)]
19pub struct GetTimeTool;
20
21impl Tool for GetTimeTool {
22 const NAME: &'static str = "get_current_time";
23 type Error = TimeError;
24 type Args = TimeArgs;
25 type Output = String;
26
27 async fn definition(&self, _prompt: String) -> ToolDefinition {
28 ToolDefinition {
29 name: Self::NAME.to_string(),
30 description: "Get the current date and time in local timezone".to_string(),
31 parameters: json!({
32 "type": "object",
33 "properties": {},
34 "required": []
35 }),
36 }
37 }
38
39 async fn call(&self, _args: Self::Args) -> Result<Self::Output, Self::Error> {
40 let now: DateTime<Local> = Local::now();
41 let time_str = now.to_rfc3339();
42
43 debug!(time = %time_str, "GetTimeTool executed");
44 Ok(time_str)
45 }
46}