Subagents
ox-core delegates self-contained tasks through the unified Agent and SpawnSpec abstraction in ox_core::subagent. A spawned subagent is a regular Agent instance with its own ToolContext, optional tool allowlist, and depth limit.
SpawnSpec
Section titled “SpawnSpec”SpawnSpec configures how AgentSpawner::spawn runs a child Agent:
| Field | Type | Default | Description |
|---|---|---|---|
prompt |
String |
Required | Initial user prompt sent to the spawned agent |
context |
SpawnContext |
SpawnContext::Fresh |
Fresh for a clean history, or Fork(Vec<Message>) to continue |
lifecycle |
SpawnLifecycle |
SpawnLifecycle::OneShot |
OneShot drops history on return, Persistent returns messages |
cwd |
PathBuf |
Required | Working directory for the child ToolContext |
model |
Option<String> |
Spawner default | Wire model identifier override |
system_prompt |
Option<String> |
None |
Optional system instruction override |
allowed_tools |
Option<Vec<String>> |
All registered tools | Optional allowlist of tool names exposed to the child agent |
max_turns |
Option<usize> |
Spawner default (32) |
Maximum model turns before the child loop stops |
max_depth |
Option<usize> |
Spawner default (3) |
Maximum nesting depth for recursive delegation |
Depth Enforcement and Tool Filtering
Section titled “Depth Enforcement and Tool Filtering”AgentSpawner tracks current_depth (starting at 0) and rejects any spawn where current_depth >= max_depth with SpawnError::MaxDepthExceeded.
When allowed_tools is set, only tools whose names appear in the allowlist are copied into the child ToolRegistry. If invoke_subagent is included in the child registry, AgentSpawner automatically re-registers it with current_depth + 1 so nested subagents inherit the remaining depth budget.
invoke_subagent Tool
Section titled “invoke_subagent Tool”InvokeSubagentTool implements Tool under the name invoke_subagent so any Agent can delegate tasks through the same AgentSpawner pipeline.
| Argument | Type | Default | Description |
|---|---|---|---|
prompt |
string |
Required | Non-empty task instructions for the subagent |
model |
string |
None | Model override for this delegation |
system_prompt |
string |
None | System prompt override for this delegation |
allowed_tools |
string[] |
None | Allowlist of tool names exposed to the subagent |
max_turns |
integer (≥ 1) |
None | Maximum number of model turns for the subagent |
On success, invoke_subagent returns the child’s final assistant text. Validation errors return ToolError::InvalidArgs, while runtime or depth-limit failures return a tool error output so the parent model can recover.