A forensic deep-dive into the Meta-Agentic Prompt Construction and Orchestration logic of the OpenClaw repository.
01. Prompt Composition Flow
graph TD
subgraph "Phase 1: Cache-Stable Metadata"
A[Identity: OpenClaw Persona] --> B[Tooling: Policy-Filtered Definition]
B --> C[Safety: Anti-Replication & Goals]
C --> D[Style: Narrated vs Silent Interaction]
D --> E[Stable Context: .md Files Hierarchy]
end
E --> F{SYSTEM_PROMPT_CACHE_BOUNDARY}
subgraph "Phase 2: Dynamic Seam (High Volatility)"
F --> G[Dynamic Context: Volatile Project Files]
G --> H[Heartbeat: Real-time Chronos/State]
H --> I[Runtime: Host/Agent Capabilities]
end
subgraph "Phase 3: Execution Loop"
I --> J[Base Prompt Aggregation]
J --> K[Instruction Injection: Fast Path/Retries]
K --> L[Final LLM Context Payload]
end
style F fill:#FF00FF,stroke:#fff,stroke-width:2px,color:#fff
style L fill:#00FFFF,stroke:#fff,stroke-width:2px,color:#000
Orchestration Intelligence
The pi-embedded-runner implements a "Stateful Attempt Lifecycle" that monitors token pressure in real-time. If prompt usage exceeds 65% during a timeout, the system triggers preemptive compaction to break potential death-spirals.
• Context Overflow Diagnostics (diagId)
• Auth Rotation (Profile Candidate Switching)
• Cross-Provider Fallback Logic
Subagent Inheritance
subagent-spawn.ts ensures cryptographic session separation while maintaining environment continuity. Subagents inherit workspace mounts and sandboxing state but operate on a pruned "minimal" prompt mode for efficiency.