Skip to main content

RegionKind

Enum RegionKind 

Source
pub enum RegionKind {
    Pinned,
    SlidingWindow {
        max_items: usize,
        eviction_strategy: EvictionStrategy,
    },
    Temporary,
    Compacting {
        threshold_tokens: usize,
    },
    Clearable,
    CompactHistory {
        source_region: String,
    },
    HashMap {
        max_entries: Option<usize>,
    },
    Custom {
        script: String,
        persistent: bool,
    },
}
Expand description

A typed memory region within an agent’s context window.

Regions have different lifecycle policies controlling how they behave when the context window fills up. This is inspired by hardware memory architectures like SNES VRAM, where different memory regions serve distinct purposes with their own access patterns and constraints.

Variants§

§

Pinned

Never evicted or compacted. Architecture diagrams, constraints, identity.

Like SNES OAM (Object Attribute Memory) - fixed format, always present. Use for content that defines the agent’s core identity, constraints, and architectural understanding. This content persists for the entire agent lifecycle.

§

SlidingWindow

Maintains the last N items, oldest rolls off. Conversation history.

Like a ring buffer with configurable size. When the buffer is full, the oldest item is removed to make room for new content. Use for conversation history or any sequential data where recent items are most relevant.

Fields

§max_items: usize

Maximum number of items to retain in the window

§eviction_strategy: EvictionStrategy

Strategy used to evict entries when the window is full

§

Temporary

First to be evicted when space is needed. Tool outputs, intermediate results.

Cheapest to regenerate, lowest priority to keep. Use for content that can be easily regenerated or has low value after immediate use, such as tool execution results or temporary computations.

§

Compacting

Compacts (summarizes) when threshold is hit, then cleared.

When token count exceeds the threshold, the region’s content is summarized and moved to a paired CompactHistory region, then the original Compacting region is completely cleared, giving fresh capacity.

Fields

§threshold_tokens: usize

Token count that triggers compaction

§

Clearable

Wiped entirely in one shot when space is needed. All-or-nothing eviction.

Unlike Temporary (which evicts oldest entries one at a time), Clearable regions are dumped completely and immediately when eviction is needed. Use for scratch space or temporary working data where partial results are useless.

§

CompactHistory

Receives summaries from paired Compacting regions, never evicted.

When a Compacting region hits its threshold and summarizes, the summary moves here. CompactHistory regions hold compressed knowledge indefinitely and are never evicted. Can also support sliding window behavior (oldest summaries drop off) and re-compaction (combine multiple summaries).

Fields

§source_region: String

Name of the source Compacting region

§

HashMap

Key-value region where entries are indexed by string key. Writing with an existing key replaces that entry (upsert semantics). When over token budget, evicts least-recently-updated entries (LRU).

Fields

§max_entries: Option<usize>

Optional maximum number of keys

§

Custom

Script-backed region: a user-authored Rhai script owns how the region renders into the assembled context (render), may transform or reject each incoming entry (on_write), and may choose what to drop under budget pressure (on_overflow).

script is the blueprint-dir-relative path to the .rhai file; path resolution and compilation happen in the CLI spawner (this crate stays filesystem-free), and the compiled script travels on the runtime’s context window keyed by this path. persistent regions behave like Pinned for lifecycle - never evicted, immune to edge Clear transforms, counted as fixed budget - while non-persistent regions behave like Temporary.

Note: this kind is orthogonal to RegionSchema’s (unwired) custom_script field, which is a content-validation concept.

Fields

§script: String

Blueprint-dir-relative path to the Rhai script backing this region

§persistent: bool

Lifecycle: true = Pinned-like (protected, fixed budget), false = Temporary-like (stage-specific, evictable)

Implementations§

Source§

impl RegionKind

Source

pub fn cache_hint(&self) -> CacheHint

Return the cache hint appropriate for this region kind.

Trait Implementations§

Source§

impl Clone for RegionKind

Source§

fn clone(&self) -> RegionKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RegionKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RegionKind

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for RegionKind

Source§

impl PartialEq for RegionKind

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for RegionKind

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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