坏信封在工具计划直出那一发就拦下,重取回路终于进得去
上一版重取回路装在 final-reply 请求路径上,而策划子 Agent 的澄清信封根本 不走那条路:main_loop.rs 里 stream=false 且 plan.response 非空时直接 `final_reply = Some(response)`,随后 `if let Some(reply) = final_reply` 整块跳过 else 分支——重取回路就在那个 else 里面。所以它是死代码。 证据在 response-streams:27 个历史 run 的 68 条信封全部落在 final-reply-loop-N 记录上且 finishReason 一律为 null(短路路径没有 provider 响应对象,标记无从填),而真正发过 final-reply 请求的那几条写着 "completed"。 7 条坏信封无一例外走的是短路。之前那个 mock harness 怎么调都不触发, 原因就是这个,不是 Ready(None) 的 outcome 分支。 改法:短路处不再无条件认领最终回复。策划子 Agent 且信封解析失败时,把解析 原因作为 observation 回灌,不设 final_reply,让流程落回真正的 final-reply 请求——重取回路在那边生效,总计 1 发初始 + 2 次重取,与原型 MAX_WASTED_TURNS=3 同口径。 两个注入点合用同一条整改正文(提取成 plan_envelope_repair_observation), 只有阶段名不同,否则模型会把它读成两种不同的失败。converged 仍为 true: 这一轮确实收束了,只是不认这条信封当交付。 作用域由 game_creator_agent_runtime_plan_envelope_parse_error 把住——非策划 Agent 一律返回 None,做游戏与做素材逐字保持既有行为。 plan_envelope_repair_tests 6/6(含一条现场退化尾巴不再烧重取额度)。 回归对照:tests::provider 143/143;tests::collaboration 与 tests::runtime_actions 改动前后失败集合逐条相同(4 条 / 1 条本机基线)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,27 @@ fn game_creator_agent_runtime_plan_envelope_parse_error(
|
||||
parse_static_delegate_user_input_request(Some(reply)).err()
|
||||
}
|
||||
|
||||
/// 坏信封回灌给下一次请求的 observation。
|
||||
///
|
||||
/// attempt 0 是工具计划直出那一发被拒(stream=false 时 plan.response 充当最终回复,
|
||||
/// 它不经过重取回路),1..=N 是最终回复请求上的第几次重取。两处必须用同一条正文,
|
||||
/// 否则模型会以为是两种不同的失败。
|
||||
fn plan_envelope_repair_observation(parse_error: &str, attempt: u32) -> AgentRuntimeToolObservation {
|
||||
let stage = if attempt == 0 {
|
||||
"工具计划直出,改由最终回复重出".to_string()
|
||||
} else {
|
||||
format!("第 {attempt}/{AGENT_RUNTIME_PLAN_ENVELOPE_REPAIR_ATTEMPTS} 次重取")
|
||||
};
|
||||
AgentRuntimeToolObservation {
|
||||
tool: "runtime.plan_envelope".to_string(),
|
||||
status: "failed".to_string(),
|
||||
summary: format!("AGC_NEEDS_USER_INPUT_V1 信封无法解析({stage}):{parse_error}"),
|
||||
detail: Some(
|
||||
"原样重出同一个问题,不要改写题面或选项;信封必须是首行 AGC_NEEDS_USER_INPUT_V1,下一行严格 JSON 且完整闭合到最外层。不要输出 markdown、代码围栏或第三行正文。".to_string(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
struct PlanGddBlockerRuntimeProjection {
|
||||
phase: &'static str,
|
||||
current_action: &'static str,
|
||||
@@ -2637,8 +2658,27 @@ async fn run_game_creator_agent_background_task_pass_without_deadline(
|
||||
"Agent 工具计划最终回复去除 thinking 后为空",
|
||||
);
|
||||
}
|
||||
final_reply = Some(response);
|
||||
final_reply_revision = Some(planning_request_revision.revision);
|
||||
// 策划子 Agent 的澄清信封实际产在**工具计划那一发**:stream=false 时
|
||||
// plan.response 直接充当最终回复,下面那条 final-reply 请求根本不发,
|
||||
// 于是它后面的信封重取回路一次都进不去。现场 68 条信封全部落在这条
|
||||
// 短路上(response-streams 里 finishReason 一律为 null 就是它的签名),
|
||||
// 7 条坏信封也全在这里逃逸成 needs-repair 委派。
|
||||
//
|
||||
// 坏信封在这里不认最终回复,把解析原因作为 observation 回灌,让流程
|
||||
// 落回真正的 final-reply 请求——重取回路在那边才生效。
|
||||
match game_creator_agent_runtime_plan_envelope_parse_error(&agent_id, &response)
|
||||
{
|
||||
Some(parse_error) => {
|
||||
let observation = plan_envelope_repair_observation(&parse_error, 0);
|
||||
runtime.observations.push(observation.summary());
|
||||
context_tracker.record(&observation);
|
||||
observations.push(observation);
|
||||
}
|
||||
None => {
|
||||
final_reply = Some(response);
|
||||
final_reply_revision = Some(planning_request_revision.revision);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
observations = sanitize_game_creator_agent_runtime_context_observations_for_storage(
|
||||
@@ -4339,16 +4379,8 @@ async fn run_game_creator_agent_background_task_pass_without_deadline(
|
||||
break attempt_result;
|
||||
}
|
||||
envelope_repair_attempt += 1;
|
||||
let observation = AgentRuntimeToolObservation {
|
||||
tool: "runtime.plan_envelope".to_string(),
|
||||
status: "failed".to_string(),
|
||||
summary: format!(
|
||||
"AGC_NEEDS_USER_INPUT_V1 信封无法解析(第 {envelope_repair_attempt}/{AGENT_RUNTIME_PLAN_ENVELOPE_REPAIR_ATTEMPTS} 次重取):{parse_error}"
|
||||
),
|
||||
detail: Some(
|
||||
"原样重出同一个问题,不要改写题面或选项;信封必须是首行 AGC_NEEDS_USER_INPUT_V1,下一行严格 JSON 且完整闭合到最外层。不要输出 markdown、代码围栏或第三行正文。".to_string(),
|
||||
),
|
||||
};
|
||||
let observation =
|
||||
plan_envelope_repair_observation(&parse_error, envelope_repair_attempt);
|
||||
let observation_summary = observation.summary();
|
||||
runtime.observations.push(observation_summary);
|
||||
context_tracker.record(&observation);
|
||||
@@ -4687,6 +4719,39 @@ mod plan_envelope_repair_tests {
|
||||
fn the_repair_budget_matches_the_prototype() {
|
||||
assert_eq!(AGENT_RUNTIME_PLAN_ENVELOPE_REPAIR_ATTEMPTS, 2);
|
||||
}
|
||||
|
||||
/// 现场原样抓来的退化尾巴:信封本体完整,模型在同一个字符串里多吐了一段垃圾。
|
||||
/// 配平定界之后它是一条好信封,绝不能再烧掉一次重取额度——重取的成本是一整发
|
||||
/// provider 请求,而这一条本来就该直接放行。
|
||||
#[test]
|
||||
fn a_degenerated_tail_no_longer_burns_a_repair_attempt() {
|
||||
let reply = concat!(
|
||||
"AGC_NEEDS_USER_INPUT_V1\n",
|
||||
r#"{"questions":[{"id":"replay_progression","header":"第2轮·关键决定","question":"当前要决定:自由经营农场的长期目标采用哪种组合?","options":[{"label":"A · 推荐:里程碑升级+成就","description":"以累计资金解锁少量新地块或设施。"},{"label":"B · 专注农场扩建","description":"只用经营收益逐步解锁地块与设施。"},{"label":"需要原型验证","description":"制作微型原型让目标玩家试玩两种目标结构。"}]}]}સwerhu рҭ. 北京赛车? тру. [ ]"#,
|
||||
);
|
||||
assert!(game_creator_agent_runtime_plan_envelope_parse_error(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
reply
|
||||
)
|
||||
.is_none());
|
||||
}
|
||||
|
||||
/// 两个注入点必须给出同一条整改正文,否则模型会把它读成两种不同的失败。
|
||||
/// attempt 0 是工具计划直出那一发被拒——现场 7 条坏信封全部走这条路,而它
|
||||
/// 恰恰是重取回路唯一进不去的地方。
|
||||
#[test]
|
||||
fn both_injection_points_share_one_instruction_and_name_their_stage() {
|
||||
let first = plan_envelope_repair_observation("信封 JSON 括号不闭合", 0);
|
||||
let retry = plan_envelope_repair_observation("信封 JSON 括号不闭合", 1);
|
||||
assert_eq!(first.tool, "runtime.plan_envelope");
|
||||
assert_eq!(first.status, "failed");
|
||||
assert_eq!(first.detail, retry.detail);
|
||||
assert!(first.summary.contains("工具计划直出"), "{}", first.summary);
|
||||
assert!(retry.summary.contains("第 1/2 次重取"), "{}", retry.summary);
|
||||
for observation in [&first, &retry] {
|
||||
assert!(observation.summary.contains("括号不闭合"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user