pub struct C;Expand description
The C namespace — static factory methods for context policies.
Implementations§
Source§impl C
impl C
Sourcepub fn window(n: usize) -> ContextPolicy
pub fn window(n: usize) -> ContextPolicy
Keep only the last n messages.
Sourcepub fn user_only() -> ContextPolicy
pub fn user_only() -> ContextPolicy
Keep only messages with role “user”.
Sourcepub fn custom(
f: impl Fn(&[Content]) -> Vec<Content> + Send + Sync + 'static,
) -> ContextPolicy
pub fn custom( f: impl Fn(&[Content]) -> Vec<Content> + Send + Sync + 'static, ) -> ContextPolicy
Apply a custom filter function.
Sourcepub fn model_only() -> ContextPolicy
pub fn model_only() -> ContextPolicy
Keep only messages with role “model”.
Sourcepub fn head(n: usize) -> ContextPolicy
pub fn head(n: usize) -> ContextPolicy
Keep the first n messages (head).
Sourcepub fn sample(n: usize) -> ContextPolicy
pub fn sample(n: usize) -> ContextPolicy
Keep every n-th message (sampling).
Sourcepub fn exclude_tools() -> ContextPolicy
pub fn exclude_tools() -> ContextPolicy
Exclude messages that contain tool-related parts (function calls/responses).
Sourcepub fn prepend(content: Content) -> ContextPolicy
pub fn prepend(content: Content) -> ContextPolicy
Prepend a system message to the context.
Sourcepub fn append(content: Content) -> ContextPolicy
pub fn append(content: Content) -> ContextPolicy
Append a content to the context.
Sourcepub fn text_only() -> ContextPolicy
pub fn text_only() -> ContextPolicy
Keep only messages that contain text parts.
Sourcepub fn filter(
f: impl Fn(&Content) -> bool + Send + Sync + 'static,
) -> ContextPolicy
pub fn filter( f: impl Fn(&Content) -> bool + Send + Sync + 'static, ) -> ContextPolicy
Filter messages by a predicate on Content.
Sourcepub fn map(
f: impl Fn(&Content) -> Content + Send + Sync + 'static,
) -> ContextPolicy
pub fn map( f: impl Fn(&Content) -> Content + Send + Sync + 'static, ) -> ContextPolicy
Map/transform each message in the context.
Sourcepub fn truncate(max_chars: usize) -> ContextPolicy
pub fn truncate(max_chars: usize) -> ContextPolicy
Truncate context to approximately max_chars total characters of text.
Sourcepub fn empty() -> ContextPolicy
pub fn empty() -> ContextPolicy
Return an empty context (useful for isolated agents).
Sourcepub fn from_state(keys: &[&str]) -> ContextPolicy
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]"Sourcepub fn template(tpl: &str) -> ContextPolicy
pub fn template(tpl: &str) -> ContextPolicy
Template-based context injection with {key} placeholders.
Replaces placeholders in the template with state key references.
Sourcepub fn when(
predicate: impl Fn() -> bool + Send + Sync + 'static,
inner: ContextPolicy,
) -> ContextPolicy
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.
Sourcepub fn redact(patterns: &[&str]) -> ContextPolicy
pub fn redact(patterns: &[&str]) -> ContextPolicy
Redact patterns from context messages.
Sourcepub fn summarize(prompt: &str) -> ContextPolicy
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");Sourcepub fn relevant(query_key: &str) -> ContextPolicy
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");Sourcepub fn extract(keys: &[&str]) -> ContextPolicy
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"]);Sourcepub fn distill(instruction: &str) -> ContextPolicy
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");Sourcepub fn priority(weights: &[(&str, f64)]) -> ContextPolicy
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)]);Sourcepub fn fit(max_tokens: usize) -> ContextPolicy
pub fn fit(max_tokens: usize) -> ContextPolicy
Sourcepub fn project(fields: &[&str]) -> ContextPolicy
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"]);Sourcepub fn select(
predicate: impl Fn(&Content) -> bool + Send + Sync + 'static,
) -> ContextPolicy
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).
Sourcepub fn from_agents(names: &[&str]) -> ContextPolicy
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"]);Sourcepub fn exclude_agents(names: &[&str]) -> ContextPolicy
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"]);Sourcepub fn notes(key: &str) -> ContextPolicy
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");Sourcepub fn pipeline_aware() -> ContextPolicy
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();Sourcepub fn dedup() -> ContextPolicy
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> 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].