Skip to main content

Module history

Module history 

Structs§

InteractiveSessionState

Constants§

DEFAULT_MAX_HISTORY_MESSAGES
Default complete-turn retention limit. Prefer passing the config-driven value via run_tool_call_loop; this constant is only used when callers omit the parameter. The name is retained for config compatibility.
HISTORY_TRIM_BREADCRUMB_CANONICAL
Canonical breadcrumb text used for trim markers. This is the English string that has been stable across all locales; it is the locale- independent anchor for legacy migration. Injected breadcrumbs are always produced via get_required_cli_string("history-trim-breadcrumb"), which currently resolves to this same English text in every locale. Checking the canonical value makes restore independent of the current process locale.
IMAGE_TOKEN_ESTIMATE
Fixed per-image charge in the history estimate, applied to the images preparation dispatches: the markers it lifts from user messages and the attachments a tool-result carrier declares. Approximates the standard-tier Anthropic maximum (1,568 tokens for an image at the 1568px downscale). High-resolution tiers and some models bill more (Anthropic high-res up to 4,784; GPT-4o-mini base 2,833; Qwen-VL ~4k per A4 page): this is a heuristic for trimming, not a ceiling, and provider-reported usage corrects it after the first successful response.

Functions§

append_or_merge_system_message
context_floor_remediation
estimate_history_tokens
Estimate token count for a message history using the ~4 chars/token heuristic plus ~4 framing tokens per message. Images are charged per image only where preparation dispatches them: the markers lifted from user turns and the attachments declared by the tool-result carriers of the current user turn. Stale tool-result carriers are priced as their bytes, and system or assistant content is priced as text. Trim probes estimate history suffixes that always retain the newest turn, so the current turn’s tool-result carriers carry the same disposition in every probe as in the full history.
estimate_system_floor_tokens
estimate_tool_schema_tokens
Estimate the token cost of native tool definitions serialized into the provider request, using the same ~4 chars/token heuristic as messages. The OpenAI and compatible adapters serialize these schemas into the chat request, so providers that include them in input_tokens report a population of messages plus tool schemas, not messages alone.
floor_char_boundaryDeprecated
Returns the largest UTF-8 character boundary at or before index.
is_history_trim_breadcrumb_text
load_interactive_session_history
load_interactive_session_history_with_crumb
Load interactive history plus the persisted breadcrumb provenance. Legacy files without the flag are migrated by inspecting the restored history: if the first non-system message equals the breadcrumb string, the flag is recovered as true. v2 records carry an explicit history_has_trim_breadcrumb (true or false) so a genuine user message that collides with the breadcrumb text keeps its real turn-boundary role. Legacy v1 migration is locale-independent: it checks the canonical English breadcrumb plus the current-locale string, covering both the stable historical value and any future translated variant. A v1 file whose first user turn genuinely equals the breadcrumb text cannot be distinguished from a synthetic marker on its one-time migration; after the next persist the file becomes v2 with the (mis)classified flag, which is the documented one-time limitation for unmarked legacy state.
normalize_system_messages
save_interactive_session_history
save_interactive_session_history_with_crumb
trim_history
truncate_tool_message
Truncate a tool message’s content, preserving JSON structure when the message stores tool_call_id alongside content (native tool-call format). Without this, truncate_tool_result destroys the JSON envelope and downstream model_providers receive a null call_id.
truncate_tool_result