Skip to main content

Module sub_agent

Module sub_agent 

Source
Expand description

Sub-agent tool — delegates tasks to a child agent loop.

The SubAgentTool implements AgentTool and internally runs agent_loop() with its own system prompt, tools, and provider. The parent LLM invokes it like any other tool, passing a natural-language task string.

§Design

  • Context isolation: each invocation starts a fresh conversation
  • Nesting supported: sub-agents can contain other SubAgentTools for recursive delegation (use with_max_turns() to bound depth)
  • Cancellation propagation: the parent’s cancel token is forwarded
  • Event forwarding: sub-agent events stream to the parent via on_update
  • Spend reporting: the sub-agent’s SessionStats — its own usage and, recursively, its own sub-agents’ — reach the parent loop, which keeps them in a separate SessionStats::sub_agents bucket. Failed runs included.

§Example

use yoagent::sub_agent::SubAgentTool;
use yoagent::provider::ModelConfig;

// Provider selected from the config's protocol; key from ANTHROPIC_API_KEY.
let researcher = SubAgentTool::from_config(
    "researcher",
    ModelConfig::anthropic("claude-sonnet-5", "Sonnet 5"),
)
.with_description("Searches codebases and documents")
.with_system_prompt("You are a research assistant.");

Structs§

SubAgentTool
A tool that delegates work to a child agent loop.