OpenClaw Context Assembly
OpenClaw Context Assembly
Phase 3 of the Gateway execution flow. The Agent Runtime assembles the full context window before invoking the model.
Components
Session History
Conversation turns from the current session, managed by the SessionManager (write-locked, append-only in-process log). See Agent Loop (OpenClaw).
System Prompt Files
Three dedicated files define the agent's operating context:
| File | Purpose |
|---|---|
AGENTS.md |
Describes available sub-agents and their capabilities |
SOUL.md |
Persona, values, behavioral guidelines for the agent |
TOOLS.md |
Tool definitions and usage instructions |
These are loaded and injected into the system prompt at context-assembly time.

Memory Retrieval
Semantically relevant memories are fetched via hybrid search — combining vector similarity and keyword search — and prepended or injected into context. This gives the agent access to long-term memory beyond the session window.
See Memory System for file layout and backends, Memory Search for dual-retrieval mechanics (temporal decay, MMR), and Builtin Memory Engine for the default SQLite implementation.
Assembly Order (inferred)
- System prompt (SOUL.md + AGENTS.md + TOOLS.md)
- Retrieved memory chunks (hybrid search results)
- Session history (recent turns)
- Current user message
Related
- Agent Loop (OpenClaw) — the loop that calls context assembly
- OpenClaw Gateway — six-phase flow context
- Durable Session Storage — external session log (contrast: OpenClaw uses in-process SessionManager)
- Compaction — what happens when context grows too large