Skip to main content

Module tool_carrier

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 under content, and an attachments array 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§

CarrierParts
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§

CarrierKind
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 attachments array 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 of content untouched.
render_native_attachments
Render the attachments array value for a native carrier envelope.
render_prompt_tool_carrier
Render a prompt-mode carrier: prefix, count header, marker lines, body.