Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Use Sub-Agent Delegation

Use this when one agent orchestrates other agents through built-in delegation tools.

What is auto-wired

By default, AgentOs::resolve(...) wires these tools and behaviors:

  • tools: agent_run, agent_stop, agent_output
  • behaviors: agent_tools, agent_recovery

No manual plugin registration is required for baseline delegation.

Steps

  1. Define worker agents and orchestrator.
let os = AgentOs::builder()
    .with_agent_spec(AgentDefinitionSpec::local_with_id("writer", AgentDefinition::new("deepseek-chat")
            .with_excluded_tools(vec!["agent_run".to_string(), "agent_stop".to_string()]),))
    .with_agent_spec(AgentDefinitionSpec::local_with_id("reviewer", AgentDefinition::new("deepseek-chat")
            .with_excluded_tools(vec!["agent_run".to_string(), "agent_stop".to_string()]),))
    .with_agent_spec(AgentDefinitionSpec::local_with_id("orchestrator", AgentDefinition::new("deepseek-chat")
            .with_allowed_agents(vec!["writer".to_string(), "reviewer".to_string()]),))
    .build()?;
  1. In orchestrator prompt/tool flow, call delegation tools.
  • start or resume: agent_run
  • stop background run tree: agent_stop
  • fetch output snapshot: agent_output
  1. Choose foreground/background execution per agent_run call.
  • background=false: parent waits and receives child progress
  • background=true: child runs asynchronously and can be resumed/stopped later

Verify

  • Orchestrator can call agent_run for allowed child agents.
  • Child run status transitions are visible (running, completed, failed, stopped).
  • agent_output returns child-thread outputs for the requested run_id.

Common Errors

  • Target agent filtered by allowed_agents / excluded_agents.
  • Worker agents accidentally retain delegation tools and recurse unexpectedly.
  • Background runs left running without agent_stop/resume policy.
  • No dedicated UI starter focuses on sub-agents yet; use crates/tirea-agentos/tests/real_multi_subagent_deepseek.rs for the main end-to-end example

Key Files

  • crates/tirea-agentos/src/runtime/agent_tools/manager.rs
  • crates/tirea-agentos/src/runtime/agent_tools/tools/
  • crates/tirea-agentos/tests/real_multi_subagent_deepseek.rs