···7272- Current depth limit: the built-in subtask mechanism currently allows only one child layer. A child task cannot spawn another child task.
7373- Current observer hint: `spawn` accepts an optional `observe_profile` parameter. `default` keeps mid-run previews conservative, `long_shell` is suited to long shell/log output, and `web_extract` suppresses raw noisy output until better stage signals exist.
74747575+For parameter details, result envelope fields, and the difference between `spawn` and `bash.run_in_subtask=true`, see [Subagents and Subtasks](/guide/subagents).
7676+7577## Runtime Tools
76787779These tools are injected dynamically while the agent is running.
···1919- To get running quickly: read [Quickstart (CLI)](/guide/quickstart-cli)
2020- To embed it into a Go project: read [Create Your Own AI Agent in 24 Lines](/guide/build-your-own-agent)
2121- To understand long-running entry points: read [Runtime Modes](/guide/runtime-modes)
2222+- To delegate isolated child work: read [Subagents](/guide/subagents)
2223- For pre-production governance: read [Security and Guard](/guide/security-and-guard)
+132
web/vitepress/docs/guide/subagents.md
···11+---
22+title: Subagents and Subtasks
33+description: "When to use `spawn`, when to use `bash.run_in_subtask`, and what the runtime guarantees."
44+---
55+66+# Subagents and Subtasks
77+88+Mistermorph currently has two explicit ways to put work behind a child-task boundary:
99+1010+- `spawn`: starts a child agent with its own LLM loop and an explicit tool whitelist.
1111+- `bash.run_in_subtask=true`: runs one shell command inside a direct subtask boundary without starting a second LLM loop.
1212+1313+Both paths return the same `SubtaskResult` envelope shape and share the same depth limit.
1414+1515+## Which entry to use
1616+1717+- Use `spawn` when the child work still needs agent-style tool reasoning, such as `read_file` plus `url_fetch`, or a fetch-then-extract flow.
1818+- Use `bash.run_in_subtask=true` when the work is already one concrete shell command or script.
1919+- Do not use a child task for trivial one-step work that the parent can complete directly.
2020+2121+Current status: both paths are synchronous. The parent waits until the child finishes. This is isolation, not background execution.
2222+2323+## `spawn`
2424+2525+`spawn` is an engine-scoped tool. It appears when an agent engine is assembled for a run.
2626+2727+Parameters:
2828+2929+- `task`: required child prompt.
3030+- `tools`: required non-empty array of tool names the child may use.
3131+- `model`: optional child model override. Defaults to the parent model.
3232+- `output_schema`: optional contract label for structured output.
3333+- `observe_profile`: optional observer hint. Supported values are `default`, `long_shell`, and `web_extract`.
3434+3535+Runtime behavior:
3636+3737+- The child registry starts from the `tools` names you pass. Unknown or unavailable names are ignored.
3838+- If none of the requested tool names are available in the parent registry, the call fails.
3939+- `spawn` is never re-exposed inside the child, even if you include it in `tools`.
4040+- The current depth limit is `1`, so a child task cannot start another child task.
4141+- Raw child transcript is not pushed back into the parent loop by default.
4242+4343+### About `output_schema`
4444+4545+`output_schema` is a schema identifier, not a built-in JSON Schema registry.
4646+4747+If you set it:
4848+4949+- the child is told to produce JSON final output;
5050+- the runtime requires the final output to be JSON or JSON-parsable text;
5151+- the same identifier is echoed back in `output_schema`.
5252+5353+Mistermorph does not validate the returned object against a real schema definition for you.
5454+5555+## Result Envelope
5656+5757+Both `spawn` and direct subtasks return JSON in this shape:
5858+5959+```json
6060+{
6161+ "task_id": "sub_123",
6262+ "status": "done",
6363+ "summary": "subtask completed",
6464+ "output_kind": "text",
6565+ "output_schema": "",
6666+ "output": "child result",
6767+ "error": ""
6868+}
6969+```
7070+7171+Field meanings:
7272+7373+- `status`: currently `done` or `failed`.
7474+- `summary`: short status text suitable for parent-side progress or preview.
7575+- `output_kind`: `text` or `json`.
7676+- `output_schema`: empty for plain text output, or the identifier you passed in.
7777+- `output`: child result payload.
7878+- `error`: non-empty only when the child fails.
7979+8080+## `bash.run_in_subtask=true`
8181+8282+This is the lighter child-task path.
8383+8484+- It uses the subtask runner directly and does not start a second LLM loop.
8585+- Its `output_schema` is fixed to `subtask.bash.result.v1`.
8686+- Its observer profile is fixed to `long_shell`.
8787+- The `output` payload contains `exit_code`, truncation flags, `stdout`, and `stderr`.
8888+8989+Example payload:
9090+9191+```json
9292+{
9393+ "task_id": "sub_456",
9494+ "status": "done",
9595+ "summary": "bash exited with code 0",
9696+ "output_kind": "json",
9797+ "output_schema": "subtask.bash.result.v1",
9898+ "output": {
9999+ "exit_code": 0,
100100+ "stdout_truncated": false,
101101+ "stderr_truncated": false,
102102+ "stdout": "hello\n",
103103+ "stderr": ""
104104+ },
105105+ "error": ""
106106+}
107107+```
108108+109109+Use this when you want a separate child-task envelope around one shell step, but do not need the child to make more tool calls.
110110+111111+## Config and Embedding
112112+113113+- `tools.spawn.enabled` controls only the explicit `spawn` tool entry.
114114+- Direct subtasks such as `bash.run_in_subtask=true` still use the subtask runtime even if `tools.spawn.enabled=false`.
115115+- `integration.Config.BuiltinToolNames` can include or omit `spawn`. It is not limited to static tools.
116116+- If you build an engine directly with `agent.New(...)`, `spawn` is enabled by default. Disable it with `agent.WithSpawnToolEnabled(false)`.
117117+118118+Example:
119119+120120+```go
121121+cfg := integration.DefaultConfig()
122122+cfg.BuiltinToolNames = []string{"read_file", "url_fetch", "spawn"}
123123+cfg.Set("tools.spawn.enabled", true)
124124+```
125125+126126+If you omit `spawn` from `BuiltinToolNames`, the agent loses the explicit child-agent tool, but the underlying subtask runtime can still be used by internal callers such as `bash.run_in_subtask=true`.
127127+128128+See also:
129129+130130+- [Built-in Tools](/guide/built-in-tools)
131131+- [Create Your Own AI Agent: Advanced](/guide/build-your-own-agent-advanced)
132132+- [Config Fields](/guide/config-reference)