|
| 1 | +# Checkpoint Workflow with Microkernel and Context Modes |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Complete workflow for checkpoint creation with microkernel generation and context mode transitions. |
| 6 | + |
| 7 | +## Checkpoint Workflow |
| 8 | + |
| 9 | +### 1. Threshold Detection |
| 10 | + |
| 11 | +```python |
| 12 | +# Model-specific dynamic threshold |
| 13 | +context_window = CONTEXT_WINDOWS[model_id] |
| 14 | +threshold_pct = calculate_checkpoint_threshold(context_window) |
| 15 | +# 64K → 90%, 128K → 71%, 200K → 59%, 1MB → 15% |
| 16 | + |
| 17 | +checkpoint_threshold = int(context_window * threshold_pct) |
| 18 | + |
| 19 | +if token_count >= checkpoint_threshold: |
| 20 | + # Trigger checkpoint creation |
| 21 | +``` |
| 22 | + |
| 23 | +### 2. Microkernel Generation (BEFORE Dump) |
| 24 | + |
| 25 | +```python |
| 26 | +microkernel = generate_microkernel(message_lists) |
| 27 | + |
| 28 | +# Microkernel contains: |
| 29 | +{ |
| 30 | + "tasks": [ |
| 31 | + {"content": "Implement OAuth callback", "status": "in_progress"}, |
| 32 | + {"content": "Add error handling", "status": "pending"} |
| 33 | + ], |
| 34 | + "goals": [ |
| 35 | + "Build OAuth login system", |
| 36 | + "Integrate with JWT tokens" |
| 37 | + ], |
| 38 | + "current_activity": [ |
| 39 | + {"tool": "Edit", "context": "auth.ts - adding callback handler"}, |
| 40 | + {"tool": "Read", "context": "middleware.ts - reviewing auth flow"} |
| 41 | + ], |
| 42 | + "planned_verbs": ["implement", "test", "debug"], |
| 43 | + "important_breadcrumbs": [ |
| 44 | + "auth.ts", |
| 45 | + "middleware.ts", |
| 46 | + "jwt.ts", |
| 47 | + "test_oauth.py" |
| 48 | + ] |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +**Purpose**: Model knows what will be important breadcrumbs before checkpoint is created. |
| 53 | + |
| 54 | +### 3. Checkpoint Creation |
| 55 | + |
| 56 | +```python |
| 57 | +slab_id = await checkpoint_system.create_checkpoint( |
| 58 | + message_lists=message_lists, |
| 59 | + microkernel=microkernel # Injected into payload and backdrop |
| 60 | +) |
| 61 | + |
| 62 | +# Checkpoint stored: |
| 63 | +# - slab_001/payload.mp4 (QR-encoded, includes microkernel) |
| 64 | +# - slab_001/backdrop.mp4 (QR-encoded, includes microkernel) |
| 65 | +# - Indexed: hashtable + (future) vector store |
| 66 | +``` |
| 67 | + |
| 68 | +**Context NOT evicted** - remains in L1, checkpoint indexed for recall. |
| 69 | + |
| 70 | +### 4. Context Mode Transition |
| 71 | + |
| 72 | +After checkpoint created, model can operate in different modes: |
| 73 | + |
| 74 | +#### Mode 1: SUSPENDED (Microkernel Only) |
| 75 | + |
| 76 | +```python |
| 77 | +context_mode.transition_to_suspended(slab_id, microkernel) |
| 78 | + |
| 79 | +# Model sees: |
| 80 | +# - Tasks: 2 pending |
| 81 | +# - Goals: Build OAuth login |
| 82 | +# - Activity: Editing auth.ts |
| 83 | +# - Breadcrumbs: auth.ts, middleware.ts, jwt.ts, test_oauth.py |
| 84 | +``` |
| 85 | + |
| 86 | +**Use case**: Lightweight operation with just the gist. Full context checkpointed but not loaded. |
| 87 | + |
| 88 | +#### Mode 2: HIGH_DETAIL (Expanded Context for Specific Focus) |
| 89 | + |
| 90 | +```python |
| 91 | +context_mode.transition_to_high_detail(focus="OAuth token refresh") |
| 92 | + |
| 93 | +# Model can now: |
| 94 | +# 1. Use RecallContext("OAuth token refresh") → breadcrumb trail |
| 95 | +# 2. Use MicrocontextSubroutine("OAuth token refresh", depth=3, focus="operational") |
| 96 | +# → Temporarily expand context with digested slabs |
| 97 | +``` |
| 98 | + |
| 99 | +**Use case**: Deep dive on specific aspect. Expand context selectively for that focus. |
| 100 | + |
| 101 | +**Workflow**: |
| 102 | +1. Query breadcrumbs: `RecallContext("OAuth token refresh")` |
| 103 | +2. Get trail: `[slab_001] → [slab_002] ⟳ [slab_003]` |
| 104 | +3. Digest relevant slabs: `MicrocontextSubroutine` returns operational state |
| 105 | +4. Work on detail with expanded context |
| 106 | +5. Return to SUSPENDED when done |
| 107 | + |
| 108 | +#### Mode 3: HIGH_CAPACITY (Empty Context for Pure Thinking) |
| 109 | + |
| 110 | +```python |
| 111 | +context_mode.transition_to_high_capacity() |
| 112 | + |
| 113 | +# Context: EMPTY (as minimal as possible) |
| 114 | +# Only microkernel present |
| 115 | +# Maximum space for thinking |
| 116 | +``` |
| 117 | + |
| 118 | +**Use case**: Complex reasoning, planning, analysis without historical context weight. |
| 119 | + |
| 120 | +**Workflow**: |
| 121 | +1. Enter HIGH_CAPACITY mode |
| 122 | +2. Context stripped to microkernel only |
| 123 | +3. Model has maximum token budget for pure thinking |
| 124 | +4. Think through problem, make plans, reason about architecture |
| 125 | +5. Return to NORMAL with conclusions |
| 126 | + |
| 127 | +#### Mode 4: RESUME_NORMAL |
| 128 | + |
| 129 | +```python |
| 130 | +context_mode.return_to_normal() |
| 131 | + |
| 132 | +# Back to standard operation |
| 133 | +# Context from L1 still available |
| 134 | +``` |
| 135 | + |
| 136 | +## Complete Example |
| 137 | + |
| 138 | +```python |
| 139 | +# 1. Detect threshold |
| 140 | +if token_count >= 117_823: # Claude 200K @ 59% |
| 141 | + # 2. Generate microkernel |
| 142 | + microkernel = generate_microkernel(message_lists) |
| 143 | + |
| 144 | + # 3. Create checkpoint |
| 145 | + slab_id = await checkpoint_system.create_checkpoint( |
| 146 | + message_lists, microkernel=microkernel |
| 147 | + ) |
| 148 | + logger.info(f"Checkpoint {slab_id} created with microkernel") |
| 149 | + |
| 150 | + # 4. Transition to SUSPENDED mode |
| 151 | + context_mode.transition_to_suspended(slab_id, microkernel) |
| 152 | + # Model now operates on microkernel only |
| 153 | + |
| 154 | +# Later: Need to work on OAuth implementation |
| 155 | +context_mode.transition_to_high_detail("OAuth implementation") |
| 156 | + |
| 157 | +# Use tools to expand context |
| 158 | +trail = await recall_tool.execute("OAuth implementation") |
| 159 | +# Returns breadcrumb trail: [slab_001] → [slab_002] ⟳ [slab_003] |
| 160 | + |
| 161 | +# Digest for detail work |
| 162 | +digest = await microcontext_tool.execute( |
| 163 | + query="OAuth implementation", |
| 164 | + depth=3, |
| 165 | + focus="operational" |
| 166 | +) |
| 167 | +# Returns: pending tasks, files modified, code changes |
| 168 | + |
| 169 | +# Work on implementation with expanded detail... |
| 170 | + |
| 171 | +# Now need to think through architecture |
| 172 | +context_mode.transition_to_high_capacity() |
| 173 | +# Context cleared to microkernel only, maximum thinking space |
| 174 | + |
| 175 | +# Deep reasoning... |
| 176 | + |
| 177 | +# Resume normal operation |
| 178 | +context_mode.return_to_normal() |
| 179 | +``` |
| 180 | + |
| 181 | +## Key Principles |
| 182 | + |
| 183 | +1. **Microkernel before checkpoint**: Model knows what matters before dump |
| 184 | +2. **Context not evicted**: Checkpoint indexed, original context stays in L1 |
| 185 | +3. **Mode transitions**: SUSPENDED → HIGH_DETAIL → HIGH_CAPACITY → NORMAL |
| 186 | +4. **Breadcrumb awareness**: Microkernel tells model what breadcrumbs are important |
| 187 | +5. **Empty for thinking**: HIGH_CAPACITY mode strips to minimal context |
| 188 | +6. **Tool-driven recall**: LLM decides when to expand (not automatic) |
| 189 | + |
| 190 | +## Benefits |
| 191 | + |
| 192 | +- **Context awareness**: Model understands what to remember before checkpoint |
| 193 | +- **Flexible modes**: Suspend, detail dive, or pure thinking as needed |
| 194 | +- **Lossless**: Full history preserved, selectively retrieved |
| 195 | +- **Efficient**: Only expand context when needed for specific tasks |
| 196 | +- **Cognitive offload**: Microkernel maintains minimal state between modes |
0 commit comments