Skip to main content

adk_tool/builtin/
exit_loop.rs

1use adk_core::{Result, Tool, ToolContext};
2use async_trait::async_trait;
3use serde_json::{Value, json};
4use std::sync::Arc;
5
6/// A control-flow tool that signals a loop agent to exit its iteration cycle.
7#[derive(Default)]
8pub struct ExitLoopTool;
9
10impl ExitLoopTool {
11    /// Create a new `ExitLoopTool`.
12    pub fn new() -> Self {
13        Self
14    }
15}
16
17#[async_trait]
18impl Tool for ExitLoopTool {
19    fn name(&self) -> &str {
20        "exit_loop"
21    }
22
23    fn description(&self) -> &str {
24        "Exits the loop.\nCall this function only when you are instructed to do so."
25    }
26
27    async fn execute(&self, ctx: Arc<dyn ToolContext>, _args: Value) -> Result<Value> {
28        let mut actions = ctx.actions();
29        actions.escalate = true;
30        actions.skip_summarization = true;
31        ctx.set_actions(actions);
32        Ok(json!({}))
33    }
34}