context - kongusen/loom-agent GitHub Wiki
Context is the agent's only perception interface. Everything the model knows about the current task comes from the context window.
C = C_system β C_memory β C_skill β C_history β C_working
| Partition | Purpose | Compressed? |
|---|---|---|
C_system |
Harness-injected instructions | Never |
C_working |
Dashboard, plan, events, scratchpad | Never |
C_memory |
AGENTS.md, persistent notes | Rarely |
C_skill |
Active skill/tool declarations | Swapped on demand |
C_history |
Execution history | Yes β first to go |
Protection priority: C_system > C_working > C_memory > C_skill > C_history
C_working is not a log. It's the model's working memory:
C_working = {
"dashboard": {
"rho": # context pressure (0.0β1.0)
"token_budget": # remaining budget
"goal_progress": # model's self-assessment
"error_count": # recent errors
"depth": # sub-agent recursion depth
"last_hb_ts": # last heartbeat timestamp
"interrupt_requested": # H_b interrupt flag
},
"plan": [...], # current task plan
"event_surface": {...}, # pending events, active risks
"knowledge_surface": {...}, # active questions, evidence packs
"scratchpad": "...", # short-term reasoning
}Triggered by context pressure Ο, one level per turn:
| Level | Trigger | Strategy |
|---|---|---|
| Snip | Ο > 0.7 | Truncate messages over 2000 chars |
| Micro | Ο > 0.8 | Deduplicate tool results by call ID |
| Collapse | Ο > 0.9 | Extractive summary of middle messages |
| Auto | Ο > 0.95 | Score-based keep: KΒ·relΒ·e^(βλ·age) |
| Reactive | API 413 | Emergency: auto + snip at 500 chars |
When Ο β₯ 1.0, Loom snapshots C_working to M_f (filesystem), compresses history, and rebuilds a fresh context window. The agent continues without losing its working state.
Code: loom/context/