Skip to content

Implement Task tool for spawning subagents #78

@evansenter

Description

@evansenter

Summary

Add a task tool that spawns clemini subprocesses to handle delegated work, similar to Claude Code's Task tool.

Core Concept

Task is simple subprocess spawning:

  1. Spawn subprocess with prompt → cargo run -- -p "do X"
  2. Capture output → stdout/stderr
  3. Return result → JSON response

Building Blocks Already Available

Implementation

// Pseudocode
fn task_tool(prompt: &str, background: bool) -> Result<Value> {
    let child = Command::new("cargo")
        .args(["run", "--", "-p", prompt])
        .spawn()?;
    
    if background {
        // Store handle, return task_id for later retrieval
        Ok(json!({"task_id": "abc123", "status": "running"}))
    } else {
        // Wait and return output
        let output = child.wait_with_output()?;
        Ok(json!({"output": String::from_utf8_lossy(&output.stdout)}))
    }
}

Tool Schema

struct TaskTool {
    /// The prompt/task to give to the subagent
    prompt: String,
    
    /// Run in background (default: false)
    /// If true, returns task_id immediately
    /// If false, waits for completion and returns output
    #[serde(default)]
    background: bool,
    
    /// Optional: specific subagent type (future: explore, plan, etc.)
    #[serde(default)]
    subagent_type: Option<String>,
}

Return Values

Foreground (background=false):

{
  "status": "completed",
  "output": "Task result here...",
  "exit_code": 0
}

Background (background=true):

{
  "task_id": "task_abc123",
  "status": "running"
}

Task Management

Reuse existing background shell infrastructure:

  • Store task handles in same registry as background bash
  • KillShell can kill tasks
  • Add TaskOutput tool to retrieve results (or extend existing mechanism)

No Architectural Changes Needed

This is pure process management. #59 (streaming-first) is an optimization for complex multi-agent workflows with real-time streaming - not a prerequisite.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions