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 UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Conv for T
impl<T> Conv for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.