- Session Initialization Rule: Load ONLY SOUL.md, USER.md, IDENTITY.md, memory/YYYY-MM-DD.md * Skip MEMORY.md, session history on startup (load on-demand via memory_search) * Result: 50KB → 8KB context = 80% token savings - Model Routing: Haiku default, Sonnet/Opus for complex reasoning only * Haiku: routine tasks, memory searches (/bin/bash.00025/1K tokens) * Sonnet/Opus: architecture, security, complex debugging - Prompt Caching enabled for Sonnet + Opus (90% discount on reused content) * TTL: 5m cache window * Static files (SOUL.md, USER.md) cached automatically * Savings: 5KB prompt = $0.015 → $0.0015 per reused call - Rate Limits: 5s between API calls, 10s between searches, max 5 searches/batch - Budgets: $5/day warning @ 75%, $200/month warning @ 75% Gateway config (~/.openclaw/clawdbot.json): * agents.defaults.model.cache enabled for opus + sonnet * rateLimits + budgets sections added * heartbeat routing to Ollama ready (manual setup) Files updated: - AGENTS.md: Core optimization rules documented - memory/kb/tools/session-initialization.md: Detailed initialization strategy - ~/.openclaw/clawdbot.json: Model config + caching + rate limits + budgets
1.9 KiB
1.9 KiB
Session Initialization Rule
Purpose: Minimize context overhead and token waste by explicitly controlling what loads on every session start.
ON SESSION START: Load ONLY These Files
- SOUL.md — Core principles, tone, boundaries
- USER.md — Who I'm working with, timezone, preferences
- IDENTITY.md — Self-definition (name, vibe, emoji)
- memory/YYYY-MM-DD.md (if today's note exists) — Daily context
Total overhead: ~8KB instead of 50KB+
DO NOT Auto-Load
- ❌ MEMORY.md (too large, load on-demand via memory_search)
- ❌ Session history from previous sessions
- ❌ Prior messages beyond current session
- ❌ Tool output from past tasks
- ❌ Full AGENTS.md unless explicitly needed
- ❌ TOOLS.md unless explicitly needed
When User Asks About Prior Context
Example: "What did we decide about the refactoring?"
Response:
- Use
memory_search(query="refactoring decision")to find relevant snippets - Use
memory_get(path="...", lines=5-10)to pull only the needed lines - Quote the specific snippet with Source: attribution
- Don't load entire files
Session End: Update memory/YYYY-MM-DD.md
Before session closes, append to memory/YYYY-MM-DD.md:
## [Session Time] - [Topic/Task]
**What we did:**
- Item 1
- Item 2
**Decisions made:**
- Decision 1
**Blockers:**
- Blocker 1
**Next steps:**
- Step 1
Cost Impact
| Metric | Before | After |
|---|---|---|
| Context per session | 50KB | 8KB |
| Token waste | 2-3M per session | ~300K |
| Cost per session | $0.40 | $0.05 |
| Cost per 100 sessions | $40 | $5 |
Implementation Checklist
- This rule is documented in system prompt
- Echo knows to use memory_search() on-demand
- Echo knows to pull snippets, not whole files
- Daily notes are in memory/YYYY-MM-DD.md format
- Echo updates notes at session end