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