mojentic/llm/tools/ephemeral_task_manager/
clear_tasks.rs1use super::task_list::TaskList;
2use crate::error::Result;
3use crate::llm::tools::{FunctionDescriptor, LlmTool, ToolDescriptor};
4use serde_json::{json, Value};
5use std::collections::HashMap;
6use std::sync::{Arc, Mutex};
7
8#[derive(Clone)]
10pub struct ClearTasksTool {
11 task_list: Arc<Mutex<TaskList>>,
12}
13
14impl ClearTasksTool {
15 pub fn new(task_list: Arc<Mutex<TaskList>>) -> Self {
17 Self { task_list }
18 }
19}
20
21impl LlmTool for ClearTasksTool {
22 fn run(&self, _args: &HashMap<String, Value>) -> Result<Value> {
23 let mut task_list = self.task_list.lock().unwrap();
24 let count = task_list.clear_tasks();
25
26 Ok(json!({
27 "count": count,
28 "summary": format!("Cleared {} tasks from the list", count)
29 }))
30 }
31
32 fn descriptor(&self) -> ToolDescriptor {
33 ToolDescriptor {
34 r#type: "function".to_string(),
35 function: FunctionDescriptor {
36 name: "clear_tasks".to_string(),
37 description: "Remove all tasks from the task list.".to_string(),
38 parameters: json!({
39 "type": "object",
40 "properties": {}
41 }),
42 },
43 }
44 }
45 fn clone_box(&self) -> Box<dyn LlmTool> {
46 Box::new(self.clone())
47 }
48}