ai_chain/tools/tools/
exit.rs1use crate::tools::description::{Describe, Format, ToolDescription};
2use crate::tools::tool::{Tool, ToolError};
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7pub struct ExitTool {}
9
10impl ExitTool {
11 pub fn new() -> Self {
13 ExitTool {}
14 }
15}
16
17impl Default for ExitTool {
18 fn default() -> Self {
19 Self::new()
20 }
21}
22
23#[derive(Serialize, Deserialize)]
25pub struct ExitToolInput {
26 status_code: i32,
27}
28
29#[derive(Serialize, Deserialize)]
31pub struct ExitToolOutput {}
32
33impl Describe for ExitToolInput {
34 fn describe() -> Format {
35 vec![("status_code", "<integer> UNIX status to exit with").into()].into()
36 }
37}
38
39impl Describe for ExitToolOutput {
40 fn describe() -> Format {
41 vec![].into()
42 }
43}
44
45#[derive(Debug, Error)]
46pub enum ExitToolError {
47 #[error(transparent)]
48 YamlError(#[from] serde_yaml::Error),
49 #[error(transparent)]
50 IOError(#[from] std::io::Error),
51}
52
53impl ToolError for ExitToolError {}
54
55#[async_trait]
56impl Tool for ExitTool {
57 type Input = ExitToolInput;
58 type Output = ExitToolOutput;
59 type Error = ExitToolError;
60 async fn invoke_typed(&self, input: &ExitToolInput) -> Result<ExitToolOutput, ExitToolError> {
62 std::process::exit(input.status_code);
63 }
64 fn description(&self) -> ToolDescription {
66 ToolDescription::new(
67 "ExitTool",
68 "Exits the program with the given status code",
69 "Use this when your task is complete and you want to exit the program.",
70 ExitToolInput::describe(),
71 ExitToolOutput::describe(),
72 )
73 }
74}