修复: 子代理上下文预算恒128K不随模型窗口

子代理预算改继承父会话(同模型同窗口单一事实来源), 939-③ 收口;
939-⑪⑫ 核实已由前批落地, 看板销账更新
This commit is contained in:
lxy
2026-10-11 09:35:49 +08:00
parent 423c1df398
commit 96bab8cd49
2 changed files with 15 additions and 12 deletions
+13 -10
View File
@@ -113,16 +113,13 @@ pub(crate) const SUB_AGENT_WALL_TIMEOUT_SECS: u64 = 900;
/// 自达统一出口。
pub(crate) const SUB_AGENT_TOOL_BATCH_HEADROOM_SECS: u64 = 65;
/// 子代理上下文窗口预算上限(token)。自动压缩触发阈值与 build_for_request 裁剪预算
/// 的数据源,口径同 [`ContextConfig::max_tokens`]。默认 128_000 对齐 ContextConfig::default
/// ——接入压缩层不改动既有预算(零行为变更);值单点集中于此,后续按需分档只改本常量。
const SUB_AGENT_CONTEXT_MAX_TOKENS: u32 = 128_000;
/// 子代理会话的上下文配置(压缩/裁剪预算来源)。仅覆写 max_tokens 为子代理常量,
/// 子代理会话的上下文配置(压缩/裁剪预算来源)。max_tokens **继承父会话预算**——
/// 子代理与父同模型同窗口(939③ 收口:原恒 128K,1M 窗口模型被子代理裁半是同款缺口),
/// 父侧已按 model_context 按窗口构造,直接取单一事实来源,子侧不再自持口径。
/// 输出预留与安全系数沿用 ContextConfig::default,与主会话同一压缩链路口径一致。
fn sub_agent_context_config() -> ContextConfig {
fn sub_agent_context_config(parent_max_tokens: u32) -> ContextConfig {
ContextConfig {
max_tokens: SUB_AGENT_CONTEXT_MAX_TOKENS,
max_tokens: parent_max_tokens,
..ContextConfig::default()
}
}
@@ -755,10 +752,16 @@ async fn run_sub_agent_loop_inner(
// 先于 conv() 调用(insert 需可变借 session,避免与 conv 借用冲突)
session.deleted_convs.insert(child_conv_id.clone());
session.conv_origins.insert(child_conv_id.clone(), SUB_AGENT_ORIGIN.to_string());
// 父预算先取(可变借用 conv 之前):子代理与父同模型,窗口预算单一事实来源在父侧
let parent_max_tokens = session
.conv(&parent_conv_id)
.messages
.config()
.max_tokens;
let conv = session.conv(&child_conv_id);
// 上下文预算单点接入:子会话 ContextManager 用子代理配置(默认值与父会话一致),
// 上下文预算单点接入:子会话 ContextManager 继承父预算(939③ 子代理半边),
// 供压缩触发阈值与 build_for_request 裁剪读取;新条目消息为空,直接替换无损。
conv.messages = ContextManager::new(sub_agent_context_config());
conv.messages = ContextManager::new(sub_agent_context_config(parent_max_tokens));
conv.messages.push(ChatMessage::user(&task_prompt));
conv.stop_flag.store(false, Ordering::SeqCst);
conv.iteration_used = 0;