pub struct P;Expand description
The P namespace — static factory methods for prompt sections.
Implementations§
Source§impl P
impl P
Sourcepub fn role(role: &str) -> PromptSection
pub fn role(role: &str) -> PromptSection
Define the agent’s role.
Sourcepub fn task(task: &str) -> PromptSection
pub fn task(task: &str) -> PromptSection
Define the agent’s task.
Sourcepub fn constraint(c: &str) -> PromptSection
pub fn constraint(c: &str) -> PromptSection
Add a constraint.
Sourcepub fn format(f: &str) -> PromptSection
pub fn format(f: &str) -> PromptSection
Specify output format.
Sourcepub fn example(input: &str, output: &str) -> PromptSection
pub fn example(input: &str, output: &str) -> PromptSection
Add an input/output example.
Sourcepub fn text(t: &str) -> PromptSection
pub fn text(t: &str) -> PromptSection
Add free-form text.
Sourcepub fn context(ctx: &str) -> PromptSection
pub fn context(ctx: &str) -> PromptSection
Add background context.
Sourcepub fn persona(desc: &str) -> PromptSection
pub fn persona(desc: &str) -> PromptSection
Define a personality/persona.
Sourcepub fn guidelines(items: &[&str]) -> PromptSection
pub fn guidelines(items: &[&str]) -> PromptSection
Add multiple guidelines as a bulleted list.
Sourcepub fn section(name: &str, text: &str) -> PromptSection
pub fn section(name: &str, text: &str) -> PromptSection
Add a named section (flexible section kind).
Sourcepub fn template(tpl: &str) -> PromptSection
pub fn template(tpl: &str) -> PromptSection
Template with {key} placeholders — rendered with state values at runtime.
Sourcepub fn reorder(order: &[&str]) -> PromptTransform
pub fn reorder(order: &[&str]) -> PromptTransform
Reorder sections in a composite by name.
Sections whose names match the given order come first (in order); unmatched sections are appended at the end in their original order.
let prompt = (P::role("analyst") + P::task("analyze") + P::format("JSON"))
.reorder_by_name(&["format", "role", "task"]);Sourcepub fn only(names: &[&str]) -> PromptTransform
pub fn only(names: &[&str]) -> PromptTransform
Keep only sections whose names match the given list.
let prompt = (P::role("analyst") + P::task("analyze") + P::format("JSON"))
.only_by_name(&["role", "task"]);Sourcepub fn without(names: &[&str]) -> PromptTransform
pub fn without(names: &[&str]) -> PromptTransform
Remove sections whose names match the given list.
let prompt = (P::role("analyst") + P::task("analyze") + P::format("JSON"))
.without_by_name(&["format"]);Sourcepub fn compress() -> PromptSection
pub fn compress() -> PromptSection
Mark prompt for compression. This is a placeholder/marker indicating the prompt content should be compressed before sending to the model.
Sourcepub fn adapt<F>(f: F) -> PromptSection
pub fn adapt<F>(f: F) -> PromptSection
Create an adaptive prompt that adjusts based on a context function.
The function receives context (e.g., token budget, turn count) and returns the adapted prompt text.
let prompt = P::adapt(|ctx| {
if ctx.contains("detailed") {
"Provide a thorough analysis with citations.".to_string()
} else {
"Be concise.".to_string()
}
});Sourcepub fn scaffolded(steps: &[&str]) -> PromptSection
pub fn scaffolded(steps: &[&str]) -> PromptSection
Create a step-by-step scaffolded prompt from ordered steps.
let prompt = P::scaffolded(&["Identify the problem", "Gather data", "Analyze", "Conclude"]);Sourcepub fn versioned(version: &str, text: &str) -> PromptSection
pub fn versioned(version: &str, text: &str) -> PromptSection
Create a versioned prompt section with a version tag.
let prompt = P::versioned("v2.1", "Analyze the data using the new methodology");Sourcepub fn with_state(keys: &[&str]) -> InstructionModifier
pub fn with_state(keys: &[&str]) -> InstructionModifier
Create a state-append modifier that renders selected state keys into the instruction.
let modifiers = P::with_state(&["emotional_state", "willingness_to_pay"]);