Language is not text, but a mapping from information to expression.
hb.Prompt persists prompts as Capsule-backed workspace rows with first-class translation.
1. Why Prompt Utilities Exist
Without a prompt system, every LLM call site assembles its own prompt text from raw f-strings. The result is prompt drift: one endpoint formats instructions one way, another endpoint uses different phrasing, and there is no single source of truth for what the prompt should say.2. Prompt as an Encoder
Think ofhb.Prompt as a named encoder — a callable you register, version, and reload. Format-string prompts are one encoding strategy; Python functions are another. Both compile into Capsule-backed callables and share one runtime path.
Prompt is a special case of Capsule. The prompt definition — source code or compiled format string — is captured as a manifest and can be stored as a sys-prompt workspace row. At call time, prompt + payload produces the serialized text the LLM sees:
Construction does not write to a workspace. Call
prompt.register(...) explicitly, or pass register=True when you want decorator-time registration. Scope register and load with ws=... when prompts belong to a task workspace.3. Markdown Helpers
Before you reach forhb.Prompt, you often need stable Markdown blocks: headings, lists, code fences, structured examples. HeavenBase keeps these in heavenbase.utils so generated prompt text stays deterministic across runs, reports, and tests.
Use these helpers inside function prompts when you want full control over layout. They are composable building blocks, not tied to any single task shape.
4. One-Shot Prompt Layout
For the common case — a single-turn task with system context, a few examples, and a new instance to solve — HeavenBase providesfast_prompt_section(...). It is a convenience wrapper that turns a conventional section layout into OpenAI-style messages using the Markdown helpers above.
The layout follows one principle:
system + descriptions + examples + instructions + instance
Each example carries inputs, hints, output, expected, and notes. The new instance reuses the same shape but marks its output as TODO, signaling the model what to produce.
separate_system=True when the target LLM path should receive a dedicated system message instead of one user message containing all sections.
5. Function Prompts
Decorate a Python function when the encoder logic should stay in code and persist as a Capsule-backed callable. The function body is your encoder; call arguments are the payload.*, tr=str in the signature when the prompt contains user-facing phrases. HeavenBase injects a bound translation function at call time so localized text flows through the same encoder without forking the function.
5.1. Compose Encoders
Function prompts can call other prompts, layout helpers, and LLMs in one encoder. A toy meta-prompter pattern: a one-line format-string prompt drafts the system section;fast_prompt_section(...) assembles the one-shot body from examples and the new instance.
6. Format-String Prompts
Passing a string tohb.Prompt(...) creates the simplest encoder: a compiled format string with placeholder substitution. It uses the same Capsule-backed callable path as function prompts, but the body cannot run arbitrary logic. Use it for short, stable patterns; reach for a function prompt when the encoder needs branching, composition, or meta-generation.
tr_keys when only the full string needs translation:
7. Load, List, and Version Prompts
Prompts are loaded by dotted name, compact version ref, or row id:sys-prompt row:
8. Translation as a First-Class Concern
Localization should not require maintaining parallel prompt files. HeavenBase makes translation a first-class part of the prompt surface through thetr argument and prompt.tr.
Every prompt call resolves language in this order: explicit lang=..., the prompt object’s bound lang, the current CM_HVNB config scope at heavenbase.prompt.lang, then main_lang. The bound tr function applies that language to source phrases inside the encoder:
tr=... to fast_prompt_section(...) to translate section titles and list items the same way. Function prompts receive tr automatically when the signature declares it.
Translation rows live as queryable sys-translation entities in the same workspace. Reach them through prompt.tr:
{placeholder} captures. If no translation is found, HeavenBase returns the source text for elicit="none". elicit="llm" is reserved and raises NotImplementedError in this release.
Translation is available from heavenbase.extensions.prompt for lower-level code, but the root import heavenbase as hb surface keeps translation under Prompt.tr.
9. Persist Agent Instructions
Combinefast_prompt_section(...) with hb.Prompt when agent instructions should persist with the task workspace. The function encoder wraps the one-shot layout; registration stores the callable as a versioned row.
10. CLI
create command creates format-string prompts.
Summary
- Model prompts as encoders — callable functions that map input data to LLM-facing text, not as static strings.
hb.Promptis a Capsule special case: prompt + payload produces the final serialized output, and the encoder itself is persistable.- Prefer function prompts when the encoder needs logic, composition, or meta-generation; use format-string prompts for simple substitution.
- Use Markdown helpers for stable text blocks; use
fast_prompt_section(...)for the standard one-shot layout when it fits. - Pass
trthrough encoders andfast_prompt_section(...)so localization stays in the same code path as rendering.

