Skip to main content

mojentic/llm/tools/ephemeral_task_manager/
clear_tasks.rs

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