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)
- 从最新消息向旧遍历,跳过最近 2 个 user turn
- 累计 tool output tokens,超过
protect_tokens后开始标记 - 仅在总修剪量超过
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
impl PruneConfig
Sourcepub fn with_enabled(self, enabled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
设置修剪开关。
Sourcepub fn with_protect_tokens(self, tokens: u64) -> Self
pub fn with_protect_tokens(self, tokens: u64) -> Self
设置保护 token 数。
Sourcepub fn with_minimum_tokens(self, tokens: u64) -> Self
pub fn with_minimum_tokens(self, tokens: u64) -> Self
设置最小触发阈值。
Sourcepub fn with_tool_output_max_chars(self, chars: usize) -> Self
pub fn with_tool_output_max_chars(self, chars: usize) -> Self
设置工具输出截断字符数。
Sourcepub fn add_protected_tool(self, tool: impl Into<String>) -> Self
pub fn add_protected_tool(self, tool: impl Into<String>) -> Self
添加受保护的工具。
Trait Implementations§
Source§impl Clone for PruneConfig
impl Clone for PruneConfig
Source§fn clone(&self) -> PruneConfig
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PruneConfig
impl Debug for PruneConfig
Source§impl Default for PruneConfig
impl Default for PruneConfig
Source§impl<'de> Deserialize<'de> for PruneConfig
impl<'de> Deserialize<'de> for PruneConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl PartialEq for PruneConfig
Source§fn eq(&self, other: &PruneConfig) -> bool
fn eq(&self, other: &PruneConfig) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for PruneConfig
impl Serialize for PruneConfig
impl Eq for PruneConfig
impl StructuralPartialEq for PruneConfig
Auto Trait Implementations§
impl Freeze for PruneConfig
impl RefUnwindSafe for PruneConfig
impl Send for PruneConfig
impl Sync for PruneConfig
impl Unpin for PruneConfig
impl UnsafeUnpin for PruneConfig
impl UnwindSafe for PruneConfig
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