Skip to main content

BudgetContextPolicy

Struct BudgetContextPolicy 

Source
pub struct BudgetContextPolicy { /* private fields */ }
Expand description

Keeps the newest whole turns that fit ContextConfig’s budget and replaces older history with one bounded summary note.

A turn group is a user message and everything after it up to the next user message, so an assistant tool call is never separated from its result.

Implementations§

Source§

impl BudgetContextPolicy

Source

pub fn new(config: ContextConfig) -> Result<Self, ContextError>

A policy for config, which must leave room for history.

Trait Implementations§

Source§

impl ContextPolicy for BudgetContextPolicy

Source§

fn select( &self, history: &[Message], system_prompt: &str, tools: &[ToolSpec], ) -> Result<ContextSelection, ContextError>

The budget for history is the window minus the system prompt, the tool schemas, the output reserve, and the safety margin. Selection then:

  1. keeps the newest turn group, failing if it alone is over budget;
  2. walks older groups from newest to oldest, keeping each while it fits, and stops at the first that does not (so the kept history is always one contiguous suffix);
  3. if anything was left out, puts one summary note of the left-out prefix in front. When the note does not fit beside the kept groups, the oldest kept group joins the summarized prefix and the note is rebuilt; with only the newest group left, the note is cut to the room that remains.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.