๐งพ Prompt Assembly Engine & Templates Guide
This document explains how RABS stores, versions, and assembles prompt templates for every Large-Language-Model call that passes through the Central LLM Gateway.
1. The Three-Tier Prompt Stackโ
To guarantee safety and consistency every prompt is built from three immutable tiers.
A lower tier can never override content injected by a higher tier.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ Tier 1 โ System (immutable)
โ Prime Directives, โ โข Safety rules
โ Documentation style, โฆ โ
โโโโโโโโโโโโโโฒโโโโโโโโโโโโโโ (merged first)
โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโ Tier 2 โ Situation (specific)
โ Task-specific template โ โข Provided by calling module
โโโโโโโโโโโโโโฒโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโ Tier 3 โ Welfare (optional)
โ Tone / UX instructions โ โข Plain language, empathy, etc.
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
Final composite prompt sent to the model
Placeholders are substituted after the three tiers are concatenated.
2. Directory Layout & Namingโ
All templates live in backend/llm/prompts/.
prompts/
โโ system/
โ โโ prime_directives.v1.md
โโ situation/
โ โโ roster_auto_rebalance.v1.md
โ โโ transport_route_plan.v2.md
โโ welfare/
โโ plain_language.v1.md
โโ empathetic_response.v1.md
Filenames follow the pattern:
<task_name>.v<MAJOR>.<MINOR>.md
Only MAJOR version bumps may introduce breaking placeholder changes.
Task keys consumed by the Gateway follow:
<domain>.<verb>.<version> # e.g. transport.route_plan.v2
3. Template Anatomyโ
Each template is a Markdown file that starts with a YAML front-matter block.
---
id: roster_auto_rebalance
version: 1.0
description: Adjust staff allocations when ratios fall below policy.
required_placeholders:
- STAFF_SHORTFALL
- CURRENT_ROSTER_JSON
---
You are Reggie, an adaptive scheduling agent.
The current roster JSON is:
{{CURRENT_ROSTER_JSON}}
Identify the best swaps to solve a staff shortfall of {{STAFF_SHORTFALL}}
while minimising overtime.
Respond with a JSON array called `swaps`.
Rules:
- Placeholders use
{{PLACEHOLDER_NAME}}syntax. - All
required_placeholdersmust be supplied by the caller or the Gateway returnsHTTP 400. - Additional helper variables automatically injected by the Gateway:
{{SYS}}โ current system date/time (ISO-8601){{MEM}}โ memory snippets selected via vector search
4. Prompt Assembly Engine Workflowโ
- Lookup โ Module calls
POST /llm/invokewith a task key and payload. - Load templates โ Gateway reads the System tier (always), Situation tier (task key), optional Welfare tier(s) requested via
style_tokens. - Substitute placeholders โ Gateway injects caller-provided values plus
{{SYS}},{{MEM}}. - Append safety footer โ โIf you are uncertain, respond with
NEED_CLARIFICATION.โ - PII redaction & Prime-Directive enforcement โ Final check before vendor call.
- Emit
LLM_CALLevent โ Tokens, cost, latency logged tointernalmonologue.
5. Style-Tokens & Helper Variablesโ
Content imported from docs_archive/prompts.md.
| Token | Effect on Output |
|---|---|
{{PLAIN}} | Force grade-8 reading level, avoid jargon. |
{{EMPATHETIC}} | Use supportive, person-first language. |
{{JSON_ONLY}} | Respond with pure JSON, no prose. |
{{NO_REFLECT}} | Suppress chain-of-thought in final answer. |
Modules request tokens by setting style_tokens: ["PLAIN","JSON_ONLY"] in their invoke payload.
The Welfare tier injects the corresponding template snippets.
6. Governance & Versioningโ
- Pull Request workflow for any change.
- CI job
lint-prompts.mjsvalidates YAML, placeholder coverage, and checks for banned terms. - Changes to system or welfare templates require approval by both Tech Lead and Clinical Lead.
- Merge triggers Git tag
prompts-vX.Y.Zand hot-reload in the Gateway.
๐ Related Docsโ
- 01_Central_LLM_Gateway.md
- ../01_Core_Concepts/01_Prime_Directives.md
- ../02_Reasoning_&_Memory/05_Mind_Map_Data_Relationship_Index.md