lesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rotlesson 3 of 6 · context engineering — fighting the rotcontext engineering — fighting the rot
Checkpoint
One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.
Final context-engineering drill. Write manage_session(items, budget, threshold_pct)
that combines budget-planning with a compaction trigger.
Returns a dict with FOUR fields:
loaded: list of item names that fit in the budget (priority-desc, then name-asc; greedy fill)offloaded: list of item names that didn't fit (same sort order)load_pct: int 0-100, percentage of budget used (rounded to nearest,round(100 * used / budget))compact_targets: list of up to TWO item names — the LOWEST priority items currently inloaded. Only populated ifload_pct > threshold_pct; otherwise empty list. Order: priority ascending, then name ascending.
Five items, 4000-token budget, 75% threshold. Expected output:
loaded: ['claude_md', 'current_task', 'recent_tool_results', 'session_history']
offloaded: ['deploy_skill']
load_pct: 92
compact_targets: ['session_history', 'recent_tool_results']