AI 坏 tool call 标记 errAck:入库留痕但移出模型上下文,防模仿死循环

- messages 新增 type 列,参数非法(JSON 坏/缺必填)的 assistant 轮标 errAck
- buildMessages 跳过 errAck 行及其关联 tool 回执,改发一条 user 错误提示引导重新生成
- tool_calls 落库时补全缺失 id,保证与 tool 回执配对一致
- safeParse 升级为 checkToolArgs:区分非法 JSON 与缺必填,执行前统一挡下
This commit is contained in:
2026-09-05 08:55:31 +08:00
parent 9e583afaf5
commit 848937c156
3 changed files with 75 additions and 18 deletions
+3
View File
@@ -41,6 +41,9 @@ function initDb(dbPath) {
`);
// 升级老库:早期表不带 reasoning 列,补上(重入安全;不在上面 db.exec 模板串里,免得被当作 SQL 解析)
try { db.exec('ALTER TABLE messages ADD COLUMN reasoning TEXT'); } catch (_) { /* 已存在 */ }
// 升级老库:type 标记特殊消息行。目前唯一取值 'errAck'——AI 的 tool call 参数错误
// (JSON 非法/缺必填)整条标记;仍入库供 UI 展示,但 buildMessages 发请求时跳过(见 llm.js)
try { db.exec('ALTER TABLE messages ADD COLUMN type TEXT'); } catch (_) { /* 已存在 */ }
db.exec(`
CREATE TABLE IF NOT EXISTS files (