mojentic/llm/tools/ephemeral_task_manager/
start_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)]
12pub struct StartTaskTool {
13 task_list: Arc<Mutex<TaskList>>,
14}
15
16impl StartTaskTool {
17 pub fn new(task_list: Arc<Mutex<TaskList>>) -> Self {
19 Self { task_list }
20 }
21}
22
23impl LlmTool for StartTaskTool {
24 fn run(&self, args: &HashMap<String, Value>) -> Result<Value> {
25 let task_id = args.get("id").and_then(|v| v.as_u64()).unwrap_or(0) as usize;
26
27 let mut task_list = self.task_list.lock().unwrap();
28 let task = task_list.start_task(task_id)?;
29
30 Ok(json!({
31 "id": task.id,
32 "description": task.description,
33 "status": task.status.as_str(),
34 "summary": format!("Task '{}' started successfully", task_id)
35 }))
36 }
37
38 fn descriptor(&self) -> ToolDescriptor {
39 ToolDescriptor {
40 r#type: "function".to_string(),
41 function: FunctionDescriptor {
42 name: "start_task".to_string(),
43 description: "Start a task by changing its status from PENDING to IN_PROGRESS."
44 .to_string(),
45 parameters: json!({
46 "type": "object",
47 "properties": {
48 "id": {
49 "type": "integer",
50 "description": "The ID of the task to start"
51 }
52 },
53 "required": ["id"]
54 }),
55 },
56 }
57 }
58 fn clone_box(&self) -> Box<dyn LlmTool> {
59 Box::new(self.clone())
60 }
61}