Skip to main content

PruneConfig

Struct PruneConfig 

Source
pub struct PruneConfig {
    pub enabled: bool,
    pub protect_tokens: u64,
    pub minimum_tokens: u64,
    pub tool_output_max_chars: usize,
    pub protected_tools: Vec<String>,
}
Expand description

旧工具输出修剪配置。

Prune 是一种轻量级的上下文优化手段,独立于全量压缩: 把旧的、体积大的工具输出内容截断或标记为已压缩, 释放 token 空间,延迟全量压缩的触发。

§算法(来源: opencode)

  1. 从最新消息向旧遍历,跳过最近 2 个 user turn
  2. 累计 tool output tokens,超过 protect_tokens 后开始标记
  3. 仅在总修剪量超过 minimum_tokens 时才实际执行

§Examples

use katu_core::compaction::PruneConfig;

let config = PruneConfig::default();
assert!(config.enabled);
assert_eq!(config.protect_tokens, 40_000);

Fields§

§enabled: bool

是否启用修剪。

§protect_tokens: u64

保护最近的 tool output token 数不被修剪。

从最新往旧遍历,累计超过此值后才开始标记修剪。 来源: opencode PRUNE_PROTECT = 40,000。

§minimum_tokens: u64

修剪的最小触发阈值。

仅当可修剪量超过此值时才执行,避免无意义的小量修剪。 来源: opencode PRUNE_MINIMUM = 20,000。

§tool_output_max_chars: usize

修剪时工具输出截断的最大字符数。

超过此长度的工具输出在修剪时被截断。 来源: opencode TOOL_OUTPUT_MAX_CHARS = 2,000。

§protected_tools: Vec<String>

不受修剪影响的工具名称列表。

某些工具(如 skill)的输出对上下文非常重要,不应被修剪。 来源: opencode PRUNE_PROTECTED_TOOLS = [“skill”]。

Implementations§

Source§

impl PruneConfig

Source

pub fn with_enabled(self, enabled: bool) -> Self

设置修剪开关。

Source

pub fn with_protect_tokens(self, tokens: u64) -> Self

设置保护 token 数。

Source

pub fn with_minimum_tokens(self, tokens: u64) -> Self

设置最小触发阈值。

Source

pub fn with_tool_output_max_chars(self, chars: usize) -> Self

设置工具输出截断字符数。

Source

pub fn add_protected_tool(self, tool: impl Into<String>) -> Self

添加受保护的工具。

Trait Implementations§

Source§

impl Clone for PruneConfig

Source§

fn clone(&self) -> PruneConfig

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 PruneConfig

Source§

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

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

impl Default for PruneConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PruneConfig

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 PartialEq for PruneConfig

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PruneConfig

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

impl Eq for PruneConfig

Source§

impl StructuralPartialEq for PruneConfig

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> 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,