Subagents
Atomic bundles@bastani/subagents, an extension for bounded specialist delegation with separate context while the parent remains in control. Use a single agent or parallel fan-out when isolation or a specialist pass materially helps with locating code, analyzing behavior, researching references, reproducing actual failures, or simplifying code. Keep interactive, exploratory, conceptual, and conversation-led work inline when direct user steering is more useful.
You do not need to install anything separately when you use @bastani/atomic.
Start with natural language
Ask Atomic to coordinate subagents in plain language:Subagent execution is non-interactive
Supported subagent launches start immediately without opening a preview/editor prompt or waiting for terminal input. This applies to single, parallel, forked, fanout, prompt-template, and human-entered/run and /parallel execution. Ask any necessary questions in the parent conversation before delegating.
The human slash commands remain registered and continue to use their separate parsing and event-bridge path, including fork flags.
Prompt-template delegation comes from the separately installed pi-prompt-template-model extension, whose requestDelegatedRun emits prompt-template:subagent:request. If that caller must survive an extension reload, import registerPromptTemplateBridgeRequestSettlement from @bastani/subagents, register it before the emit, and unregister it from the normal response, cancellation, or abort path. The hook rejects the caller only when the old bridge drops a stale response emit; normal completion still arrives through prompt-template:subagent:response. Atomic cannot register this opt-in for an out-of-tree emitter.
Subagents now run and return their results directly. Atomic does not infer acceptance gates from prompt wording, inject acceptance-report instructions into child prompts, parse or strip acceptance-report blocks, or reject completed child runs because changed-file, test, or review evidence is missing. Put any evidence or validation requirements directly in the task text you give the parent or child agent.
Foreground supervisor coordination
When a foreground child sendsintercom.ask, intercom.send, or contact_supervisor coordination, Atomic first probes for the exact foreground owner. Only an exact live child reserves the request; Atomic then sends a generation-scoped detach commit and waits for that child to acknowledge it before placing the message in the parent’s model-visible steering queue. This first-refusal ordering also applies when the parent is a busy workflow stage: detach completes before the request enters the stage AgentSession generation boundary, breaking the child-waits-for-reply / stage-waits-for-child cycle. Blocking need_decision and interview_request calls remain actionable through Intercom’s pending/reply tracker, and the exact threaded reply resumes the retained child without delayed duplicate delivery. Unmatched messages retain existing routing—ordinary parents queue until idle, while open workflow stages fall back to their native generation admission.
Only the matching foreground child can authorize release of the parent subagent tool. For a parallel foreground group, that accepted commit releases foreground supervision for every active sibling as one unit, so a long-running sibling cannot keep a blocking child request trapped behind the aggregate tool call; tasks still waiting behind the concurrency limit are skipped and never launched unsupervised. Children are in-process AgentSession instances governed by the shared Rust control plane: there is no child OS process, idle watchdog, stdout drain, or detached placeholder to recover. A detached call becomes continued through continue_detached; its canonical child remains live and later delivers one terminal result. Fire-and-forget intercom.send and progress_update also release foreground supervision promptly, but do not create a reply waiter.
Blocking coordination is race-safe: a session holds at most one outbound reply waiter, and concurrent blocking requests (parallel intercom.ask calls, or intercom.ask racing contact_supervisor) settle atomically. One request wins the reservation; every other concurrent call returns a normal “Already waiting for a reply” tool error without crashing the agent process or disturbing the pending ask. Cancellation and send failures release only their own waiter, and threaded replies still resolve the exact winning request.
Subagent result announcements are also resilient in sessions that never receive an extension session_start (for example non-interactive in-process child sessions): the lazy Intercom runtime initializes from the most recent turn/tool lifecycle context and delivers self-addressed results locally. If no context is available at all, the relay acknowledges the announcement as undelivered — the subagent tool then falls back to returning results inline — instead of recording connection errors in the session transcript.
Intercom connection remains tool-driven. Foreground launches do not import the heavy Intercom runtime or connect either the parent or bridged child automatically. If live child-to-parent coordination is needed, the parent model should invoke intercom({ action: "status" }) before launch; the child then connects on its first contact_supervisor or intercom call. Cancellation or session replacement still invalidates the handshake generation, so stale acknowledgements cannot surface or detach a child.
Atomic’s implementation adapts the prompt foreground release and later-result recovery contracts proven in nicobailon/pi-subagents commits 1b55c8c, 589e51e, 68fb528, and 9dfe3df; it retains Atomic’s broker and raw-TypeScript architecture rather than copying upstream’s filesystem transport.
Migration from acceptance gates
If you have older subagent calls or custom agents that used the removed gate fields:- Remove
acceptanceproperties fromsubagent()calls, task entries, and parallel task items. Atomic no longer reads these fields. - Remove
completionGuard: falsefrom agent frontmatter and custom agent definitions. The no-mutation completion guard no longer exists, so the override has no effect and management rewrites strip it. - Move validation, command, evidence, review, or residual-risk requirements into the natural-language task text passed to the parent or child agent.
Bundled agents
Atomic currently bundles these agents from@bastani/subagents:
The bundled definitions keep their routing and model frontmatter but use compact, outcome-first bodies: role and goal, success criteria, constraints and tool routes, output contract, and stop rules where applicable. Report-producing agents ground progress claims in tool results and return concise evidence rather than narrating internal reasoning. Read-oriented agents inspect and report.
debugger, code-simplifier, and worker can edit files, so give them an explicit scope and validation target. The debugger should finish an in-scope diagnosis by applying and validating the fix, not stop at a proposed patch.
Review compositions
Atomic does not bundle a single generic review agent. Instead, compose specialists with distinct angles and let the parent session synthesize their findings before applying any fix. Common review angles:
Example request:
/parallel-review, /review-loop, /parallel-research, /parallel-context-build, /parallel-handoff-plan, and /parallel-cleanup. Treat them as reusable compositions, not as separate bundled agent names. Their task templates define the requested outcome, evidence and delegation boundaries, downstream output shape, and an explicit stop rule; preserve those contracts when adapting a template.
Foreground work and control
Foreground subagents stream progress in the conversation and return their results before the call completes. Natural-language examples:interrupt when you want a resumable stop. Use resume for a follow-up to a reachable or retained child. Use doctor for read-only setup diagnostics.
Status, interrupt, list, and resume use the Rust registry and status watch for live children; terminal delivery is an in-memory bounded envelope with the artifact and run-history record persisted once. There is no PID polling, result-claim file, stale-run reconciliation, or detached runner process.
Inside workflow stages, completion delivery observes the stage generation boundary. A completion received before the boundary closes is queued through the stage AgentSession and processed before the stage publishes its terminal snapshot. A completion that arrives after close is routed once to the parent/main chat and cannot reopen or append to the completed stage transcript. Explicit post-mortem stage chat is still available separately.
Live progress and completed results show each step’s resolved model, effective reasoning level, and applied Codex fast-mode marker, including after a model fallback; parallel steps keep their metadata separate.
Orchestrator model and group policy
Atomic applies the same delegation policy to any parent chat or workflow stage that orchestrates subagents. A named agent uses the model and fallback sequence declared by its agent definition, so the orchestrator normally omits the subagent tool’s explicitmodel argument. An override needs either the user’s exact model request or a documented task-specific reason recorded before launch; model diversity alone is not enough.
If an agent declares no model or fallback policy, the orchestrator consults the role guidance in Model selection, then calls workflow({ action: "models" }) when that tool is available. It may pin only a returned fullId and may add a thinking suffix only when the model entry lists that level. When the catalog tool is unavailable, the catalog is empty, or no recommended model is present, the child stays unpinned and the orchestrator reports the limit instead of inventing a model or inspecting credentials.
Each workflow invocation automatically receives one stable, non-"default" Intercom group as typed admission policy. Its stages and delegated children carry that group across single, parallel, and follow-up work unless a call explicitly overrides group. Outside workflows, children inherit the launching session’s resolved group. This isolates workflow runs from unrelated runs and the main chat while contact_supervisor retains its authorized cross-group route.
Context and execution modes
Subagents can run with fresh or forked context:context: "fresh"starts a separate in-process child session with only the task and selected agent context.context: "fork"creates a real branched child session from the parent session leaf. It fails fast if the parent session cannot be forked; it does not silently downgrade to fresh context.
worktree: true can give each child an isolated git worktree so concurrent edits do not clobber each other.
Fresh child sessions use normal Atomic package discovery when an agent omits extensions, so bundled lightweight MCP, web-access, and Intercom wrappers are available just as they are in the parent. An explicit extensions field (including an empty list) intentionally switches the child to extension-allowlist mode and excludes unlisted builtins; it does not inherit the parent’s normal discovery set.
Top-level parallel calls support up to 50 subagents after expanding each task’s optional count. The extension’s parallel.maxTasks setting defaults to 50 and can enforce a lower task limit; parallel.concurrency independently controls how many of those children run at once, while the Rust turn limiter admits at most four running turns per parent.
Subagent tasks, parallel items, and the top-level call accept a group field that sets the spawned child’s Intercom home group, so same-group subagents can intercom each other while staying isolated from other groups. A named string joins that group; true auto-generates one shared UUID group per parallel set. Precedence is explicit subagent group > inherited current-session group > config > "default". Workflow stages carry their runtime-owned invocation group, so children launched without group automatically join the workflow group; callers do not need to copy or generate an ID. In other sessions, omission inherits that launching session’s resolved group. The child group is applied only when the child has Intercom access (the peer intercom tool or subagent-only contact_supervisor tool); a child without Intercom receives no group. contact_supervisor still reaches the supervisor across group boundaries because Atomic requests a broker capability during typed admission and binds the child’s registration to the issuing supervisor. Foreground paths use exact child scopes. The lightweight Intercom wrapper lazy-loads the authorization provider; provider failures abort launch, while hosts without a provider omit supervisor metadata instead of exposing a broken channel.
When a subagent call or parallel task uses a cwd, Atomic validates that working directory before starting the child runtime. Missing or non-directory paths are reported as cwd problems instead of lower-level runtime errors.
Single-agent calls also accept reads: string[] | false. Atomic prepends those files as read context for foreground execution through the same in-process session path, including /run agent[reads=a.md+b.md]. Relative entries resolve against the effective child cwd (including a relative top-level cwd resolved from the parent); absolute entries are unchanged. Invalid values fail before the child session starts.
Single-agent calls accept progress: boolean in foreground and resumed mode. progress: true creates a run-scoped progress.md under isolated subagent artifact storage and instructs the child to maintain it without writing progress.md into the child cwd; progress: false disables an agent’s defaultProgress. When progress is omitted, the agent’s default is inherited, except that inherited progress is suppressed for read-only tasks (progress: true still explicitly opts in). Foreground runs remove this run-owned progress storage after the child exits when artifacts: false, including children temporarily detached for intercom coordination. This is separate from includeProgress: true, which only includes detailed runtime progress telemetry in the final tool result and does not create or maintain a file.
Nested and fanout boundaries
Child-safety boundaries are enforced by typed admission policy and the bundled subagent extension:- In-process child sessions load bundled extensions through normal discovery. The
subagenttool may therefore be registered when the child’s active tool selection permits it, including the default no-allowlist case; an explicit allowlist may omit it. Tool presence does not grant fanout. The bundled subagents skill remains parent-only and is stripped from child prompts, including fanout-authorized children. - Child context is filtered to remove parent orchestration artifacts, old control/status messages, and prior parent
subagenttool calls/results. - Non-fanout children are instructed that they are not the parent orchestrator and must not propose or run subagents.
- Nested fanout is available only for explicitly authorized agents whose resolved tools include
subagent. Authorized fanout children receive narrower instructions that limit delegation to the assigned fanout. - Typed admission policy lets a non-fanout child use only
list,get,status, anddoctor; delegation,resume, andinterruptreceive the fanout refusal. A management-restricted child is also refusedcreate,update, anddelete. - The recursion guard has a hard maximum of five delegated subagent levels. The admitted depth policy may choose a lower value from
0to5; deeper admission is refused rather than inherited from process environment state.
Custom agents
Custom agents are Markdown files with YAML frontmatter and a system prompt body. Keep the body outcome-first and locally complete: state the role or goal, observable success criteria, constraints and context-dependent tool routes, required output shape, and stop conditions. Reserve absolute wording for true invariants, request evidence and conclusions rather than private reasoning, and avoid repeated self-check instructions. Common locations are:
A small custom read-only inspection agent:
Fallback models
Agents can define orderedfallbackModels for retryable provider or model failures such as rate limits, quota/usage-limit exhaustion (for example a provider reporting The usage limit has been reached, or usage_limit_reached/insufficient_quota codes), auth problems, unavailable models, network timeouts, or 5xx errors. Atomic tries the requested primary model first, then configured fallbacks, and finally appends the current user-selected model as the last fallback candidate when available. The main chat and workflow stages share one failure classifier, so auth, model-availability, request-incompatibility, and transport signals are handled consistently. Cancellations, safety refusals, and task/tool failures are never retried on another model.
A candidate that cannot serve the current request — for example an HTTP 400/413/422 bad/unprocessable/payload-too-large request, an unsupported tool or parameter, a context-length/context-window overflow, or a too large / invalid_request error — is treated as request/context incompatible and the fallback sequence advances to the next candidate rather than stopping. This means that if none of the configured candidates are applicable to the request, Atomic falls back to the currently selected user model instead of failing outright.
Model fallback decisions use structured provider and attempt causes. There is no per-attempt idle watchdog, no child wall-clock kill cap, and no timeout-regex classification: a quiet provider response is allowed to finish, and only an explicit termination or provider failure supplies a retryable cause. Numeric process exit codes are not used as an outcome discriminator.
When registry availability shows that a known candidate provider has no configured auth, Atomic records a skipped model attempt before starting the in-process turn. Unknown/custom providers are still attempted, and the current user-selected model appended as the final fallback is never filtered out by this pre-admission check.
Fallbacks do not retry ordinary task failures, validation failures, tool failures, cancellations, or workflow-code errors. Because a fallback may send the same prompt and context to a different provider, choose models that match your cost, privacy, and data-handling requirements.
Each candidate can also carry its own reasoning effort — see Reasoning levels.
Reasoning levels
Set the reasoning (thinking) effort for each model candidate with amodel_name:thinking_effort suffix on model and on every fallbackModels entry. Valid efforts are off, minimal, low, medium, high, xhigh, and max — the same shorthand used by atomic --model sonnet:high. xhigh and max are used only when the selected model’s capability map supports them.
thinking field. The separate thinking: frontmatter field is deprecated. It still works as a default for any candidate that has no suffix, and a suffix always wins, but new agents should encode the effort directly on model and fallbackModels:
fallbackThinkingLevels exists only as an optional compatibility helper: it is aligned by index to fallbackModels and supplies a fallback candidate’s effort only when that fallback entry has no suffix. Prefer suffixed model strings instead. Attempt metadata reports the resolved model and the effective reasoning effort used for each attempt.