crabtalk_runtime/task.rs
1//! Tool schema for the delegate tool.
2//!
3//! Schema types live here. Dispatch logic is server-specific and lives in
4//! the [`Host`](crate::host::Host) implementation.
5
6use serde::Deserialize;
7use wcore::{
8 agent::{AsTool, ToolDescription},
9 model::Tool,
10};
11
12#[derive(Deserialize, schemars::JsonSchema)]
13pub struct Delegate {
14 /// List of tasks to run in parallel. Each task has an agent name and a message.
15 pub tasks: Vec<DelegateTask>,
16 /// If true, return immediately with task IDs instead of waiting for completion.
17 /// Results arrive via agent completion events (`agent:{name}:done`).
18 #[serde(default)]
19 pub background: bool,
20}
21
22#[derive(Deserialize, schemars::JsonSchema)]
23pub struct DelegateTask {
24 /// Target agent name. Auto-generated if empty and system_prompt is set.
25 #[serde(default)]
26 pub agent: String,
27 /// Message/instruction for the target agent.
28 pub message: String,
29 /// System prompt for an ephemeral agent. When set, creates a temporary
30 /// agent with this prompt instead of targeting a pre-registered agent.
31 #[serde(default)]
32 pub system_prompt: Option<String>,
33 /// Working directory for this task. Defaults to the parent's CWD.
34 #[serde(default)]
35 pub cwd: Option<String>,
36}
37
38impl ToolDescription for Delegate {
39 const DESCRIPTION: &'static str = "Delegate tasks to other agents. Runs all tasks in parallel. Set background=true to return immediately with task IDs — results arrive via agent completion events.";
40}
41
42pub fn tools() -> Vec<Tool> {
43 vec![Delegate::as_tool()]
44}