bamboo_engine/runtime/task_evaluation/
schema.rs1use bamboo_agent_core::tools::{FunctionSchema, ToolSchema};
2use serde_json::json;
3
4pub fn get_task_evaluation_tools() -> Vec<ToolSchema> {
6 vec![ToolSchema {
7 schema_type: "function".to_string(),
8 function: FunctionSchema {
9 name: "update_task_item".to_string(),
10 description: "Update the status of a task item based on evaluation".to_string(),
11 parameters: json!({
12 "type": "object",
13 "properties": {
14 "item_id": {
15 "type": "string",
16 "description": "The ID of the task item to update"
17 },
18 "status": {
19 "type": "string",
20 "enum": ["completed", "blocked"],
21 "description": "New status for the item"
22 },
23 "notes": {
24 "type": "string",
25 "description": "Brief explanation of why the status changed"
26 },
27 "evidence": {
28 "type": "string",
29 "description": "Optional concrete evidence that supports this status decision"
30 },
31 "blocker": {
32 "type": "string",
33 "description": "Optional blocker summary when status is blocked"
34 },
35 "criteria_met": {
36 "type": "array",
37 "items": {
38 "type": "string",
39 "pattern": "^(c\\d+|criterion[_-]\\d+)$"
40 },
41 "description": "Optional list of satisfied completion criteria represented by criterion IDs such as c1/c2"
42 }
43 },
44 "required": ["item_id", "status"]
45 }),
46 },
47 }]
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_get_task_evaluation_tools_returns_tool() {
56 let tools = get_task_evaluation_tools();
57 assert_eq!(tools.len(), 1);
58 }
59
60 #[test]
61 fn test_get_task_evaluation_tools_schema_type() {
62 let tools = get_task_evaluation_tools();
63 assert_eq!(tools[0].schema_type, "function");
64 }
65
66 #[test]
67 fn test_get_task_evaluation_tools_function_name() {
68 let tools = get_task_evaluation_tools();
69 assert_eq!(tools[0].function.name, "update_task_item");
70 }
71
72 #[test]
73 fn test_get_task_evaluation_tools_function_description() {
74 let tools = get_task_evaluation_tools();
75 assert!(tools[0].function.description.contains("Update"));
76 assert!(tools[0].function.description.contains("task item"));
77 }
78
79 #[test]
80 fn test_get_task_evaluation_tools_parameters_structure() {
81 let tools = get_task_evaluation_tools();
82 let params = &tools[0].function.parameters;
83
84 assert_eq!(params["type"], "object");
85 assert!(params["properties"].is_object());
86 }
87
88 #[test]
89 fn test_get_task_evaluation_tools_item_id_parameter() {
90 let tools = get_task_evaluation_tools();
91 let item_id = &tools[0].function.parameters["properties"]["item_id"];
92
93 assert_eq!(item_id["type"], "string");
94 assert!(item_id["description"].is_string());
95 }
96
97 #[test]
98 fn test_get_task_evaluation_tools_status_parameter() {
99 let tools = get_task_evaluation_tools();
100 let status = &tools[0].function.parameters["properties"]["status"];
101
102 assert_eq!(status["type"], "string");
103 assert!(status["enum"].is_array());
104
105 let enum_values = status["enum"].as_array().unwrap();
106 assert!(enum_values.contains(&json!("completed")));
107 assert!(enum_values.contains(&json!("blocked")));
108 }
109
110 #[test]
111 fn test_get_task_evaluation_tools_notes_parameter() {
112 let tools = get_task_evaluation_tools();
113 let notes = &tools[0].function.parameters["properties"]["notes"];
114
115 assert_eq!(notes["type"], "string");
116 assert!(notes["description"].is_string());
117 }
118
119 #[test]
120 fn test_get_task_evaluation_tools_required_fields() {
121 let tools = get_task_evaluation_tools();
122 let required = tools[0].function.parameters["required"].as_array().unwrap();
123
124 assert_eq!(required.len(), 2);
125 assert!(required.contains(&json!("item_id")));
126 assert!(required.contains(&json!("status")));
127 assert!(!required.contains(&json!("notes"))); assert!(!required.contains(&json!("evidence")));
129 assert!(!required.contains(&json!("blocker")));
130 assert!(!required.contains(&json!("criteria_met")));
131 }
132
133 #[test]
134 fn test_get_task_evaluation_tools_all_properties() {
135 let tools = get_task_evaluation_tools();
136 let props = tools[0].function.parameters["properties"]
137 .as_object()
138 .unwrap();
139
140 assert_eq!(props.len(), 6);
141 assert!(props.contains_key("item_id"));
142 assert!(props.contains_key("status"));
143 assert!(props.contains_key("notes"));
144 assert!(props.contains_key("evidence"));
145 assert!(props.contains_key("blocker"));
146 assert!(props.contains_key("criteria_met"));
147 }
148}