Context Engine
Builds the agent's system prompt from typed layers in a deterministic order. Each layer is independent and can be enabled, disabled, or modified by hooks.
The 10 layers
Top to bottom in the final prompt:
| # | Layer | Source | Priority |
|---|---|---|---|
| 1 | bootstrap | Date, timezone, agent name | 100 |
| 2 | persona | SOUL.md | 90 |
| 3 | user | USER.md | 80 |
| 4 | identity | IDENTITY.md | 70 |
| 5 | tools | TOOLS.md | 60 |
| 6 | skills | Skill descriptions | 50 |
| 7 | memory | Active memory entries | 40 |
| 8 | commitments | Open agent promises | 30 |
| 9 | standing | User's standing orders | 20 |
| 10 | project | AGENTS.md (walks up dirs) | 10 |
Inspecting the built context
To see what the agent will actually see:
curl -X POST http://127.0.0.1:18789/agent/bags-hunter/context \
-d '{
"sessionKey": "user-123",
"recentMessages": [{"content": "what tokens look good today"}]
}'Returns the assembled prompt + a per-layer breakdown (name, priority, char count).
Excluding layers
For minimal prompts (testing, debugging), exclude layers:
curl -X POST http://127.0.0.1:18789/agent/auto/context \
-d '{
"sessionKey": "user-123",
"excludeLayers": ["memory", "commitments", "standing"]
}'Resolution order โ user vs bundled
For each agent, the engine first checks ~/.openvesper/agents/<mode>/. If the agent is installed there, files load from user dir. Otherwise from bundled .agents/<mode>/.
Project AGENTS.md walk
The engine walks up to 5 directory levels from process.cwd() looking for AGENTS.md. The first one found becomes the project layer. This lets projects inject team conventions automatically.
Source
Implementation: apps/gateway/src/context-engine.ts