base/interface/prompt_assembler.rs
1//! `PromptAssembler` — the algorithm that turns every contribution into the
2//! blocks one request carries.
3//!
4//! Contributing a block and rewriting one are already open: a registration
5//! adds, an `AssemblyHook` gets a last pass over the result. What was not open
6//! is the assembly itself — the order stages are placed in, how a
7//! contribution's order merges with the kernel's, where the cache boundaries
8//! fall, whether two blocks stay two blocks. Those are decisions
9//! [`assemble_prompt_with`](crate::prompt::assemble_prompt_with) makes, and a
10//! deployment that wants different ones had to make them by bolting a hook on
11//! the end and undoing the arrangement it had just been handed.
12//!
13//! # The inputs are a value
14//!
15//! Assembly reads ten things. Passing them as a struct is not a style
16//! preference: an implementation that wants only two should not have to
17//! restate the other eight, and a new input should not break every
18//! implementation that never asked for one.
19
20use crate::interface::prompt_registry::PromptRegistry;
21use crate::interface::scene::{ScenePromptContext, SceneSpec};
22use crate::prompt::PromptBlock;
23
24/// Everything one assembly reads.
25pub struct AssemblyRequest<'a> {
26 /// What else asked to be in this prompt.
27 pub registry: &'a dyn PromptRegistry,
28 pub scene: &'a SceneSpec,
29 /// `settings.prompt.override`: when set, it is the whole prompt.
30 pub prompt_override: Option<&'a str>,
31 /// The blocks of `settings.prompt.append`.
32 pub prompt_append: &'a [PromptBlock],
33 /// The blocks of the managed layer's `prompt.append`: appended under
34 /// `prompt_override` too, which no lower layer can take away.
35 pub managed_append: &'a [PromptBlock],
36 /// The memory section, already rendered; `None` when memory is off.
37 pub memory_prompt: Option<&'a str>,
38 pub ctx: &'a ScenePromptContext<'a>,
39 /// The rule documents the model is told exist, already merged.
40 pub rules: &'a [crate::rules::RuleEntry],
41 /// The skills inventory, already rendered.
42 pub skills_text: Option<&'a str>,
43 /// Usage guidance from the connected MCP servers, already rendered.
44 pub mcp_instructions: Option<&'a str>,
45}
46
47/// How a request's system prompt gets built.
48pub trait PromptAssembler: Send + Sync {
49 fn assemble(&self, request: &AssemblyRequest<'_>) -> Vec<PromptBlock>;
50}