优化: 狗粮短板收口与patch_file增强
- patch_file old_text 精确未中时空白归一化回退(行首缩进归一+多空白折叠,唯一命中按整行区间替换,warning 注明) - patch_file anchor end 唯一性校验:多处命中报错并列前两处位置,治实测×2 锚点错位;三模式同传按优先级仲裁(anchor>old_text>replace_lines),warning 注明 - tool_result 压缩 memoization:PerConvState 加 tool_compress_cache(内容哈希→压缩结果),主 loop+子代理双调用点接线,治 369 组同内容反复重压 - 标题采样改两段式:user 首条必进锚定主题+其余按序补足 6 条,治 assistant 首句被当主题 - prompt 注入文件读取纪律段(父会话+子代理同源):read_file 分页/search 直读,禁 run_command 切片读文件;read_file 工具描述与 truncated 提示补大 limit 建议 - 顺带 DRY#1:agentic/mod.rs 三处裸 emit 换正典双写(心跳/破坏性回环熔断/stall 熔断),miniapp 跨端盲区补齐
This commit is contained in:
@@ -106,6 +106,7 @@ fn system_prompt_parts(lang: &str) -> (String, &'static str, &'static str) {
|
||||
- When a tool call fails, clearly tell the user it failed and why. Never disguise a fallback action as the original intent's success (e.g. don't write to description to fake a directory binding), and never falsely report success\n\
|
||||
- **Self-check before claiming completion**: Before announcing a task done, verify the result matches the original intent (grep key references / read back field values / cross-check). Fix discrepancies before declaring success; never claim all done without verification (repeatedly observed: missed reference renames, fields silently overwritten by later ops, forcing the user to manually verify)\n\
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
## Focus\n\
|
||||
- Always center your response on the core goal of the user's current request; the previous round's topic is only background, not the current task.\n\
|
||||
- When the user switches topics (a clear new intent), follow the latest request; do not drag the old topic into the new answer.\n\
|
||||
@@ -113,6 +114,7 @@ fn system_prompt_parts(lang: &str) -> (String, &'static str, &'static str) {
|
||||
- Do not proactively expand context (files/data) that is irrelevant to the current request.\n",
|
||||
read_symbol_guidance(lang),
|
||||
duplicate_call_guidance(lang),
|
||||
file_reading_guidance(lang),
|
||||
),
|
||||
"\n## Current Projects\n",
|
||||
"\n## Current Tasks\n",
|
||||
@@ -135,6 +137,7 @@ fn system_prompt_parts(lang: &str) -> (String, &'static str, &'static str) {
|
||||
- 优先使用工具完成操作,而不是只描述步骤\n\
|
||||
- 工具调用失败时必须明确告知用户失败原因,严禁用替代操作冒充原意图成功(如绑定目录失败不得改写描述冒充已绑定),也绝不谎报成功\n\
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
## 聚焦准则\n\
|
||||
- 始终围绕用户当前请求的核心目标回答;上一轮的主题只是背景,不是当前任务。\n\
|
||||
- 用户切换话题(明显的新意图)时,以最新请求为准,不要把旧话题带进新回答。\n\
|
||||
@@ -142,6 +145,7 @@ fn system_prompt_parts(lang: &str) -> (String, &'static str, &'static str) {
|
||||
- 需要的上下文(文件/数据)若与当前请求无关,不要主动展开。\n",
|
||||
read_symbol_guidance(lang),
|
||||
duplicate_call_guidance(lang),
|
||||
file_reading_guidance(lang),
|
||||
),
|
||||
"\n## 当前项目\n",
|
||||
"\n## 当前任务\n",
|
||||
@@ -193,6 +197,16 @@ fn duplicate_call_guidance(lang: &str) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// 文件读取纪律指引(中/英,不含行首 "- ")。狗粮实证(2026-10-04):67+ 次 run_command
|
||||
/// PowerShell/python 切片绕道读文件,而 read_file 本身支持 offset/limit 分页+search 参数。
|
||||
/// 父会话能力清单与子代理工具纪律段同源拼接(同 read_symbol_guidance 模式)。
|
||||
fn file_reading_guidance(lang: &str) -> &'static str {
|
||||
match lang {
|
||||
"en" => "**File reading discipline**: read_file supports offset/limit pagination and the search parameter (search matching lines inside a file) — use them to read large files in pages or locate content directly. Never use run_command (PowerShell/python scripts) to slice or read files — it is slower, bypasses path authorization and binary detection, and pollutes context; run_command is for running tests/builds/binaries only",
|
||||
_ => "**文件读取纪律**:read_file 自带 offset/limit 分页与 search 参数(文件内容行级搜索)——大文件用它分页续读、定位内容直接传 search。严禁用 run_command(PowerShell/python 脚本)切片或读取文件——更慢、绕过路径授权与二进制检测、且污染上下文;run_command 仅用于跑测试/构建/二进制等命令执行场景",
|
||||
}
|
||||
}
|
||||
|
||||
/// 子代理工具纪律段(P1-1):与父会话 system prompt 同源拼接的工具使用纪律 ——
|
||||
/// read_symbol 优先 / 重复调用检测 / URL 三工具纪律与禁臆造 URL / render=true 失败
|
||||
/// 2 次必换方案 / 查配置用 get_app_config。子代理白名单缺省下发全量 Low 工具,
|
||||
@@ -202,10 +216,12 @@ fn duplicate_call_guidance(lang: &str) -> &'static str {
|
||||
pub(crate) fn sub_agent_tool_discipline_section(lang: &str) -> String {
|
||||
format!(
|
||||
"\n## 工具纪律\n\
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
- {}\n{}{}",
|
||||
read_symbol_guidance(lang),
|
||||
duplicate_call_guidance(lang),
|
||||
file_reading_guidance(lang),
|
||||
doc_strategy_core_section(lang),
|
||||
app_config_query_guidance_section(lang),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user