C

Struct C 

Source
pub struct C;
Expand description

The C namespace — static factory methods for context policies.

Implementations§

Source§

impl C

Source

pub fn window(n: usize) -> ContextPolicy

Keep only the last n messages.

Source

pub fn user_only() -> ContextPolicy

Keep only messages with role “user”.

Source

pub fn custom( f: impl Fn(&[Content]) -> Vec<Content> + Send + Sync + 'static, ) -> ContextPolicy

Apply a custom filter function.

Source

pub fn model_only() -> ContextPolicy

Keep only messages with role “model”.

Source

pub fn head(n: usize) -> ContextPolicy

Keep the first n messages (head).

Source

pub fn sample(n: usize) -> ContextPolicy

Keep every n-th message (sampling).

Source

pub fn exclude_tools() -> ContextPolicy

Exclude messages that contain tool-related parts (function calls/responses).

Source

pub fn prepend(content: Content) -> ContextPolicy

Prepend a system message to the context.

Source

pub fn append(content: Content) -> ContextPolicy

Append a content to the context.

Source

pub fn text_only() -> ContextPolicy

Keep only messages that contain text parts.

Source

pub fn filter( f: impl Fn(&Content) -> bool + Send + Sync + 'static, ) -> ContextPolicy

Filter messages by a predicate on Content.

Source

pub fn map( f: impl Fn(&Content) -> Content + Send + Sync + 'static, ) -> ContextPolicy

Map/transform each message in the context.

Source

pub fn truncate(max_chars: usize) -> ContextPolicy

Truncate context to approximately max_chars total characters of text.

Source

pub fn empty() -> ContextPolicy

Return an empty context (useful for isolated agents).

Source

pub fn from_state(keys: &[&str]) -> ContextPolicy

Inject state values as context preamble.

Bridges Channel 2 (State) → Channel 1 (Conversation History) by prepending formatted state values as a system context message.

§Example
let policy = C::from_state(&["user:name", "app:account_balance", "derived:risk"]);
// Produces: "[Context: name=John, account_balance=$5230, risk=0.72]"
Source

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

Template-based context injection with {key} placeholders.

Replaces placeholders in the template with state key references.

Source

pub fn when( predicate: impl Fn() -> bool + Send + Sync + 'static, inner: ContextPolicy, ) -> ContextPolicy

Conditional context — applies inner policy only when predicate is true.

Falls back to passing history through unchanged.

Source

pub fn redact(patterns: &[&str]) -> ContextPolicy

Redact patterns from context messages.

Source

pub fn summarize(prompt: &str) -> ContextPolicy

LLM-powered context summarization.

Stores a summarization prompt that the runtime uses to condense context via an LLM call before passing it to the agent. The policy prepends a marker so the runtime knows summarization is requested.

§Example
let policy = C::summarize("Summarize the conversation focusing on action items");
Source

pub fn relevant(query_key: &str) -> ContextPolicy

Keep only context relevant to a state key.

Marker policy for LLM-powered relevance filtering. The runtime uses the referenced state key’s value to filter context entries by relevance.

§Example
let policy = C::relevant("user:current_topic");
Source

pub fn extract(keys: &[&str]) -> ContextPolicy

Extract specific information from context.

Marker policy that signals the runtime to extract only the named pieces of information from the conversation history via an LLM call.

§Example
let policy = C::extract(&["customer_name", "order_id", "complaint"]);
Source

pub fn distill(instruction: &str) -> ContextPolicy

Distill context to essential information.

Marker policy for LLM-powered distillation. Similar to summarize but focused on extracting only the essential facts per the given instruction.

§Example
let policy = C::distill("Keep only decisions made and their rationale");
Source

pub fn priority(weights: &[(&str, f64)]) -> ContextPolicy

Priority-weighted context selection.

Assigns weights to context entries by role or content pattern. Higher weight entries are kept preferentially when context must be truncated. Weights are encoded as a marker for runtime processing.

§Example
let policy = C::priority(&[("user", 1.0), ("model", 0.5), ("tool", 0.2)]);
Source

pub fn fit(max_tokens: usize) -> ContextPolicy

Fit context to a token budget with smart truncation.

Similar to truncate (a character budget, ~4 chars per token) but adds a truncation marker so the runtime knows content was trimmed, allowing the agent to request more context if needed.

§Example
let policy = C::fit(4096);
Source

pub fn project(fields: &[&str]) -> ContextPolicy

Project/keep only specific fields from context.

Marker policy that signals the runtime to retain only the named fields from structured content in the conversation history.

§Example
let policy = C::project(&["name", "status", "priority"]);
Source

pub fn select( predicate: impl Fn(&Content) -> bool + Send + Sync + 'static, ) -> ContextPolicy

Select context entries matching a predicate.

Similar to filter but with select semantics: entries matching the predicate are included (positive selection).

Source

pub fn from_agents(names: &[&str]) -> ContextPolicy

Include context only from specific agents.

Filters context to keep only messages attributed to the named agents. Agent attribution is detected via [Agent: name] markers in content.

§Example
let policy = C::from_agents(&["researcher", "analyst"]);
Source

pub fn exclude_agents(names: &[&str]) -> ContextPolicy

Exclude context from specific agents.

Filters out messages attributed to the named agents. Agent attribution is detected via [Agent: name] markers in content.

§Example
let policy = C::exclude_agents(&["logger", "debugger"]);
Source

pub fn notes(key: &str) -> ContextPolicy

Scratchpad: read notes from a state key as context.

Prepends the value of a state key as a notes/scratchpad section in the context. Useful for maintaining running notes across turns.

§Example
let policy = C::notes("session:scratchpad");
Source

pub fn pipeline_aware() -> ContextPolicy

Pipeline-aware context that adapts based on pipeline position.

Marker policy that signals the runtime to adjust context based on where the current agent sits in a pipeline. Early stages receive full context; later stages receive only the outputs of preceding stages.

§Example
let policy = C::pipeline_aware();
Source

pub fn dedup() -> ContextPolicy

Deduplicate adjacent messages with identical text content.

Auto Trait Implementations§

§

impl Freeze for C

§

impl RefUnwindSafe for C

§

impl Send for C

§

impl Sync for C

§

impl Unpin for C

§

impl UnwindSafe for C

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<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,