Five layers, fixed budget.
System prompt, tool schemas, memory block, conversation, output headroom. Each layer competes for room, but identity always survives.
The model's context window minus output headroom = total budget. Each layer (system, tools, memory, conversation) gets a slice with priority weights.
If layers compete, system prompt and self-identity sections truncate last. The agent's sense of who-it-is stays intact.
At 60% budget, the system extracts valuable content (decisions, facts, file paths) and writes them to the daily log. Compression loses detail; the log preserves it.
Verbose tool results trim to summaries. Cheap, fast, and the model rarely notices. tool_use/tool_result pairs stay bonded.
Older messages compress through a summarization model call. The summary passes through injection gates so jailbreaks in old messages can't survive into the new context.
If summarization still doesn't fit, the system resets to summary-plus-last-message. The model always has room to generate. The trace records that fallback fired.