P

Struct P 

Source
pub struct P;
Expand description

The P namespace — static factory methods for prompt sections.

Implementations§

Source§

impl P

Source

pub fn role(role: &str) -> PromptSection

Define the agent’s role.

Source

pub fn task(task: &str) -> PromptSection

Define the agent’s task.

Source

pub fn constraint(c: &str) -> PromptSection

Add a constraint.

Source

pub fn format(f: &str) -> PromptSection

Specify output format.

Source

pub fn example(input: &str, output: &str) -> PromptSection

Add an input/output example.

Source

pub fn text(t: &str) -> PromptSection

Add free-form text.

Source

pub fn context(ctx: &str) -> PromptSection

Add background context.

Source

pub fn persona(desc: &str) -> PromptSection

Define a personality/persona.

Source

pub fn guidelines(items: &[&str]) -> PromptSection

Add multiple guidelines as a bulleted list.

Source

pub fn section(name: &str, text: &str) -> PromptSection

Add a named section (flexible section kind).

Source

pub fn template(tpl: &str) -> PromptSection

Template with {key} placeholders — rendered with state values at runtime.

Source

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"]);
Source

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"]);
Source

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"]);
Source

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.

Source

pub fn adapt<F>(f: F) -> PromptSection
where F: Fn(&str) -> String + Send + Sync + 'static,

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()
    }
});
Source

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"]);
Source

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");
Source

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"]);
Source

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.");
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more