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.

openclaw-arch-system-prompt-composition.png

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)

  1. System prompt (SOUL.md + AGENTS.md + TOOLS.md)
  2. Retrieved memory chunks (hybrid search results)
  3. Session history (recent turns)
  4. Current user message