openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
304 lines (251 loc) • 19.8 kB
Markdown
---
summary: "How a sub-agent reports its result back, the announce context block, and why sessions_history is preferred"
title: "Sub-agent announce"
read_when:
- You are debugging a missing or duplicated completion
- You need the fields in the announce context block
- You are reading a child transcript from inside an agent turn
---
An ordinary requester run ending or a later follow-up taking over does not discard
the waiting results. An accepted completion turn keeps its delivery; findings not
yet accepted remain pending for the requester's next turn.
Transcript consumption does not confirm a channel send. An ambiguous send keeps its
recorded uncertainty until the delivery owner resolves it.
## Announce
Sub-agents report back through completion delivery:
- The completed child's result is handed to the requester; delivery does not ask the child to generate a separate announcement.
- Runs spawned with `expectsCompletionMessage: false` skip completion delivery entirely; the run registry records their delivery as not required.
- Subagents must return a meaningful result or a concrete blocker. An exact child `NO_REPLY` response or no output cannot satisfy a missing child result and triggers normal missing-answer recovery. A retained completion without a visible result is handed to the requester as `(no output)`, including when several child results are collected together.
- Duplicate delivery is suppressed through recorded completion and source-message delivery facts. Subagents and internal parent review turns do not use silent tokens for deduplication.
A requester completion turn may finish with `NO_REPLY` or no visible text. That
settles the child's completion without a retry, an extra model turn, or a blocked
delivery notice. The child result remains available in its session and the
**Subagents** panel. This also applies when the completion guidance asks the parent
to answer the user: later parent turns own any outstanding answer. A child task
itself still owes its result; this quiet settlement applies to the parent reviewing it.
An interrupted requester completion turn is not a quiet settlement. Typed cancellation,
worker timeout, preparation invalidation, and saved-state or transcript conflicts
retain the existing bounded retry schedule when replay is safe: three attempts,
with 30-second and two-minute delays. Cancellation before dispatch also uses that
schedule. Every retryable settle outcome keeps its wake; exhausting the budget
records a permanent failure and the existing blocked-delivery notice. Runs with
committed or unknown effects remain failed for explicit recovery instead of
repeating their work.
A requester bound to a removed managed worktree is a permanent refusal and needs
an explicit worktree restore before it can accept new work. An in-progress removal
is transient and keeps the wake pending.
Ordinary completion delivery retains its existing frozen-result retry policy and
delivery identity; it does not start a new requester-settle attempt.
Explicit Stop, retired work, and intentional delivery suppression still take
precedence; cancellation does not revive work those owners have closed.
By default, delivery depends on requester depth:
- Top-level requester sessions use a follow-up `agent` call. External conversations use `deliver=true`; WebChat conversations stay in-session with `deliver=false`.
- Nested requester subagent sessions receive an internal follow-up injection (`deliver=false`) so the orchestrator can synthesize child results in-session.
- If a nested requester subagent session is gone, OpenClaw falls back to that session's requester when available.
Completion follow-up turns retain the requester's authority, including
session-scoped write access. Gateway admission still checks access to the selected
requester session; a child completion does not grant global write access.
Model fallback and other model-routing updates do not invalidate prepared
completion or child follow-up authority. Changes to session identity, lifecycle,
spawn lineage, tool policy, sandbox, or execution host still reject stale work.
New-turn capability preparation refreshes stale inherited session metadata once
per affected lookup before evaluating current policy again. This lets ordinary
metadata updates coexist with child follow-ups and completion turns. It does not
renew an active turn's retained authority: session replacement, policy revocation,
and closed owners still fail their existing checks.
The requester turn's captured origin owns completion routing, including after
`sessions_yield` and for child pause notices. A WebChat origin does not inherit a
previous external destination from the session. Without a captured origin, the
stored delivery route remains the fallback; explicit external routing remains
supported without clearing that history.
For top-level requester sessions, completion-mode direct delivery first
resolves any bound conversation/thread route and hook override, then fills
missing channel-target fields from the requester's origin and compatible stored route.
That keeps completions on the right chat/topic even when the completion
origin only identifies the channel. When an override selects a different
chat or topic, it does not inherit the previous route's thread. An explicit
thread from the binding or hook is preserved.
Finished results follow the current requester agent and session key even when the
recorded session store path changes. Live completion custody is retained only for
same-source, same-invocation, same-ceiling batches; missing, revoked, or mixed
custody uses a System write-only baseline. This does not relax private requester
session ID or lifecycle-revision checks, nor replay an already consumed result.
Child completion aggregation is scoped to the current requester run when
building nested completion findings, preventing stale prior-run child
outputs from leaking into the current announce. Announce replies preserve
thread/topic routing when available on channel adapters.
When a completion or settle turn has only a source-bound `message` grant, it can
send the completed work's photos and files using `media`, `attachments`, or media
directives, with or without text. Normal outbound media validation still applies,
including local-file roots. The grant cannot change the destination, channel,
account, or thread, or perform actions other than `send`. Explicit `replyTo` stays
limited to the current message or thread; inline reply and audio directives remain
restricted. See [message tool access](/tools#configure-access-and-approvals).
After `sessions_yield`, the frozen batch waits for its own children and their
descendants to settle. A still-running child from an earlier requester turn does
not delay that batch's result; the earlier batch retains its own completion wake.
Completion and settle run IDs stay within the 256-character execution-identity
admission limit, including nested completions. IDs that fit remain unchanged;
longer IDs retain their routing prefix and continuation markers with a SHA-256
digest of the full identity. Batch size and nesting therefore do not prevent
completion admission when execution-identity collection is enabled.
Completion inputs retain their own turn identity across compaction and runtime
context messages. If transcript persistence rejects a completion because its
keyed input belongs to a closed turn, delivery records a permanent failure with
the error. It does not retry other models or keep scheduling the same completion.
Direct child-result delivery records its transcript mirror after work already
queued on the requester session. The send settles without waiting for that
append, so a requester waiting on its child can resume. These tagged mirrors
record history without closing an open keyed input; ordinary final replies still
close the turn. Mirrors remain best-effort bookkeeping after a successful send.
Completion failures retain the concrete delivery error in the run's delivery state
without queuing a system notice into the parent session. A confirmed handoff remains delivered even if its receipt
callback fails; cleanup must not replay an already consumed result. Failures before
a delivery result is reported follow the same retryability policy as direct sends.
Restart checkpoint reconciliation retains the confirmed delivery evidence before
clearing the active recovery claim. Delivered replies, intentionally suppressed
delivery, and handled silent checkpoints remain distinct. A terminal run ID alone
is not proof that the requester received its result.
Transcript writer-claim changes remain retryable when no send is confirmed. If
local retries are exhausted, the completion stays eligible for bounded requester
recovery. Permanent delivery rejections still stop recovery, including when they
are wrapped by a writer-claim error.
If a chunk in a direct-message text fallback fails or is aborted after earlier
chunks were sent, OpenClaw records an incomplete delivery. It stops automatic
retries to avoid duplicating chunks the recipient already received. A successful
child's result remains available for recovery.
### Private parent completion
Set `completionTarget: "parent"` on `sessions_spawn` to return the result in a
private turn of the original requester session. The parent reviews the result,
continues unfinished work, and settles the reviewed input. Private processing
may finish silently; it does not by itself satisfy
an outstanding user reply.
OpenClaw does not automatically send the child result, parent final, or
generated media to a channel. The parent can still choose to send a message
through its permitted tools. When the requester has no current conversation or
delivery target, the private completion guidance tells it to record its final
reply in the session for the requester; no messaging send is needed.
If the parent called `sessions_yield` while waiting for private children, the
yield hands the conversation back to it. When those children settle, the parent
resumes and answers the original conversation under its normal reply rules: with
automatic replies its final text is delivered; with `visibleReplies:
"message_tool"` it must send the answer with the `message` tool, and plain final
text stays internal. Child results stay internal input, and nothing is sent
automatically on the child's behalf. The resumed turn stays bound to the parent
session that spawned the children: if that session is reset (for example with
`/new`) or replaced before the parent resumes, the results are dropped and
nothing is sent.
This option supports hidden, native, one-shot runs only. It cannot be combined
with ACP, `collect: true`, `visible: true`, `thread: true`, `mode: "session"`, or
`expectsCompletionMessage: false`. It does not change the default completion mode.
Finished private results remain in the registry until the spawning parent turn
settles. A normal parent finish releases each ready result for private review;
`sessions_yield` hands the results to its existing child batch instead. A reset or
removed parent does not transfer the result to another session. When a settled
batch contains a private result, the child findings stay private input to the
parent's review or yielded continuation; ordinary siblings retain their individual
completion delivery.
Inspecting a completed child's status before yielding does not consume or invalidate
its private result.
Waiting for the spawning parent turn does not consume a private result's delivery
retry window. A normal parent finish starts that window when it releases the
result. After `sessions_yield`, the yielded batch owns delivery; individual child
cleanup cannot expire or suspend that batch's result.
Session controls still require the current caller’s authority. A completion report
does not transfer the original human’s permissions. Keep authorized cleanup with
the original requester turn and use after-turn self-archive when appropriate,
rather than asking a notification-only turn to acquire owner privileges.
Use `sessions_send` with `mode: "notify"` for context-only updates; a normal peer
follow-up still follows the destination conversation’s reply requirements.
Use a build that supports this option throughout the run. Older builds cannot
resume private completion handoffs and may discard them after a downgrade;
existing session transcripts remain separate.
### Announce context
Announce context is normalized to a stable internal event block:
| Field | Source |
| -------------- | -------------------------------------------------------------------------------------------------------- |
| Source | `subagent` or `cron` |
| Session ids | Child session key/id |
| Type | Announce type + task label |
| Status | Derived from runtime outcome (`ok`, `error`, `timeout`, or `unknown`) — **not** inferred from model text |
| Result content | Latest visible assistant text from the child |
| Follow-up | Instruction to review the result, continue unfinished work, and report the outcome |
The result is the child's complete visible final answer for the completed run,
including ACP-backed runs and CLI fallback transcripts. A later turn in the same
child session does not replace that run's answer. Native answers preserve the same
text-block boundaries as terminal results. Already displayed replies retain their
recorded display text, and media references remain available for parent review.
Once cleanup and requester obligations
have settled, the in-memory registry keeps a short task preview and lifecycle
metadata. Full task and result text remain in SQLite and are loaded for selected
reads or later mutations. Pending delivery, suspended delivery, cancellation, and
yielded work keep their payloads until those obligations settle.
If completion receipts for the same run arrive out of order, the receipt with
the newer producer end time owns the reply. Equal end times retain the first
accepted reply; a correction with a newer end time can replace it.
OpenClaw keeps each child result's own characters inside its prompt-data block, so
a requester can quote it exactly: markup, entities, ampersands and tabs arrive as
the child wrote them. Only a `<` that would open or close a data block, an
OpenClaw prompt-region marker or an OpenClaw `<<<…>>>` delimiter is escaped as
`<`. Task titles stay fully escaped. Several results keep a stable order, and
completion findings have a strict shared 160,000-character cap, including
escaping and framing. Small answers stay intact; larger answers keep
their beginning and an explicit truncation marker pointing to `sessions_history`
with the child session key. `sessions_history` truncates text fields to 4,000
characters; this pointer does not provide lossless retrieval of an omitted tail.
Each shown child keeps its task and status, with result heads sharing the remaining
space above a small floor. If even floor-sized blocks would exceed the cap, the
remaining children become one bounded summary line with their count, the first few
session keys, and guidance to inspect them with the session tools. Ordering stays
deterministic. The bounded lifecycle snapshot and retained complete transcript
stay separate from these prompt limits.
A successful child with an empty final reply remains in the batch with its task
identity, `ok` status, and `(no output)` result. Its successful execution status
does not satisfy the required result.
For nested work, descendant findings help the child form its answer. The child's
own final answer is what travels onward to its parent. A final answer delivered
through the message tool remains authoritative through its recorded source
delivery, even if a later terminal response is empty or silent.
Completion delivery can read an existing registered archive when child cleanup
finishes before the parent resumes. The Control UI's **Tasks** inspector also
reads the completed run's retained transcript after cleanup removes its live
session. Paging stays bound to that run's archive, even if the session key is reused.
After deletion, child-specific sharing metadata is no longer available. Archived
previews therefore require existing session access that does not depend on that
metadata, such as Gateway administrator access. Profile-scoped readers cannot
recover a deleted child's entitlement from access to its parent task. Keeping the
child session preserves its normal sharing checks.
Oversized text records use the normal history size notice. A single archived
record above 8 MiB makes Tasks history unavailable before the reader decodes it,
to bound per-record decoding memory. This limit also applies to other retained
generations with the same session key: run membership is stored inside transcript
records, so an unreadable candidate prevents the reader from establishing a unique
match, even when the requested run's own archive is small. The reader reports
unavailable rather than skipping an unclassified generation. This read limit does
not change retained archives or completion delivery's final-answer scanner.
Tasks reports this as a non-retryable preview limit; refreshing cannot resolve it.
Terminal failed runs report failure status without replaying captured
reply text. When completion is recovered from the child's stored session, its
recorded failure or timeout diagnostic is preserved for the parent.
Tool/toolResult output is not promoted into child result text.
### Stats line
Default announce payloads include a stats line at the end (even when wrapped).
Private parent completions omit mutable usage statistics so a retried handoff
keeps the same input:
- Runtime (e.g. `runtime 5m12s`).
- Token usage (input/output/total).
- Estimated cost when model pricing is configured (`models.providers.*.models[].cost`).
- `sessionKey`, `sessionId`, and transcript path so the main agent can fetch history via `sessions_history` or inspect the file on disk.
Internal metadata is meant for orchestration only; user-facing replies
should be rewritten in normal assistant voice.
Usage is read once after the child settles. If usage has not been recorded yet,
the stats line says `tokens unknown`; completion delivery does not wait for it.
### Why prefer `sessions_history`
`sessions_history` is the safer orchestration path for reading a child's
transcript from within an agent turn:
- Preserves text, including credentials, without secret masking.
- Truncates long text blocks (4000 chars per block) and drops thinking signatures, reasoning replay payloads, and inline image data.
- Caps returned messages at 80 KB; older rows can be dropped or an oversized row replaced with `[sessions_history omitted: message too large]`.
- Use `nextOffset` when present to page backward through older transcript windows.
- Returns structured history rather than `/subagents log`'s plain chat lines. Reasoning tags, `<relevant-memories>` / `<relevant_memories>` wrappers, and tool-call XML can remain in message text: `sessions_history` does not apply the log command's assistant prose sanitizer. See [Session tools](/concepts/session-tool#listing-and-reading-sessions) for the recall guarantees.
- Raw on-disk transcript inspection is the fallback when you need the full byte-for-byte transcript.