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 last(n: usize) -> ContextPolicy

Keep messages within a time window (by index offset from end). Alias for window — provided for API symmetry.

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
C::from_state(&["user:name", "app:account_balance", "derived:risk"])
// Produces: "[Context: name=John, account_balance=$5230, risk=0.72]"
Source

pub fn none() -> ContextPolicy

Alias for empty — matches upstream Python C.none().

Source

pub fn recent(n: usize) -> ContextPolicy

Alias for window — matches upstream Python C.recent().

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 rolling(n: usize) -> ContextPolicy

Rolling window — keeps last N messages (alias with summarization hint).

Source

pub fn compact() -> ContextPolicy

Compact context — removes tool call/response parts to reduce token usage.

Source

pub fn budget(max_tokens: usize) -> ContextPolicy

Budget context — truncate to approximate token count.

Rough estimate: 4 chars per token.

Source

pub fn fresh(max_entries: usize) -> ContextPolicy

Freshness filter — keep only messages within the last N entries.

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
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
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
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
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
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 budget but adds a truncation marker so the runtime knows content was trimmed, allowing the agent to request more context if needed.

§Example
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
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
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
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
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
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<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