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:

#LayerSourcePriority
1bootstrapDate, timezone, agent name100
2personaSOUL.md90
3userUSER.md80
4identityIDENTITY.md70
5toolsTOOLS.md60
6skillsSkill descriptions50
7memoryActive memory entries40
8commitmentsOpen agent promises30
9standingUser's standing orders20
10projectAGENTS.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

What's next?