Skip to main content

Module reduce

Module reduce 

Source
Expand description

The one history-reduction path.

A run previously reduced history twice: a message-count pass over crate::uar::context::ContextStrategy followed by an independent token-budget pass with its own strategy enum and its own tokenizer. The two disagreed about what a token was, neither knew the system message was pinned, and neither knew about tool-call pairs.

reduce_history is now the only way a run reduces history. It runs the structural stage and the token-budget stage in order, from the single operator-declared strategy, with the system message pinned out of reach of both. Canonical tool groups are validated before reduction and must survive byte-for-byte or the reduction returns an explicit overflow.

The operator-facing crate::uar::context::ContextStrategy remains the only declared strategy. The internal crate::uar::domain::context::ContextStrategy is derived from it here and is not part of any persisted policy.

Structs§

ReduceReport
What reduce_history did to a run’s history.

Enums§

ReduceHistoryError
Why a history cannot be prepared within the requested reduction policy.

Constants§

RESPONSE_RESERVE_TOKENS
Output tokens withheld from the model context for the response. This is the reserve reduce_history subtracts when it derives the input allowance.

Functions§

budget_strategy_for
Map the operator-declared strategy onto the token-budget stage’s strategy.
canonical_prose_spans
Mark only canonical plain dialogue as reducible prose. Input includes the optional pinned system message; returned offsets exclude that message, as required by the structural summarizer. No content heuristic grants authority.
liability_message
Event text for a reduction failure. An overflow names the liabilities the allowance already excludes: tool definitions plus world state (fixed_tokens, combined) and the response reserve.
reduce_history
Reduce a run’s history once: lossless validation, structural stage, token budget, then protected-group verification, with the system message pinned.
reduce_history_with_input_allowance
Reduce against a host-reviewed input allowance that already excludes output, reasoning, uncertainty and fixed request content. Counts used for trimming remain estimates; the destination driver recounts the complete final wire.
reduce_history_with_input_allowance_and_auxiliary
Reduce with a distinct captured allowance for auxiliary model requests.
reduce_history_with_marked_prose
Reduce history while permitting only explicitly host-marked prose ranges to enter summarization. Span indices address conversation history after the optional leading system message is removed.
reserve_fixed_input_tokens
Withhold tools and world state from an already reserved input allowance. No capacity is inferred here; the caller owns the destination contract.
reserve_fixed_request_tokens
The context limit to hand reduce_history once request content that history cannot displace (world state and tool definitions) is withheld. reduce_history then subtracts the response reserve itself.
search_tools_definition
OpenAI tool JSON of the search_tools control the orchestrator adds to the request whenever deferred MCP tools exist. Built from a scratch registry so admission counts exactly the descriptor the first request carries. None when the control cannot be built; the orchestrator then counts the actual request tools per step.
split_assembly_failure
Inverse of tag_assembly_failure: the stable code and message, or None for an untagged contributor failure.
tag_assembly_failure
Carry a reduction failure’s stable code through AssemblyError, which has no code field: "<code>: <liability message>".
tool_definition_tokens
Tokens the tool definitions occupy in a request, counted over the same OpenAI function-schema JSON the run attaches to every model call.