mojentic/llm/tools/ephemeral_task_manager/
prepend_task.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 PrependTaskTool {
11 task_list: Arc<Mutex<TaskList>>,
12}
13
14impl PrependTaskTool {
15 pub fn new(task_list: Arc<Mutex<TaskList>>) -> Self {
17 Self { task_list }
18 }
19}
20
21impl LlmTool for PrependTaskTool {
22 fn run(&self, args: &HashMap<String, Value>) -> Result<Value> {
23 let description =
24 args.get("description").and_then(|v| v.as_str()).unwrap_or("").to_string();
25
26 let mut task_list = self.task_list.lock().unwrap();
27 let task = task_list.prepend_task(description);
28
29 Ok(json!({
30 "id": task.id,
31 "description": task.description,
32 "status": task.status.as_str(),
33 "summary": format!("Task '{}' prepended successfully", task.id)
34 }))
35 }
36
37 fn descriptor(&self) -> ToolDescriptor {
38 ToolDescriptor {
39 r#type: "function".to_string(),
40 function: FunctionDescriptor {
41 name: "prepend_task".to_string(),
42 description: "Prepend a new task to the beginning of the task list with a description. The task will start with 'pending' status.".to_string(),
43 parameters: json!({
44 "type": "object",
45 "properties": {
46 "description": {
47 "type": "string",
48 "description": "The description of the task"
49 }
50 },
51 "required": ["description"]
52 }),
53 },
54 }
55 }
56 fn clone_box(&self) -> Box<dyn LlmTool> {
57 Box::new(self.clone())
58 }
59}