- 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
70 lines
1.9 KiB
Markdown
70 lines
1.9 KiB
Markdown
# 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
|
|
|
|
1. **SOUL.md** — Core principles, tone, boundaries
|
|
2. **USER.md** — Who I'm working with, timezone, preferences
|
|
3. **IDENTITY.md** — Self-definition (name, vibe, emoji)
|
|
4. **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:**
|
|
1. Use `memory_search(query="refactoring decision")` to find relevant snippets
|
|
2. Use `memory_get(path="...", lines=5-10)` to pull only the needed lines
|
|
3. Quote the specific snippet with Source: attribution
|
|
4. Don't load entire files
|
|
|
|
## Session End: Update memory/YYYY-MM-DD.md
|
|
|
|
Before session closes, append to `memory/YYYY-MM-DD.md`:
|
|
|
|
```markdown
|
|
## [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
|
|
|
|
- [x] This rule is documented in system prompt
|
|
- [x] Echo knows to use memory_search() on-demand
|
|
- [x] Echo knows to pull snippets, not whole files
|
|
- [x] Daily notes are in memory/YYYY-MM-DD.md format
|
|
- [x] Echo updates notes at session end
|