2026-02-12 18:18:25 +00:00
|
|
|
|
# Backend Templates (Product Documentation)
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
This folder contains the Markdown templates Mission Control syncs into OpenClaw agent workspaces.
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- Location in repo: `backend/templates/`
|
|
|
|
|
|
- Runtime location in backend container: `/app/templates`
|
|
|
|
|
|
- Render engine: Jinja2
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
## What this is for
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Use these templates to control what an agent sees in workspace files like:
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- `AGENTS.md`
|
|
|
|
|
|
- `HEARTBEAT.md`
|
|
|
|
|
|
- `TOOLS.md`
|
|
|
|
|
|
- `IDENTITY.md`
|
|
|
|
|
|
- `USER.md`
|
|
|
|
|
|
- `MEMORY.md`
|
2026-02-13 02:08:30 +05:30
|
|
|
|
- `LEAD_PLAYBOOK.md` (supplemental lead examples/reference)
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
When a gateway template sync runs, these templates are rendered with agent/board context and written into each workspace.
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
## How rendering works
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Rendering configuration
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Defined in `backend/app/services/openclaw/provisioning.py` (`_template_env()`):
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- `StrictUndefined` enabled (missing variables fail fast)
|
|
|
|
|
|
- `autoescape=False` (Markdown output)
|
|
|
|
|
|
- `keep_trailing_newline=True`
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Context builders
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- Board agent context: `_build_context()`
|
|
|
|
|
|
- Main agent context: `_build_main_context()`
|
|
|
|
|
|
- User mapping: `_user_context()`
|
|
|
|
|
|
- Identity mapping: `_identity_context()`
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
## Sync entry points
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### API
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
`POST /api/v1/gateways/{gateway_id}/templates/sync`
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- Router: `backend/app/api/gateways.py` (`sync_gateway_templates`)
|
|
|
|
|
|
- Service: `backend/app/services/openclaw/provisioning_db.py`
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Script
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
`backend/scripts/sync_gateway_templates.py`
|
2026-02-12 12:48:49 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
python backend/scripts/sync_gateway_templates.py --gateway-id <uuid>
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Files included in sync
|
|
|
|
|
|
|
|
|
|
|
|
Default synced files are defined in:
|
|
|
|
|
|
|
|
|
|
|
|
- `backend/app/services/openclaw/constants.py` (`DEFAULT_GATEWAY_FILES`)
|
|
|
|
|
|
|
|
|
|
|
|
Main-agent template mapping is defined in:
|
|
|
|
|
|
|
|
|
|
|
|
- `backend/app/services/openclaw/constants.py` (`MAIN_TEMPLATE_MAP`)
|
|
|
|
|
|
|
|
|
|
|
|
## HEARTBEAT.md selection logic
|
|
|
|
|
|
|
|
|
|
|
|
`HEARTBEAT.md` is selected dynamically:
|
|
|
|
|
|
|
|
|
|
|
|
- Board lead -> `HEARTBEAT_LEAD.md`
|
|
|
|
|
|
- Non-lead agent -> `HEARTBEAT_AGENT.md`
|
|
|
|
|
|
|
|
|
|
|
|
See:
|
|
|
|
|
|
|
|
|
|
|
|
- `HEARTBEAT_LEAD_TEMPLATE`, `HEARTBEAT_AGENT_TEMPLATE` in constants
|
|
|
|
|
|
- `_heartbeat_template_name()` in provisioning
|
|
|
|
|
|
|
|
|
|
|
|
## Template variables reference
|
|
|
|
|
|
|
|
|
|
|
|
### Core keys (all templates)
|
|
|
|
|
|
|
|
|
|
|
|
- `agent_name`, `agent_id`, `session_key`
|
|
|
|
|
|
- `base_url`, `auth_token`, `main_session_key`
|
2026-02-12 12:48:49 +00:00
|
|
|
|
- `workspace_root`
|
|
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### User keys
|
|
|
|
|
|
|
2026-02-12 09:49:54 +00:00
|
|
|
|
- `user_name`, `user_preferred_name`, `user_pronouns`, `user_timezone`
|
|
|
|
|
|
- `user_notes`, `user_context`
|
|
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Identity keys
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- `identity_role`, `identity_communication_style`, `identity_emoji`
|
2026-02-12 09:49:54 +00:00
|
|
|
|
- `identity_autonomy_level`, `identity_verbosity`, `identity_output_format`, `identity_update_cadence`
|
|
|
|
|
|
- `identity_purpose`, `identity_personality`, `identity_custom_instructions`
|
|
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Board-agent-only keys
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
- `board_id`, `board_name`, `board_type`
|
|
|
|
|
|
- `board_objective`, `board_success_metrics`, `board_target_date`
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- `board_goal_confirmed`, `is_board_lead`
|
2026-02-12 09:49:54 +00:00
|
|
|
|
- `workspace_path`
|
|
|
|
|
|
|
2026-02-13 02:08:30 +05:30
|
|
|
|
## OpenAPI role tags for agents
|
|
|
|
|
|
|
|
|
|
|
|
Agent-facing endpoints expose role tags in OpenAPI so heartbeat files can filter
|
|
|
|
|
|
operations without path regex hacks:
|
|
|
|
|
|
|
|
|
|
|
|
- `agent-lead`: board lead workflows (delegation/review/coordination)
|
|
|
|
|
|
- `agent-worker`: non-lead board execution workflows
|
|
|
|
|
|
- `agent-main`: gateway main / cross-board control-plane workflows
|
|
|
|
|
|
|
|
|
|
|
|
Example filter:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
curl -s "$BASE_URL/openapi.json" \
|
|
|
|
|
|
| jq -r '.paths | to_entries[] | .key as $path
|
|
|
|
|
|
| .value | to_entries[]
|
|
|
|
|
|
| select((.value.tags // []) | index("agent-lead"))
|
|
|
|
|
|
| "\(.key|ascii_upcase)\t\($path)\t\(.value.operationId // "-")"'
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
## Safe change checklist
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Before merging template changes:
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
1. Do not introduce new `{{ var }}` placeholders unless context builders provide them.
|
|
|
|
|
|
2. Keep changes additive where possible.
|
|
|
|
|
|
3. Review both board-agent and `MAIN_*` templates when changing shared behavior.
|
|
|
|
|
|
4. Preserve agent-editable files behavior (`PRESERVE_AGENT_EDITABLE_FILES`).
|
|
|
|
|
|
5. Run docs quality checks and CI.
|
2026-02-13 02:08:30 +05:30
|
|
|
|
6. Keep heartbeat templates under injected-context size limits (20,000 chars each).
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
## Local validation
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Fast check
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Run CI-relevant docs checks locally:
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
```bash
|
|
|
|
|
|
make docs-check
|
|
|
|
|
|
```
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Full validation
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
- Push branch
|
|
|
|
|
|
- Confirm PR checks are green
|
|
|
|
|
|
- Optionally run template sync on a dev gateway and inspect generated workspace files
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
## FAQ
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Why did rendering fail after adding a variable?
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Because `StrictUndefined` is enabled. Add that key to `_build_context()` / `_build_main_context()` (and related mappers) before using it in templates.
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
### Why didn’t my edit appear in an agent workspace?
|
2026-02-12 09:49:54 +00:00
|
|
|
|
|
2026-02-12 18:18:25 +00:00
|
|
|
|
Template sync may not have run yet, or the target file is preserved as agent-editable. Check sync status and preservation rules in constants.
|