新增: 上下文管理演进 Wave1(契约定义 + T1动态阈值 + T2命名空间)
Agent 3: 共享契约类型定义 - CompressedSummary(T3输出格式) - WorkflowContextBlock(T4工作流DAG上下文) - WorkingContext + GoalItem/DecisionItem/StepInfo(T5常驻上下文) - 脏标记版本追踪 + reset_all 压缩联动 T1: 动态压缩阈值 - maybe_auto_compress 加 sys_tokens 参数,触发条件从 budget*0.6 改为 available*0.6 - 调用处传 sys_tokens(loop顶部已缓存) - 3 行核心改动 T2: 工具命名空间存储 - crates/df-ai/src/namespace_store.rs: 完整实现 + 单元测试 - process_tool_calls: Low/Med/High 路径 namespace 路由 - save_conversation: namespace 引用展开为原文再落 DB - AiSession 新增 namespace_store 字段
This commit is contained in:
@@ -69,6 +69,7 @@ pub(super) async fn maybe_auto_compress(
|
||||
provider_config: &AiProviderRecord,
|
||||
llm_concurrency: &LlmConcurrency,
|
||||
iteration: usize,
|
||||
sys_tokens: u32,
|
||||
) -> bool {
|
||||
let prev_compressing = session_arc.lock().await.conv_read(&conv_id).map(|c| c.messages.is_compressing()).unwrap_or(false);
|
||||
if !prev_compressing {
|
||||
@@ -85,10 +86,10 @@ pub(super) async fn maybe_auto_compress(
|
||||
let mgr = &mgr.messages;
|
||||
let protect_start = mgr.len().saturating_sub(PROTECT_COUNT);
|
||||
let history_tokens = mgr.history_tokens();
|
||||
let budget = mgr.budget_limit();
|
||||
// 触发阈值 0.6*budget(整数比避免浮点):budget*6/10 < history_tokens
|
||||
let available = mgr.budget_limit().saturating_sub(sys_tokens);
|
||||
// 触发阈值 0.6*available(可用预算=budget-sys_tokens):available*6/10 < history_tokens
|
||||
let should = protect_start > 0
|
||||
&& (budget as u64) * 6 / 10 < history_tokens as u64
|
||||
&& (available as u64) * 6 / 10 < history_tokens as u64
|
||||
&& mgr.has_compressible_messages(protect_start);
|
||||
(should, protect_start, history_tokens)
|
||||
};
|
||||
|
||||
@@ -1122,6 +1122,7 @@ pub(crate) async fn run_agentic_loop(
|
||||
&provider_config,
|
||||
&llm_concurrency,
|
||||
iteration,
|
||||
sys_tokens,
|
||||
).await {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user