Module tool_carrier
Expand description
Tool-result carrier grammar: the fixed position where a tool round’s attachments live in conversation history.
A tool result becomes history in one of two carrier shapes (see the
runtime’s history_append):
- native — a
role = "tool"message whose content is a JSON object with the call id, the verbatim result text undercontent, and anattachmentsarray sibling, always present when written by the new runtime ([]for none). - prompt mode — a
role = "user"message starting with[Tool results]on line 1,[Tool attachments: N]on line 2, exactly N marker lines, then the joined verbatim tool text.
The position is fixed so a parser never has to search, and therefore never has to trust, carrier body text: a marker-looking line inside the body is body, because the attachments were already counted at the position only the runtime writes. A carrier without the array key / count line is legacy: it parses as zero attachments and its body stays untouched text.
Marker lines reuse the existing marker syntax ([IMAGE:<target>] and the
other kinds) so an image attachment handed to the marker loader as those
lines alone lifts exactly as before.
Structs§
- Carrier
Parts - A carrier opened at its fixed position: the verbatim body, the declared attachments, whether the position carried a declaration at all, and which shape the carrier takes.
Enums§
- Carrier
Kind - Which carrier shape a tool-result carrier uses.
Constants§
- TOOL_
RESULTS_ PREFIX - Line 1 of a prompt-mode tool-result carrier. Kept identical to the pre-attachment format so every span selector that keys on this prefix keeps working.
Functions§
- classify
- Classify a message as a tool-result carrier, whichever shape it takes.
- image_
refs - The image references a carrier declared, in declaration order. Non-image kinds are carried but never resolved into image parts.
- is_
prompt_ tool_ carrier - Whether user-role content is a prompt-mode tool-result carrier. Mirrors the detection the provider layer has long used, so runtime and providers agree on what counts as a carrier even when its shape is legacy.
- is_
tool_ result_ carrier - Whether a message is a tool-result carrier in either shape, legacy included: the same predicate every seam uses, so runtime, providers, and channels agree on what counts as a carrier even when its shape is legacy.
- marker_
line - The marker line for one attachment, in the existing marker syntax.
- native_
attachments - Read the
attachmentsarray of a parsed native carrier envelope. - parse_
marker_ line - Parse one marker line back into an attachment record. Only the kinds this grammar writes are accepted; anything else is not a marker line.
- parse_
native_ tool_ carrier - Parse a native (
role = "tool") carrier envelope. - parse_
prompt_ tool_ carrier - Parse a prompt-mode carrier: line 1 the results prefix, line 2 the exact count header, then exactly that many marker lines, then the body.
- rebuild_
carrier - Rebuild a carrier’s content with a new attachment list, taking the body
from
parts— the only text a caller may have rewritten — and keeping every other envelope field ofcontentuntouched. - render_
native_ attachments - Render the
attachmentsarray value for a native carrier envelope. - render_
prompt_ tool_ carrier - Render a prompt-mode carrier: prefix, count header, marker lines, body.