prompt
prompt
¶
PromptRenderer — full prompt rendering for baton musicians.
Bridges the PromptBuilder pipeline with the baton's Sheet-based execution
model. Replaces the bare-bones _build_prompt() in musician.py with
the full 9-layer prompt assembly:
1. Preamble (positional identity)
2. Template rendering (Jinja2 with all variables)
3. Skills/tools injection (prelude/cadenza with category=skill/tool)
4. Context injection (prelude/cadenza with category=context)
5. Spec fragments (from specification corpus)
6. Failure history (from previous sheets)
7. Learned patterns (from learning store)
8. Validation requirements (as agent-readable checklist)
9. Completion suffix (for completion mode retries)
The renderer is intentionally stateless — create one per job, call
render() per sheet. No runner dependency, no mixin inheritance.
This is the F-104 fix. Without it, the baton produces raw templates instead of rendered prompts.
See: docs/plans/2026-03-26-baton-design.md — Prompt Assembly
Classes¶
RenderedPrompt
dataclass
¶
Output of the prompt rendering pipeline.
Contains both the rendered prompt (for backend execution) and the preamble (set on the backend before execution). Separating them allows the musician to configure the backend correctly.
Attributes¶
prompt_extensions
class-attribute
instance-attribute
¶
Request-local additional directives appended by the backend.
context_manifest
class-attribute
instance-attribute
¶
Hash-only manifest of context and technique bytes in prompt.
prompt_receipt
class-attribute
instance-attribute
¶
Per-source sizes, hashes and drop reasons for this prompt (GH #546).
PromptRenderer
¶
PromptRenderer(prompt_config, total_sheets, total_stages, parallel_enabled, *, job_id=None, schedule_id=None, scheduled_due_at=None)
Renders full prompts for baton musicians.
Bridges the PromptBuilder pipeline with the baton's Sheet-based execution model. Handles template rendering, injection resolution, preamble assembly, and validation requirements — everything the old runner's context mixin did, but without the runner dependency.
Create one per job (or share across jobs with the same config).
Call render() per sheet dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_config
|
PromptConfig
|
The job's PromptConfig (template, variables, etc.). |
required |
total_sheets
|
int
|
Total sheets in the job (for preamble). |
required |
total_stages
|
int
|
Total stages before fan-out expansion (for template aliases). |
required |
parallel_enabled
|
bool
|
Whether parallel execution is enabled (for preamble). |
required |
Source code in src/marianne/daemon/baton/prompt.py
Methods:¶
render
¶
render(sheet, attempt_context, *, patterns=None, failure_history=None, spec_fragments=None, technique_manifest=None, technique_skill_docs=None, raw_prompt=False, memory_manifest=None)
Render a full prompt for a sheet execution.
Performs the complete 9-layer prompt assembly: template rendering -> injection resolution -> optional layers -> validation requirements -> completion suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Sheet
|
The Sheet entity to render for. |
required |
attempt_context
|
AttemptContext
|
Context from the baton (attempt number, mode). |
required |
patterns
|
list[str] | None
|
Optional learned pattern descriptions to inject. |
None
|
failure_history
|
list[HistoricalFailure] | None
|
Optional historical failures from previous sheets. |
None
|
spec_fragments
|
list[SpecFragment] | None
|
Optional spec corpus fragments to inject. |
None
|
technique_manifest
|
str | None
|
Optional technique manifest text to inject as a skill-category item. Generated by the technique resolver from the job's technique declarations filtered by phase. |
None
|
technique_skill_docs
|
Mapping[str, str] | Sequence[str] | None
|
Optional list of technique document contents discovered by the technique resolver. Each entry is the full text of a skill-kind technique document, injected as a skill-category item alongside the manifest. |
None
|
memory_manifest
|
str | None
|
The memory block for this sheet. Its own channel, never
part of the technique manifest, so a template that already lists
techniques cannot suppress it. Injected once, as |
None
|
raw_prompt
|
bool
|
When True (driven by the instrument profile's
|
False
|
Returns:
| Type | Description |
|---|---|
RenderedPrompt
|
RenderedPrompt with fully rendered prompt and preamble. |
Source code in src/marianne/daemon/baton/prompt.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
Functions:¶
injection_over_max_bytes
¶
Enforce max_bytes on what an injection item would inject (GH #474).
A required item over its cap fails the sheet before execution with the measured size; an optional one is dropped with a warning. Either way the prompt is never silently shipped over-sized — the conductor's token warning fires only after assembly and names no item.
Source code in src/marianne/daemon/baton/prompt.py
write_context_delivery_receipt
¶
write_context_delivery_receipt(*, workspace, job_id, sheet_num, attempt, instrument, rendered, instrument_class=None, class_snapshot_sha256=None)
Persist proof of the exact prompt context passed to sheet_task.
Source code in src/marianne/daemon/baton/prompt.py
resolve_injection_path
¶
Resolve one rendered injection path with portable HOME semantics.