mojentic 3.0.0

An LLM integration framework for Rust
Documentation
use super::task_list::TaskList;
use crate::error::Result;
use crate::llm::tools::{FunctionDescriptor, LlmTool, ToolDescriptor};
use async_trait::async_trait;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

/// Tool for clearing all tasks from the ephemeral task manager list
#[derive(Clone)]
pub struct ClearTasksTool {
    task_list: Arc<Mutex<TaskList>>,
}

impl ClearTasksTool {
    /// Creates a new ClearTasksTool with a shared task list
    pub fn new(task_list: Arc<Mutex<TaskList>>) -> Self {
        Self { task_list }
    }
}

#[async_trait]
impl LlmTool for ClearTasksTool {
    async fn run(
        &self,
        _args: &HashMap<String, Value>,
        _ctx: &crate::llm::tools::ToolRunCtx,
    ) -> Result<Value> {
        let mut task_list = self.task_list.lock().unwrap();
        let count = task_list.clear_tasks();

        Ok(json!({
            "count": count,
            "summary": format!("Cleared {} tasks from the list", count)
        }))
    }

    fn descriptor(&self) -> ToolDescriptor {
        ToolDescriptor {
            r#type: "function".to_string(),
            function: FunctionDescriptor {
                name: "clear_tasks".to_string(),
                description: "Remove all tasks from the task list.".to_string(),
                parameters: json!({
                    "type": "object",
                    "properties": {}
                }),
            },
        }
    }
    fn clone_box(&self) -> Box<dyn LlmTool> {
        Box::new(self.clone())
    }
}