Skip to main content

MAX_CARRIED_BYTES

Constant MAX_CARRIED_BYTES 

pub const MAX_CARRIED_BYTES: usize = _; // 262_144usize
Expand description

The most serialized JSON, in bytes, of messages that a continued conversation carries from the conversation it continues (Conversation::continued): 256 KiB.

Why a cap at all: every continuation copies the carried history into the new run’s state, which is one JSON value in the store, so without a bound each task in a long-lived context would store, and each model call would re-read, everything said before. Why this size: it is about what Limits::max_history_tokens lets through to the model (100 000 tokens of about 4 characters). Bytes of JSON, not tokens: the cap has to be checkable without a tokenizer, and it over-counts the JSON’s own punctuation, which only makes it stricter.

What is given up to meet it, in this order, and only as far as needed:

  1. The tool outputs of the turns older than the newest are shortened, oldest first, each keeping its head and ending in the TRUNCATION_MARKER_PREFIX marker: what a run does to its own history when it goes over Limits::max_history_tokens, and the output of a tool is the bulk of a coding run. No call loses its result.
  2. Whole old turns are dropped, oldest first (a turn is a user message and everything that followed it up to the next user message), and one marker text (OMITTED_MARKER_PREFIX) says how many. This is what the model is not already shown in full.
  3. The tool outputs of the newest prior turn are shortened, last, oldest first, only if the cap is still exceeded. The newest turn is what the new message most likely follows up on, so its output is the last thing given up: older turns go before it is touched.

Two things are never dropped: the first user message of the chain (the task the whole conversation is about, kept verbatim as the first text part of the first message) and the newest prior turn (only step 3 shortens its tool outputs). A newest turn whose own assistant text and tool-call arguments are larger than the cap is therefore carried over the cap: one run’s own limits bound it, and the next continuation shortens or drops it.