agent_base/tool/
auto_continue.rs1use async_trait::async_trait;
2use serde_json::{Value, json};
3
4use crate::tool::{Tool, ToolContext, ToolControlFlow, ToolOutput};
5use crate::types::AgentResult;
6
7#[derive(Clone, Debug, Default)]
14pub struct AutoContinueTool;
15
16impl AutoContinueTool {
17 pub fn new() -> Self {
18 Self
19 }
20}
21
22#[async_trait]
23impl Tool for AutoContinueTool {
24 fn name(&self) -> &'static str {
25 "request_auto_continue"
26 }
27
28 fn definition(&self) -> Value {
29 json!({
30 "type": "function",
31 "function": {
32 "name": "request_auto_continue",
33 "description": "When you encounter an error in the previous tool execution and have found a solution or retry strategy, or when you need to execute multiple long tasks in sequence, call this tool to request the system to automatically continue to the next turn instead of stopping and waiting for user reply. This tool is only for making the request; you still need to describe your solution in the prompt.",
34 "parameters": {
35 "type": "object",
36 "properties": {
37 "reason": {
38 "type": "string",
39 "description": "A brief reason for requesting auto-continue, e.g. 'network error, trying alternative source'"
40 }
41 },
42 "required": ["reason"]
43 }
44 }
45 })
46 }
47
48 fn metadata(&self) -> crate::tool::ToolMetadata {
49 crate::tool::ToolMetadata {
50 name: self.name().to_string(),
51 description: "Request automatic continuation to the next turn without waiting for user input."
52 .to_string(),
53 origin: "agent-base".to_string(),
54 version: env!("CARGO_PKG_VERSION").to_string(),
55 requirements: vec![],
56 }
57 }
58
59 async fn call(&self, args: &Value, _ctx: &ToolContext) -> AgentResult<ToolOutput> {
60 let reason = args
61 .get("reason")
62 .and_then(Value::as_str)
63 .unwrap_or("no reason provided");
64
65 Ok(ToolOutput {
66 summary: format!("Auto-continue request received. Reason: {}", reason),
67 raw: Some(json!({
68 "action": "auto_continue",
69 "reason": reason,
70 })),
71 control_flow: ToolControlFlow::Continue,
72 truncation: None,
73 })
74 }
75}