Skip to main content

Interface: PromptTemplateStore

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:79

PromptTemplateStore -- the prompts as data: every prompt text the gateway writes, keyed by job and versioned

About​

A new wording is a new version, activated without a deploy, and every answer can be traced back to the version that produced it.

Holds the text of each prompt (EPromptTemplateKey: the main chat system prompt, the memory extractors, the query rewriter, the title) and fills its {slots} for a call.

  • One active version per key, served from a cache and refreshed after cacheTtlMs.
  • The history of a key stays in the repository for the admin UI and for rollback; it is read only on request, paged.
  • The seed (version 0) answers when the repository has no active version, so a fresh database works at once; the host overrides it per key with seedTemplates.

Global: one copy for all tenants; tenant flavour comes only through the profile's addendum slot. See docs/60-architecture/90-decisions.md § PromptTemplateStore.

Who needs it​

ContextAssembler renders CHAT_MAIN; WorkingMemory, UserMemoryStore and QueryRewriter render their own key. The admin methods (listVersions, addVersion, activate) are for the host's administration screen.

What needs​

IPromptTemplateStoreConfig: the IPromptTemplateRepository, the optional cacheTtlMs and the optional seedTemplates.

Usage​

When to use it​

Every text that goes to a model as a system prompt; a class asks for its key and never composes prompt text in code.

When shouldn't use it​

Per-call or per-tenant text: that is a slot value (instructions, context, the profile addendum), not a template.

Pitfalls​

A missing slot throws; render with every slot the active version uses, also with an empty string. addVersion saves an inactive version; nothing changes for callers until activate. activate takes effect for other instances only after their cache expires.

Implements​

Methods​

activate()​

activate(__namedParameters): Promise<void>

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:291

activate -- makes one version the wording in force for its key

About​

One active version per key: this one on, the others off, as one repository operation.

The version must exist (404 otherwise). Drops this instance's cache, so its next render uses the version; other instances follow after their TTL.

Who needs it​

The host's administration screen, for a new wording and for a rollback.

Pitfalls​

CHAT_MAIN is cached by the provider only when the version keeps {cacheBreakpoint} with no per-call slot before it; a version without {skills} drops the skills of a call with the WARNING skills_slot_missing.

Parameters​

__namedParameters​
key​

EPromptTemplateKey

version​

number

Returns​

Promise<void>

Implementation of​

IPromptTemplateStore.activate


addVersion()​

addVersion(__namedParameters): Promise<IPromptTemplate>

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:244

addVersion -- saves a new wording of a key, inactive

About​

A new version is a draft until activate: nothing changes for the calls.

Numbers the version after the newest one of the key (the seed is 0, the first stored version 1) and saves it with isActive: false. Returns the stored template.

Who needs it​

The host's administration screen.

Parameters​

__namedParameters​
body​

string

key​

EPromptTemplateKey

Returns​

Promise<IPromptTemplate>

Implementation of​

IPromptTemplateStore.addVersion


get()​

get(__namedParameters): Promise<IPromptTemplate>

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:99

get -- the active template of a key

About​

The wording in force for a job, with its version.

Reads the cached active templates. Falls back to the seed (version 0) when the repository has no active version for the key: the host's seedTemplates entry, else the shipped one; a key with neither is a 404.

Who needs it​

ContextAssembler, which needs the body of CHAT_MAIN before it renders (the cache breakpoint, the {skills} slot); the other callers go through render.

Parameters​

__namedParameters​
key​

EPromptTemplateKey

Returns​

Promise<IPromptTemplate>

Implementation of​

IPromptTemplateStore.get


listVersions()​

listVersions(__namedParameters): Promise<IPage<IPromptTemplate>>

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:192

listVersions -- the history of a key, paged, for the administration screen

About​

Every version of a key, highest first; the cursors are version numbers.

Validates the page (a limit outside 1–200 or both cursors at once is a 400) and reads the repository: the history is never cached. An unknown cursor is the repository's 404.

Who needs it​

The host's administration screen, before activate (pick a version) and after addVersion (see it listed).

Parameters​

__namedParameters​
key​

EPromptTemplateKey

page​

IPageArgs<number>

Returns​

Promise<IPage<IPromptTemplate>>

Implementation of​

IPromptTemplateStore.listVersions


refresh()​

refresh(): Promise<void>

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:331

refresh -- drops the cache and reloads the active templates from the repository

About​

For a host that changed the repository behind the store's back.

The next renders use the reloaded versions; nothing else changes.

Returns​

Promise<void>

Implementation of​

IPromptTemplateStore.refresh


render()​

render(__namedParameters): Promise<IRenderedPrompt>

Defined in: internal/prompt-template-store/PromptTemplateStore.ts:144

render -- the active template of a key with its slots filled

About​

The text that goes to the model, and the version that produced it.

Replaces every {slot} of the active body (get) with the value of that name and returns the text with key and version, so the trace can record which wording produced which answer. A slot without a value is a 400: a silent empty slot is the classic prompt bug. A value given for a slot the body does not use is ignored.

Who needs it​

ContextAssembler (CHAT_MAIN), WorkingMemory (MEMORY_WORKING), UserMemoryStore (MEMORY_USER), QueryRewriter (KB_QUERY_REWRITE): each renders its own key before its model call.

Pitfalls​

Pass every slot the active version uses, with an empty string when there is nothing to say. A stored version may use fewer slots than the seed, never more than its key's list (IPromptTemplateStoreConfig.seedTemplates).

Parameters​

__namedParameters​
key​

EPromptTemplateKey

slots​

Record<string, string>

Slot values; keys match {slot} names.

Returns​

Promise<IRenderedPrompt>

Implementation of​

IPromptTemplateStore.render