rs_adk/tools/
exit_loop.rs1use async_trait::async_trait;
7
8use crate::error::ToolError;
9use crate::tool::ToolFunction;
10
11#[derive(Debug, Clone, Default)]
16pub struct ExitLoopTool;
17
18impl ExitLoopTool {
19 pub fn new() -> Self {
21 Self
22 }
23}
24
25#[async_trait]
26impl ToolFunction for ExitLoopTool {
27 fn name(&self) -> &str {
28 "exit_loop"
29 }
30
31 fn description(&self) -> &str {
32 "Exits the current loop. Call this function only when you are instructed to do so."
33 }
34
35 fn parameters(&self) -> Option<serde_json::Value> {
36 None
37 }
38
39 async fn call(&self, _args: serde_json::Value) -> Result<serde_json::Value, ToolError> {
40 Ok(serde_json::json!({
43 "status": "loop_exited",
44 "message": "Loop has been exited successfully."
45 }))
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn tool_name_and_description() {
55 let tool = ExitLoopTool::new();
56 assert_eq!(tool.name(), "exit_loop");
57 assert!(tool.description().contains("Exit"));
58 }
59
60 #[test]
61 fn no_parameters() {
62 let tool = ExitLoopTool::new();
63 assert!(tool.parameters().is_none());
64 }
65
66 #[tokio::test]
67 async fn call_returns_success() {
68 let tool = ExitLoopTool::new();
69 let result = tool.call(serde_json::json!({})).await.unwrap();
70 assert_eq!(result["status"], "loop_exited");
71 }
72}