Skip to main content
Prompts are code. When you hardcode a system prompt in a handler file, changing it means a full redeploy, you lose history, and rolling back means reverting a commit. PromptRegistry treats prompts as first-class, versioned artifacts backed by your existing StateStore. You can pin a route to a specific version, diff two versions line-by-line, and roll forward or backward entirely independently of code changes.

Setup

Create a PromptRegistry backed by any StateStore:
For tests or one-off scripts, pass a MemoryStateStore instead — it requires no file I/O or native dependencies.

Registering prompts

Call registry.register(name, template, note?) to append a new immutable version. Version numbers start at 1 and increment automatically.
register returns a PromptVersion object:

Retrieving prompts

registry.get(name, version?)

Returns the latest version when version is omitted, or the specific version if provided. Returns undefined if the prompt or version does not exist.

registry.list(name)

Returns all versions for a named prompt as a PromptVersion[] array, oldest first.

registry.names()

Returns an array of all prompt names registered in the store.

Diffing versions

registry.diff(name, from, to) returns a line-level diff between two versions. Use this in a deploy pipeline or admin UI to review prompt changes before promoting them.
PromptDiff fields:

Rendering templates

renderPrompt(template, vars) fills {{varName}} placeholders in a template string with values from a plain object. Missing variables are replaced with empty strings.
Placeholders support optional whitespace: {{ varName }} and {{varName}} are both valid.

Using a registry in an agent

Fetch the prompt template at startup, render it with runtime variables, and pass it as the agent’s system prompt.
1

Register your prompt (once, at setup time)

2

Fetch and render the prompt in your agent definition

3

Roll back without redeploying

Pin a different version number in registry.get() and restart the process — no code change required.

Reviewing changes programmatically

Run a diff in CI to surface prompt changes alongside code changes:
Store the PromptRegistry instance as a singleton module export so every route and agent shares the same registry and the same underlying StateStore connection.