swiftide_agents/tools/
control.rs

1//! Control tools manage control flow during agent's lifecycle.
2use anyhow::Result;
3use async_trait::async_trait;
4use std::borrow::Cow;
5use swiftide_core::{
6    chat_completion::{errors::ToolError, Tool, ToolOutput, ToolSpec},
7    AgentContext,
8};
9
10// TODO: Cannot use macros in our own crates because of import shenanigans
11#[derive(Clone, Debug, Default)]
12pub struct Stop {}
13
14#[async_trait]
15impl Tool for Stop {
16    async fn invoke(
17        &self,
18        _agent_context: &dyn AgentContext,
19        _raw_args: Option<&str>,
20    ) -> Result<ToolOutput, ToolError> {
21        Ok(ToolOutput::Stop)
22    }
23
24    fn name(&self) -> Cow<'_, str> {
25        "stop".into()
26    }
27
28    fn tool_spec(&self) -> ToolSpec {
29        ToolSpec::builder()
30            .name("stop")
31            .description("When you have completed, or cannot complete, your task, call this")
32            .build()
33            .unwrap()
34    }
35}
36
37impl From<Stop> for Box<dyn Tool> {
38    fn from(val: Stop) -> Self {
39        Box::new(val)
40    }
41}