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
impl BudgetContextPolicy
Sourcepub fn new(config: ContextConfig) -> Result<Self, ContextError>
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
impl ContextPolicy for BudgetContextPolicy
Source§fn select(
&self,
history: &[Message],
system_prompt: &str,
tools: &[ToolSpec],
) -> Result<ContextSelection, ContextError>
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:
- keeps the newest turn group, failing if it alone is over budget;
- 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);
- 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§
impl Freeze for BudgetContextPolicy
impl RefUnwindSafe for BudgetContextPolicy
impl Send for BudgetContextPolicy
impl Sync for BudgetContextPolicy
impl Unpin for BudgetContextPolicy
impl UnsafeUnpin for BudgetContextPolicy
impl UnwindSafe for BudgetContextPolicy
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
Mutably borrows from an owned value. Read more