Repository navigation
summarization
How the agent keeps long conversations inside the model's context window: five trigger points watch the whole lifecycle (before the turn, before every model call, after every model response, and on provider overflow errors), a pure 4-route router picks the cheapest fix (truncate big tool results and oversized tool-call args first, AI-compact only when forced), and anti-thrash guards make sure compression can never spiral.
Source of truth: agent/middlewares/summarization/core.py, agent/middlewares/summarization/compression.py, agent/middlewares/summarization/overflow.py, agent/middlewares/summarization/summary_generation.py, agent/middlewares/summarization/thrash.py, agent/middlewares/summarization/state_aliases.py, agent/middlewares/summarization/plan_context.py, pub/func/message/overflow_router.py, pub/func/message/tool_result_ttl.py, pub/func/message/llm_error_classifier.py, pub/func/estimate_tokens.py, pub/func/message/tool_output_dedup.py, pub/func/message/tool_output_prune.py, pub/func/message/target_truncation.py, pub/func/message/tool_args_truncate.py, pub/func/message/turn_utils.py, config/features/agent_side/summarization.py, agent/middlewares/summarization/microcompact.py, agent/tools/compact_now.py, models/LLMs/provider_max_output.py, plus the two registration sites agent/core.py and agent/tools/subagent/spawn/core.py. Every line number and constant in this document was verified against that code.
- Overview
- Triggers: Lifecycle & Overflow Routing
- Token Estimation (No Tokenizer)
- Output Caps, Microcompact & User-Requested Compaction
-
Compression Internals
- ✂️ The Truncate Track: Budget Truncation & the TTL Module
- 🔁 The Compact Track: Inside
_apply_compression - 🖼️ Compression-Time Media Offload (Inline Media → Reference)
- 📝 LLM Summary: Prompt, Chaining, Fallback
- 🧱 The Static Fallback (LLM-Free Summary)
- 📦 The Output: Summary Message Pair
- 🛡️ Anti-Thrash Guard Matrix & Degradation Recovery
- 🔄 System Prompt Refresh
- 📌 Registration Sites
- Configuration Reference
- Testing
⚠️ Honesty & Limitations
Summarization (agent/middlewares/summarization/core.py, class at core.py:234) is a from-scratch AgentMiddleware — it does not inherit from LangChain's built-in SummarizationMiddleware. It hooks exactly two points of the agent lifecycle:
-
before_agent/abefore_agent(core.py:399/core.py:403) — T1 preflight -
wrap_model_call/awrap_model_call(core.py:413/core.py:495) — T2 dispatch, T3 post-response re-check, T4/T5 error-recovery ring
In the middleware chain it sits directly under LLMRetryMiddleware; only InvalidToolCallRepairMiddleware wraps it from the inside — that one is closest to the LLM. When compression fires, the history always ends up in the shape:
HumanMessage("What did we do so far?")
AIMessage(<summary>, lc_source="summarization")
<recent turns preserved verbatim>
Because the replacement is a Human/AI pair, the model never sees two consecutive same-role messages and no pairing repair is needed.
Two registrations exist:
| Site | Trigger | LLM | need_update_system_prompt |
|---|---|---|---|
Main agent (agent/core.py) |
("tokens", resolve_compression_threshold(window, max_output, fallback_ratio=COMPRESSION_TRIGGER_RATIO)[0]) |
compression_llm (COMPRESSION_LLM_*, aux fallback) |
True |
Worker/subagent (agent/tools/subagent/spawn/core.py) |
("messages", 40) or the same threshold helper |
auxiliary_llm |
False (default) |
Both pass main_llm_context_window=main_llm_max_tokens (from MAIN_LLM_MAX_TOKEN). resolve_compression_threshold uses window - max_output_tokens when MAIN_LLM_MAX_OUTPUT_TOKEN is set; COMPRESSION_TRIGGER_RATIO = 0.80 is only the unset-cap fallback ratio.
The summarizer never sees the live reminder layer's stale snapshots.
_filter_summary_messages drops (a) the previous summary pair
(lc_source="summarization") and (b) catalog reminders whose source declared
compress_exclude (the default: plan mode, todo, TaskFlow, boulder, project
instructions, directory notice). Their content was a snapshot
of the injection turn and the next turn rebuilds it from live state, so it is
noise in a summary. continuity_context declares compress_exclude=False and
stays; reminders injected before the tag existed carry no key and keep the
legacy behavior.
The serializer labels a HumanMessage [User] only when
pub.func.message.classify.is_user_message is true — a positive, fail-closed
check of metadata.origin == "user". A surviving compress_exclude=False
reminder is [Continuity]; every other injected HumanMessage (workspace
notice, continuation directive, subagent completion, task-intent steering,
cron result) is [System notice]. The static fallback and
_latest_human_eviction_ref use the same test, so an injected carrier can
never become the summary's Goal or the latest user request.
pub/func/estimate_tokens.py (230 lines) is deliberately tokenizer-free and deterministic, with a three-tier fallback:
-
T1 — API-reported usage:
estimate_messages_tokensreturns the lastAIMessage'susage_metadata(or an explicitreported_tokens) verbatim when present — the provider's ground-truth count short-circuits all local estimation; -
T2 — CJK-aware heuristic:
estimate_text_tokenssplits the text into CJK characters (// CHARS_PER_TOKEN_CJK = 2) and the rest (// CHARS_PER_TOKEN = 4), reusingpub.func.cjk.count_cjkfor detection; -
T3 — legacy
len // 4: not a separate code path — the T2 degenerate case whencount_cjk(text) == 0, so pure-ASCII estimates keep the legacy numbers exactly.
tokens = (cjk chars // CHARS_PER_TOKEN_CJK) # CHARS_PER_TOKEN_CJK = 2
+ (other chars // CHARS_PER_TOKEN) # CHARS_PER_TOKEN = 4
# message-level: str content → text estimate
# + Σ tool_call name/args chars + tool_call_id chars
# list content → per block: text blocks as text, media blocks at a fixed
# per-type cost, unknown blocks at the conservative unknown costA content list is counted block by block, never by JSON-serializing the whole list: text blocks are estimated as text, media blocks (image_url / audio_url / video_url / audio_bytes / video_bytes, or any block carrying a data: payload) get a fixed cost from TOKEN_ESTIMATION — tokens_per_image_block = 85, tokens_per_audio_block = 256, tokens_per_video_block = 1024 — and unknown blocks get tokens_per_unknown_block = 85. The removed JSON path counted 5 MB of base64 as ~1.25M tokens and would fire compression on a single image; the fixed costs are conservative stand-ins for media whose real token count is not derivable without a model. str content and None are unchanged, and a pure-text list estimates like the concatenated text.
pub/func/message/estimate_msg_tokens.py is now a backward-compatible re-export of the same helpers. The estimator is fast, stable across runs (same input → same number → reproducible tests), and intentionally conservative-approximate. Nothing in the trigger/budget path depends on a model tokenizer.
MAIN_LLM_MAX_OUTPUT_TOKEN / AUXILIARY_LLM_MAX_OUTPUT_TOKEN (.models) separate the per-request output cap from the context window. Empty = no field is sent (provider default); a set value must be >= 8192 (8K) and is refused at boot, built_agent(), subagent spawn, model build and PUT /models-config. models/LLMs/provider_max_output.py maps the provider to the keyword init_chat_model accepts: max_tokens for OpenAI-compatible providers, Azure and Anthropic; max_completion_tokens for OpenAI o-series/gpt-5; max_output_tokens for Google/Vertex and the Responses family. An unknown gateway gets no field. The thinking-budget base uses the configured cap when set.
_effective_context_window() = ctx - min(max_output, ctx). The preserve budget (_calculate_preserve_budget) and the overflow budget (_usable_budget) use it, so an explicit output cap is never over-committed. Unset keeps reserve 0 and the legacy formulas byte-identical.
microcompact.py runs at the end of _run_non_llm_strategies. Trigger: 60-minute idle (process-local completion clock) or tokens >= min(auto_threshold * 0.9, auto_threshold - 2000). It replaces OLD compactable tool results with [Old tool result content cleared], keeping the newest 5 messages, skipping media/already-cleared results, and discarding a pass that saves < 256 tokens. It is LLM-free and keeps the ToolMessage pairing fields.
The compact_now main tool queues SUMMARIZATION_COMPACT_REQUESTED; the next model call's T2 dispatch runs one compaction with trigger USER, bypasses anti-thrash and records {trigger: user_requested, phase: standalone_turn}. It is a tool (the model calls it when the user asks), not a client /compact command.
A session model profile may declare context_window (a decimal string in the client descriptor, validated by the backend sanitizer). _session_context_window(session_id) feeds that window into the preserve and overflow budgets, so a switch to a smaller model compacts at the next pre-request check; the compact event is labelled reason=model_downshift. An absent field keeps the env window.
Every compact path emits one trajectory compact event carrying phase (standalone_turn / pre_request / post_response / reactive / mid_turn), reason (context_limit / provider_overflow / user_requested / model_downshift) and the unchanged trigger (T1–T5 / USER), plus messages_before, messages_after and route. T1/T2/T3/user-requested compactions share _finish_compact; the T4/T5 forced-recovery path records from _finish_forced_recovery, so the labels derive from the real trigger and cannot drift.
All thresholds live in config/features/agent_side/summarization.py (SUMMARIZATION TypedDict). Values marked ◆ are consumed by the live code paths; values marked ○ are defined or imported but not consumed by any live path (see Honesty & Limitations).
| Constant | Value | Consumed where |
|---|---|---|
COMPRESSION_TRIGGER_RATIO ◆ |
0.80 |
hard-overflow band in decide_route; T3 pressure gate; builds both trigger clauses |
PREEMPTIVE_TRUNCATE_RATIO ◆ |
0.70 |
soft-overflow band in decide_route
|
COMPRESSION_RESERVE_TOKENS ◆ |
16_000 |
_usable_budget (overflow.py:168): window − reserve |
TRUNCATE_BUDGET_RATIO ◆ |
0.60 |
truncate-track budget = usable × 0.60 (overflow.py:219) |
MIN_TOOL_RESULT_TOKENS_TO_TRUNCATE ◆ |
200 |
candidate floor in find_truncatable_tool_results
|
TRUNCATABLE_RECENT_SKIP ◆ |
6 |
newest messages never truncatable (pairing margin) |
MAX_OVERFLOW_RETRIES ◆ |
3 |
T4/T5 forced-recovery cap (shared counter) |
OVERFLOW_CLIP_ENABLED ◆ |
True |
P1-2 no-LLM tail clip master switch |
OVERFLOW_CLIP_MAX_REMOVE ◆ |
10 |
max tail messages stubbed per clip pass |
OVERFLOW_CLIP_MIN_KEEP ◆ |
5 |
transcript floor: ≤ this many messages → no clip |
MAX_COMPRESS_ATTEMPTS_PER_TURN ◆ |
3 |
per-turn proactive compaction cap |
COMPACTION_COOLDOWN_ROUNDS ◆ |
3 |
cooldown armed after every actual compact |
MIN_PRESERVE_TOKENS ◆ |
2_000 |
preserve-budget floor; budget without a window |
MAX_PRESERVE_TOKENS ◆ |
15_000 |
preserve-budget ceiling |
PRESERVE_RATIO ◆ |
0.25 |
preserve budget = 25% of window |
PRUNE_PROTECT_TOKENS ◆ |
40_000 |
prune: newest tool-output tokens kept |
PRUNE_MIN_REDUCTION_TOKENS ◆ |
5_000 |
prune: minimum payoff to apply |
TARGET_TRUNCATE_RATIO ◆ |
0.5 |
target-truncate: shrink toward 50% of current tokens |
MIN_OUTPUT_CHARS_TO_TRUNCATE ◆ |
500 |
target-truncate: eligibility |
MAX_TOOL_OUTPUT_TOKENS ◆ |
500 |
target-truncate: per-output token cap (legacy char keys are ×4) |
MIN_ARGS_CHARS_TO_TRUNCATE ◆ |
500 |
tool-args truncate: eligibility (JSON-serialized args length) |
MAX_TOOL_ARGS_CHARS ◆ |
2_000 |
tool-args truncate: per-args cap |
AGGRESSIVE_TRUNCATE_TOKENS ◆ |
250 |
aggressive backstop cut length (tool results and tool-call args) |
SUMMARY_TOTAL_MAX_TOKENS ◆ |
4_000 |
summary message token cap (×4 approximates the old 16 000-char cap) |
CONTENT_HEAD_RATIO / CONTENT_TAIL_RATIO ◆ |
0.3 / 0.3
|
all head/tail keeps (summaries and TTL truncation) |
DEGRADATION_NO_TEXT_THRESHOLD ◆ |
3 |
empty replies before forced recovery |
MAX_RECOVERY_ATTEMPTS ◆ |
2 |
degradation-recovery budget |
MAX_TOTAL_COMPRESSION_ATTEMPTS ◆ |
5 |
governor: session attempt cap |
INEFFECTIVE_THRESHOLD ◆ |
2 |
governor: consecutive ineffective → skip LLM |
MIN_EFFECTIVENESS_PCT ◆ |
0.05 |
governor: token-reduction effectiveness |
PROTECTED_TOOLS ◆ |
{"memory", "skill_view", "skill_list"} |
exempt from every shrink strategy |
MICROCOMPACT_ENABLED ◆ |
True |
microcompact master switch |
MICROCOMPACT_KEEP_RECENT_TOOL_RESULTS ◆ |
5 |
newest messages never compacted |
MICROCOMPACT_IDLE_THRESHOLD_MINUTES ◆ |
60 |
idle-time trigger |
MICROCOMPACT_MIN_TOKEN_SAVINGS ◆ |
256 |
discard a pass below this saving |
MICROCOMPACT_THRESHOLD_RATIO ◆ |
0.9 |
token-pressure band vs the auto threshold |
MICROCOMPACT_BUFFER_TOKENS ◆ |
2_000 |
pressure band leaves this headroom |
MICROCOMPACT_COMPACTABLE_TOOLS ◆ |
9 tool names | only these results are compacted |
LAST_TURN_RATIO_THRESHOLD ◆ |
0.5 |
last-turn compression gate |
COMPLETED_MAX_ITEMS / KEY_DECISIONS_MAX_ITEMS / CRITICAL_CONTEXT_MAX_ITEMS ◆ |
5 / 5 / 3
|
FIFO section caps |
ACTIVE_PLAN_NOTES_MAX_ITEMS / EVICTED_REFS_MAX_ITEMS ◆ |
20 / 20
|
document array caps (plan notes / eviction pointers) |
FILE_OPS_LIST_MAX_CHARS ◆ |
900 |
file-ops ratchet list cap |
LATEST_USER_REQUEST_MAX_CHARS ◆ |
800 |
recovery-context request cap |
CHARS_PER_TOKEN / CHARS_PER_TOKEN_CJK (estimator) |
4 / 2
|
deterministic token estimate divisors (non-CJK / CJK); defined in config/features/agent_side/token_estimation.py
|
TOKENS_PER_IMAGE_BLOCK / TOKENS_PER_AUDIO_BLOCK / TOKENS_PER_VIDEO_BLOCK / TOKENS_PER_UNKNOWN_BLOCK (estimator) |
85 / 256 / 1024 / 85
|
fixed per-block costs for a multimodal content list — base64 is never counted as text; defined in config/features/agent_side/token_estimation.py
|
PRUNE_TTL_SECONDS |
300 |
TTL-expiry horizon — consumed only by the TTL trio (test-only today) |
TTL_REGISTRY_MAX_ENTRIES |
512 |
TTL first-seen registry bound (test-only today) |
SUMMARY_TRIM_TOKENS ○ |
12_000 |
defined in config, never read |
AUTO_CONTINUE_PROMPT ○ |
— | imported by the middleware, never read |
DEGRADATION_MONITOR_COUNT ○ |
5 |
defined, not imported |
FILE_OPS_SECTION_MAX_CHARS ○ |
2_000 |
defined, not imported (only the 900-char list cap is used) |
| Suite | Cases | Covers |
|---|---|---|
tests/pub/func/message/test_overflow_router.py |
29 |
compute_pressure / find_truncatable_tool_results / decide_route bands, candidate rules, stable route strings |
tests/pub/func/message/test_tool_result_ttl.py |
28 | In-place truncation, pairing invariant, non-empty placeholders, registry bound, budget truncation |
tests/pub/func/message/test_llm_error_classifier.py |
75 | 413 status, text hints, 7 substring + 25 provider overflow patterns, NON_OVERFLOW exclusions, Cerebras bodyless, cause-chain depth, read-only guarantees |
tests/models/test_provider_max_output.py |
15 | provider field mapping, Responses floor, 8K business floor, unknown-gateway skip |
tests/agent/middlewares/test_preserve_budget_with_output_reserve.py |
5 | effective window, preserve/usable budgets, pressure bands, reserve clamp |
tests/agent/middlewares/test_microcompact.py |
7 | token/idle triggers, keep-recent, media/cleared skips, min savings, kill switch |
tests/agent/tools/test_compact_now.py |
4 | queue flags, no-session refusal, T2 USER dispatch |
tests/agent/middlewares/test_phase.py |
9 | T1-T5/USER derive the expected phase+reason; unknown trigger falls back |
tests/agent/middlewares/test_trajectory_phase.py |
6 |
_finish_compact (T1/T2/T3/USER) and _finish_forced_recovery (T4/T5) events keep legacy fields and add phase/reason |
tests/agent/middlewares/test_model_downshift.py |
4 | session context_window drives the budget; compact event reason=model_downshift; no override keeps context_limit |
tests/pub/func/message/test_pub_func_message_tools.py |
29 | dedup / prune / target-truncate / turn-utils plus tool-args truncation: head+tail format, small-args skip, freed clamp, protected tools, skip-recent, pairing & no-mutation |
tests/pub/func/message/test_read_file_slice.py |
12 | read_file recoverable slice: original path + 1-based offset notice, no line skip, absolute page numbering, byte-identical generic marker, protected / under-budget / fallback paths |
tests/config/test_num_contract.py |
46 | Constants contract (watchdog CONTRACT_NAMES covers all documented knobs) |
tests/pub/func/message/test_overflow_clip.py |
21 | P1-2 pure clip: trailing-batch detection, max_remove/min_keep/enabled gates, token target, marker preservation (P0-2 pointer, P2-4 notice), no-op idempotency, pairing invariant |
tests/agent/middlewares/test_summarization_overflow_clip.py |
9 | P1-2 middleware integration: T1/T2 clip without LLM, insufficient-clip degradation, kill switch, T4/T5 clip-then-retry and clip→compression degradation, sync/async parity, sanitizer-unchanged |
tests/agent/middlewares/test_compression_comprehensive.py |
54 | 12 classes: T2 soft-overflow, T2 cooldown, T2 negative/no-op, sync/async parity, T1 preflight, route decision, T3 trigger/three-forms/negative-double, T4/T5 recovery, the full anti-thrash matrix, full-branch parity, chained-summary filtering |
tests/agent/middlewares/test_compression_media_offload.py |
12 | Compression-time inline-media offload: write + pointer, content-hash dedup, placeholder on decode/store failure, preserved-window media untouched, sync/async parity, evicted_refs collection |
tests/agent/middlewares/test_license_invalidation.py |
11 | Read-license invalidation: a summarized-away read_file drops its license (later write_file refused), preserved-tail reads keep theirs, latest-read rule, partial overlap, patch_file / append unaffected, re-read re-licenses, sync/async parity, fail-open |
tests/pub/func/test_estimate_tokens_media.py |
22 | Block-wise multimodal estimation: fixed media costs, 5 MB-base64 regression, unknown blocks hiding media, str / None / empty-list / pure-text edges |
tests/agent/middlewares/test_summary_message_filtering.py |
6 | Chained-summary filtering: prior pair stripped from the serialized conversation, normal/empty/multi-pair inputs, unmarked legacy human preserved, async _acreate_summary mirror |
tests/agent/middlewares/test_summary_doc.py + test_summary_doc_middleware.py
|
50 | Structured summary: schema coercion, render round-trip + byte stability + section order, code-layer caps + annotations, verbatim latest request, json_mode/json_repair/free-form tiers, prior-doc JSON chaining, legacy-MD transition, evicted-refs collection + carry-forward |
tests/agent/middlewares/test_summary_active_plan.py |
20 | Part 1: plan-active detection (state/todo refs, all-done gate, fail-open), prompt injection on first/update paths, notes inherit/append/cap/clear across chained compressions, verbatim latest request + eviction pointer, multi-message burst |
tests/agent/middlewares/test_compression_e2e_static.py |
18 | 6 end-to-end scenarios + 3 overflow-counter regression tests × 2 registration orders, static-fallback compaction, zero network |
tests/agent/middlewares/test_summarization_trigger.py |
3 | Registration contract (test-pinned window): MAIN_LLM_MAX_TOKEN = 65 536 → trigger threshold 52 428; low-token pass-through |
tests/agent/middlewares/test_summarization_comprehensive.py |
143 | Legacy deep suite: cutoff/budget, FIFO caps, fallback, prune/dedup/target-truncate, degradation |
tests/agent/middlewares/test_e2e_summarization.py |
7 | Full-graph hermetic e2e: real create_agent chain (capturing stub main, failing stub auxiliary) drives the static-fallback path; zero network, scaled-down window 32 000, skips when MAIN_LLM config is missing |
tests/agent/middlewares/message_persistence/ |
31 | Per-boundary flush (+ tool return): each message exactly once, no duplicate across boundaries, restart replay via the persistent watermark, sync + async hooks, missing-session_id skip, HITL denial re-pairing, filter semantics; plus T1/T2/T3 compactions proving zero store writes and the summary pair (both halves) proving zero writes |
tests/agent/middlewares/test_compression_background_reviews.py |
2 | Compression-time background-review dispatch: memory review + skill review fire from the compact path; no-cut compactions dispatch nothing |
tests/context_engine/store/test_persisted_message_ids.py |
3 | Persistent watermark store: idempotent marking, session scoping, cleanup on session deletion, empty-input no-ops |
tests/context_engine/store/test_interrupt_marker_approach.py |
11 | Marker semantics: the summary pair survives later compaction; FACT C fixture (window 26 000 → usable 10 000, truncate line 7 000) |
The full process-isolated suite (uv run python tests/run_tests_split.py) passes in CI; the exact per-group totals are printed by the runner.
- ModelDownshift runs at the next pre-request check, not as a switch-time hook. The model override (with its context window) lands at the turn boundary; the following T1/T2 sees the smaller window and compacts if needed.
- Microcompact can preempt the LLM summary. When clearing old tool results alone brings the history under the preserve budget, the compact route is skipped; the memory-review pass then does not fire (no messages were discarded).
-
compact_nowis a tool, not a client command. The model calls it when the user asks; there is no/compactcomposer command. -
Tail retention is budget-based, not a message count. The preserve budget is
PRESERVE_RATIO× window clamped to [2 000, 15 000], plus the router'sTRUNCATABLE_RECENT_SKIPmargin; the constructor takes nokeepargument. -
Inert config keys.
SUMMARY_TRIM_TOKENS,AUTO_CONTINUE_PROMPT,DEGRADATION_MONITOR_COUNT, andFILE_OPS_SECTION_MAX_CHARSare defined in theSUMMARIZATIONTypedDict but consumed by nothing; they are not imported bysummarization/core.py. The live truncation knobs are the token-denominatedMAX_TOOL_OUTPUT_TOKENS,AGGRESSIVE_TRUNCATE_TOKENS, andSUMMARY_TOTAL_MAX_TOKENS; the character-denominated legacy keys remain only for compatibility/tests. -
The TTL registry is not wired into production.
record_first_seen/select_expired/truncate_expired(andPRUNE_TTL_SECONDS,TTL_REGISTRY_MAX_ENTRIES) are consumed only by tests; the middleware uses exclusivelytruncate_to_budget. A grep ofagent/finds no production call sites for the TTL trio. The registry is also volatile (in-memory, keyed bytool_call_id, lost on restart). -
Retained-but-inert code.
_preemptive_check(overflow.py:148) and_preemptive_truncate(compression.py:420) are reference-only: no production call site reaches the two-band preemption they implement. -
The estimator is a three-tier tokenizer-free heuristic, not a tokenizer. T1 returns provider-reported usage when available; T2 is the CJK-aware heuristic (CJK characters at
CHARS_PER_TOKEN_CJK = 2, everything else atCHARS_PER_TOKEN = 4); T3 is the legacylen // 4, the pure-ASCII degenerate case of T2. It is intentionally deterministic (reproducible tests, stable budgets);CHARS_PER_TOKEN_CJK = 2reflects Chinese averaging closer to 1–2 chars/token than 4. -
Where reported usage wins. T3 is the only reported-usage-driven trigger (
compute_pressuretakes the max). The T1/T2 route decision is estimate-driven (estimate + system-prompt overhead only); the legacy_check_triggerclause fallback usesmax(local estimate, reported). -
T3 never alters the returned response. A T3 dispatch's durable effects are the in-place truncation of tool results (message objects are shared with the graph state) and the anti-thrash bookkeeping; the compact route's
request.overrideat T3 is local and the original response is always returned. The whole T3 body is fail-open. -
T4/T5 bypass the anti-thrash matrix by design — that is the point of "forced". After
MAX_OVERFLOW_RETRIES (3)(shared T4/T5 counter, reset each turn), or if the forced-compression step itself fails, the ORIGINAL provider exception propagates (never swallowed, never replaced by the compression error). -
Compression is fail-open. Any exception inside
_apply_compressionis logged and swallowed; the turn proceeds with the uncompressed history. - The static fallback is heuristic. Keyword-based decision/completed classification and path extraction from raw tool args are best-effort; the section skeleton is guaranteed, the content quality is not.
-
The structured tier runs in
json_modebecause the configured endpoint requires it.glm-5.3-flash(openai-compatible) does not emit function calls forwith_structured_output, so the default function-calling method raises a Pydantic parse error;_structured_runnableretries without themethodkwarg for providers whosewith_structured_outputrejects it, and thejson_repair+ free-form tiers cover the rest. The code-layer caps and the renderer still guarantee the output shape. -
_SUMMARY_PREFIX/_SUMMARY_SUFFIX/<summary>tags/lc_source="summarization"are load-bearing exact strings. Later-turn chaining (_extract_previous_summary), prune stop-condition, and the test suites all match them literally — do not reword them casually.
Generated from the repository's wiki/ tree. Source