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
Add a compression marker to a prompt. When present in a composite, the
whole rendered prompt is run through compress_text — trimming lines,
collapsing whitespace, and dropping blank/duplicate lines — to reduce
tokens deterministically (no LLM call) before it reaches 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 show_state(keys: &[&str]) -> InstructionModifier
pub fn show_state(keys: &[&str]) -> InstructionModifier
Create a modifier that shows the selected state keys to the model by rendering them into the instruction.
let modifier = P::show_state(&["emotional_state", "willingness_to_pay"]);Sourcepub fn when(
predicate: impl Fn(&State) -> bool + Send + Sync + 'static,
text: impl Into<String>,
) -> InstructionModifier
pub fn when( predicate: impl Fn(&State) -> bool + Send + Sync + 'static, text: impl Into<String>, ) -> InstructionModifier
Create a conditional modifier that appends text when the predicate is true.
let risk_mod = P::when(risk_is_elevated, "IMPORTANT: Show extra empathy.");Sourcepub fn context_fn(
f: impl Fn(&State) -> String + Send + Sync + 'static,
) -> InstructionModifier
pub fn context_fn( f: impl Fn(&State) -> String + Send + Sync + 'static, ) -> InstructionModifier
Create a custom-append modifier from a formatting function.
let ctx = P::context_fn(|s| format!("Customer: {}", s.get::<String>("name").unwrap_or_default()));Auto Trait Implementations§
impl Freeze for P
impl RefUnwindSafe for P
impl Send for P
impl Sync for P
impl Unpin for P
impl UnwindSafe for P
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].