Skip to main content

steer_tools/tools/
dispatch_agent.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::ToolSpec;
6use crate::error::{ToolExecutionError, WorkspaceOpError};
7use crate::result::AgentResult;
8
9pub const DISPATCH_AGENT_TOOL_NAME: &str = "dispatch_agent";
10
11pub struct DispatchAgentToolSpec;
12
13impl ToolSpec for DispatchAgentToolSpec {
14    type Params = DispatchAgentParams;
15    type Result = AgentResult;
16    type Error = DispatchAgentError;
17
18    const NAME: &'static str = DISPATCH_AGENT_TOOL_NAME;
19    const DISPLAY_NAME: &'static str = "Dispatch Agent";
20
21    fn execution_error(error: Self::Error) -> ToolExecutionError {
22        ToolExecutionError::DispatchAgent(error)
23    }
24}
25
26#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
27#[serde(tag = "location", rename_all = "snake_case")]
28pub enum WorkspaceTarget {
29    Current,
30    New { name: String },
31}
32
33#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
34#[serde(tag = "session", rename_all = "snake_case")]
35pub enum DispatchAgentTarget {
36    New {
37        workspace: WorkspaceTarget,
38        #[serde(default)]
39        agent: Option<String>,
40    },
41    Resume {
42        session_id: String,
43    },
44}
45
46#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
47pub struct DispatchAgentParams {
48    pub prompt: String,
49    pub target: DispatchAgentTarget,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Error)]
53#[serde(tag = "code", content = "details", rename_all = "snake_case")]
54pub enum DispatchAgentError {
55    #[error("{0}")]
56    Workspace(WorkspaceOpError),
57
58    #[error("workspace unavailable: {message}")]
59    WorkspaceUnavailable { message: String },
60
61    #[error("sub-agent failed: {message}")]
62    SpawnFailed { message: String },
63
64    #[error("failed to load session {session_id}: {message}")]
65    SessionLoadFailed { session_id: String, message: String },
66
67    #[error("session {session_id} is missing a SessionCreated event")]
68    MissingSessionCreatedEvent { session_id: String },
69
70    #[error("session {session_id} is not a child of current session {parent_session_id}")]
71    InvalidParentSession {
72        session_id: String,
73        parent_session_id: String,
74    },
75
76    #[error("failed to open workspace for session {session_id}: {message}")]
77    WorkspaceOpenFailed { session_id: String, message: String },
78}