Quick Start
Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_factory | Callable | None | Custom function to create agents |
allowed_agents | List[str] | None | Restrict which agent types can be spawned |
max_depth | int | 3 | Maximum subagent nesting depth |
default_llm | str | None | Default LLM model for subagents |
default_permission_mode | str | None | Default permission mode |
Spawn Parameters
When calling the subagent function:| Parameter | Type | Required | Description |
|---|---|---|---|
task | str | ✅ Yes | Task description for the subagent |
agent_name | str | No | Specific agent type to use |
context | str | No | Additional context for the task |
tools | List[str] | No | Tools to give the subagent |
llm | str | No | LLM model override |
permission_mode | str | No | Permission mode override |
background | bool | No | When True, enqueue on the background job runner and return immediately with a job_id |
deliver | str | No | Delivery target for a background job’s result — e.g. "origin", "all", or "telegram:12345". Only meaningful with background=True. Empty (default) keeps jobs pull-only. |
platform | str | No | Origin platform (e.g. "telegram") — captured for deliver="origin". Usually supplied by the gateway context automatically. |
chat_id | str | No | Origin chat/channel ID — captured for deliver="origin". |
thread_id | str | No | Optional origin thread ID. |
session_id | str | No | Optional origin session ID to preserve context. |
Deliver Background Job Results Back to Chat
When a background job finishes, its result can be pushed back to the user’s chat automatically — no polling required.Delivery targets
| Target | Behaviour |
|---|---|
"" (empty, default) | Pull-only — use subagent_result(job_id) to collect |
"origin" | Deliver to the chat that started the job (requires parent to have an origin) |
"all" | Deliver to all channels registered on the gateway |
"platform:chat_id" | Deliver to a specific platform/channel (e.g. "telegram:123456") |
"platform:chat_id:thread_id" | Deliver to a specific thread |
deliver="origin" requires the parent to have an origin context — inside a BotOS chat it does. From a plain script with no active chat context, the pull-only default (deliver="") applies. Failures are also delivered as a failure notice, so the user is never left waiting silently.deliver vocabulary mirrors the scheduling tool’s deliver= parameter. See JOB_COMPLETED Hook for the hook that fires on completion.
Backward compatibility: with no deliver target set, behaviour is byte-for-byte identical to before — pull-only via subagent_result.
Background Mode
Run a long subtask without blocking the parent agent. Use it for full test runs, broad codebase scans, or large refactors — anything where the parent agent should keep working instead of waiting.When to use background mode
Background return shapes
spawn_subagent(..., background=True) returns a handle (not a final result):
subagent_result(job_id) polls without blocking:
subagent_result(job_id, wait=True) blocks until done:
Depth (
max_depth), allowed_agents, and per-call tools / llm / permission_mode apply to background subagents identically to synchronous ones. Background jobs run on a worker thread but inherit the same scoping the parent set up.Model Selection
Model selection priority:- Per-call
llmparameter - Highest priority default_llmfrom tool creation - Fallback- Agent’s default model - Final fallback
Permission Modes
| Mode | Value | Description |
|---|---|---|
default | Standard | Normal permission checking |
accept_edits | Auto-accept | Auto-accept file edits |
dont_ask | Auto-deny | Auto-deny all prompts |
bypass_permissions | Bypass | Skip all checks |
plan | Read-only | Exploration mode only |
Custom Agent Factory
Create agents with custom configurations:Depth Limiting
Prevent infinite subagent recursion:Agent Restrictions
Limit which agent types can be spawned:Result Structure
Synchronous calls (background=False, the default) return the final result directly:
subagent_result shapes.
Best Practices
Use appropriate models
Use appropriate models
Use smaller models like
gpt-4o-mini for simple tasks and larger models for complex analysis.Set permission modes
Set permission modes
Always set
permission_mode="plan" for exploration tasks to prevent accidental modifications.Limit allowed agents
Limit allowed agents
Restrict
allowed_agents to only the agent types needed for your use case.Handle errors
Handle errors
Always check
result["success"] before accessing the output.Use background mode for long tasks
Use background mode for long tasks
For test suites, broad scans, or refactors, use
background=True so the parent agent can keep working and collect results with subagent_result.Related
Subagent Delegation
Advanced subagent management
Permission Modes
Permission mode details
JOB_COMPLETED Hook
Hook that fires when a background job finishes — success or failure

