promptlibretto¶
promptlibretto is a prompt registry library. It assembles prompts from named sections, runtime state, and an explicit assembly_order.
Minimal Example¶
from promptlibretto import Engine, MockProvider, Registry
reg = Registry.from_dict({
"registry": {
"version": 2,
"assembly_order": ["output_prompt_directions", "personas.context"],
"output_prompt_directions": {
"required": True,
"items": [{"id": "rules", "text": "Be brief."}],
},
"personas": {
"required": True,
"items": [{"id": "direct", "context": "Be direct."}],
},
}
})
eng = Engine(reg, provider=MockProvider())
print(eng.hydrate({"personas": {"selected": "direct"}}))
Current Public Model¶
Registry,Section,RouteRegistryState,SectionStateContextItem,Persona,Sentiment,GroupStaticInjection,RuntimeInjectionOutputDirection,PromptEndingDisplay,Fragment,Scale
Use these model names when authoring registries in Python.
State Shape¶
State is keyed by section:
{
"base_context": {
"selected": "scene",
"template_vars": {"place": "the kitchen"}
},
"personas": {
"selected": "direct"
},
"sentiment": {
"selected": "warm",
"slider": 7,
"array_modes": {"groups[warm_examples]": "random:1"}
}
}
Assembly Tokens¶
sectionsection.fieldsection.scalesection.groupssection.groups[group_id]groups[group_id]injections
Adjacent blocks from the same section join with one newline. Different sections join with two newlines. Adjacent list blocks can merge when they share a pre_context.
Dynamic Items¶
Dynamic items may carry:
template_varstemplate_defaultsfragments
Fragments use condition to render only when a section template variable has a value.
Groups¶
Groups are reusable lists of prompt snippets. Attach them to items with groups: ["group_id"], then render with section.groups or section.groups[group_id].
Providers¶
Use Engine.hydrate() for prompt-only rendering, Engine.run() for provider generation, and Engine.stream() for streaming providers.
Built-ins:
MockProviderOllamaProvider