astrid_tools/subagent_spawner.rs
1//! Sub-agent spawner trait for dependency inversion.
2//!
3//! `astrid-tools` defines this trait; `astrid-runtime` implements it.
4//! This avoids a circular dependency between the two crates.
5
6use std::time::Duration;
7
8/// Request to spawn a sub-agent.
9#[derive(Debug, Clone)]
10pub struct SubAgentRequest {
11 /// Short description of the task (shown in status/logs).
12 pub description: String,
13 /// Detailed instructions for the sub-agent.
14 pub prompt: String,
15 /// Optional timeout (falls back to executor default if `None`).
16 pub timeout: Option<Duration>,
17}
18
19/// Result returned by a completed sub-agent.
20#[derive(Debug, Clone)]
21pub struct SubAgentResult {
22 /// Whether the sub-agent completed successfully.
23 pub success: bool,
24 /// Output text from the sub-agent (last assistant message).
25 pub output: String,
26 /// Wall-clock duration in milliseconds.
27 pub duration_ms: u64,
28 /// Number of tool calls the sub-agent made.
29 pub tool_calls: usize,
30 /// Error message (if `success` is false).
31 pub error: Option<String>,
32}
33
34/// Trait for spawning sub-agents from built-in tools.
35///
36/// Implemented by `SubAgentExecutor` in `astrid-runtime`.
37/// Injected into `ToolContext` as `Arc<dyn SubAgentSpawner>`.
38#[async_trait::async_trait]
39pub trait SubAgentSpawner: Send + Sync {
40 /// Spawn a sub-agent and wait for its result.
41 async fn spawn(&self, request: SubAgentRequest) -> Result<SubAgentResult, String>;
42}