同一条报错,换个位置放模型就不修了:Tool-Calling Agent 的错误投递

把这条报错原样留在对话里,模型会换条路径重试;把它删掉、只在上一句里补个"上次失败了",Llama 系列会直接停手不干了。同一条 FileNotFoundError: config/app.yaml,同样的模型、同样的温度、同样的用户意图,只改它出现的位置,下一步动作就变了。

不是玄学。2026-11-08 挂上 arXiv 的 2611.11581《Same Error, Different Recovery: How Delivery Changes LLM Agent Behavior》(Sunghyeun Woo、Javier Conde、Pedro Reviriego)把这件事做成了受控实验:两项研究都把计划在收集数据之前固定,跨 13 个开放模型、3B 到 70B,用确定性重跑比较"下一步动作"和"后续任务是否完成"。隔离出来的变量,是大多数 agent 框架根本没建模的那一层——错误是怎么被送到模型面前的。

改了什么,又没改什么

错误文本一个字不动。变的是 placement、guidance、retained history、turn structure。落到代码里就是三种典型投递:删掉失败交换(把 assistant 的 tool_calls 连同 role=tool 的结果一起抹掉,上下文最干净)、改写历史(把失败塞进上一条 user 消息里)、追加一条新 user turn(保留完整失败交换,另起一轮告诉模型出错了)。工具调用类应用里第一种特别常见,因为很多框架在"压缩上下文"或"遇到异常重置"时会顺手把失败的那几轮清掉。

结果:删掉失败交换时,Llama 系列出现论文里说的 severe stopping failure;追加新 user turn 能避开这个坑,在 pooled synthetic 比较里不劣于改写历史,但作者强调不是每个模型都最优。他们把这个形式做成确定性推理引擎里的 opt-in recovery layer, ToolMaze 上显式错误的成功率,7-8B 模型 +14.2 点,32-70B 模型 +10.5 点。

我最看重的是那个负结果:Loud/Quiet 有 24 个多轮任务,既有看得见的失败也有静默损坏,按最终状态一致性打分,没有测出可测量的收益。反过来,客户端如果拿到了精确的 fault kind,表现还要更好。所以论文的措辞相当克制——delivery 是恢复里一个独立因素,既不是引擎专属的解法,也不是一条通用重试策略。翻成大白话:"加一句请重试"只在错误被明确说出来时管用;工具返回了错的数据却没报错,这一层什么也做不了。

为什么位置能压过内容

消息角色是带语义的。assistant 自己写下的失败是"我的记录",user 轮里出现的失败是"外部观测到的事实"。把失败交换整段删掉,模型下一轮面对的是一个没有前因的断点——它连自己刚才调过哪个工具、参数是什么都不知道,最省事的动作就是停下来向用户交代。保留 tool_calls 和 tool_call_id 的配对,模型才能把"哪个调用炸了"和"下一步该改哪个参数"对上号。这也是为什么论文把 retained history 单列成一个变量:省下来的那几百个 token,买走的是因果链。

顺带一个特别容易踩的坑:配对校验通过,不等于信息还在。把整段失败交换删干净之后,orphan tool result 和 unanswered tool call 都是空的,校验看起来非常健康,可模型已经不记得自己试过什么。历史"干净"和状态"完整"是两码事,下面的实操会把这个反差直接打印出来。

今天其他几条消息,在说同一件事

机器之心 2026-11-12 挂出 NeurIPS 2026 论文解读《从「先出题」到「先探索」:重新思考 Tool-Calling Agent 的训练数据合成》——训练侧开始补失败轨迹,不再是先编好题目再补标准答案。ModelScope 上的 Qwopus3.8-27B-Coder-Flash(2026-11-08)把工作流直接写成"阅读 → 推理 → 调用工具 → 编辑 → 测试 → 恢复 → 交付",恢复是一个显式阶段,而不是藏在 retry 装饰器里。The Decoder 2026-11-04 报的 CloudOpsBench 更直白:45 个真实 AWS 运维任务,最好的模型也只解出 60%,约 80% 的失败源于误判任务范围、没查全相关服务、或者停得太早——跟论文里的 stopping failure 是同一种病,只是换到了云运维的场景。

工程侧最有意思的对照是今天 GitHub Trending 上的 microsoft/TokenEconomizer。它的 loop guard 要等 e=5 个正常结束的 turn 才学出本仓库的 usual turn,judge 置信度 ≥0.7 才给一次短 redirect,每 turn 最多 r=1 次,churning 超过 usual 长度 b=2.5 倍才用规则兜底,而且明确写着从不自行停止 turn。一边在研究"模型自己会停",一边在设计"系统绝不替你停",两边其实在回答同一个问题:停止这个动作,到底该由谁来做。

实操:把投递方式做成可切换的一层 step-by-step

下面这段只用标准库,python delivery.py 直接跑。三种策略构造出来的 messages、配对校验结果、token 估算一次打印;拿到真实端点后,把 build() 的返回值直接塞进请求体就是一组 A/B,不需要改 agent 主循环。

# delivery.py - stdlib only. Run: python delivery.py
# Build and validate three ways of handing a failed tool call back to an agent.

CALL_ID = "call_01"


def failed_exchange():
    return [
        {"role": "user", "content": "Read config/app.yaml and print the port."},
        {"role": "assistant", "content": "",
         "tool_calls": [{"id": CALL_ID, "name": "read_file",
                         "arguments": {"path": "config/app.yaml"}}]},
        {"role": "tool", "tool_call_id": CALL_ID,
         "content": "Error: FileNotFoundError: config/app.yaml"},
    ]


def drop_exchange(msgs):
    return [m for m in msgs
            if m["role"] != "tool" and not m.get("tool_calls")]


def rewrite_history(msgs):
    out = drop_exchange(msgs)
    out[0] = {"role": "user",
              "content": out[0]["content"]
                         + " Previous attempt failed: FileNotFoundError."}
    return out


def new_user_turn(msgs, fault_kind="FileNotFoundError"):
    out = [dict(m) for m in msgs]
    out.append({"role": "user",
                "content": "The tool call above failed with " + fault_kind
                           + ". Keep the failed exchange in context, "
                           + "then retry with a corrected path or report "
                           + "the missing file."})
    return out


def validate(msgs):
    calls = set()
    for m in msgs:
        for c in m.get("tool_calls", []):
            calls.add(c["id"])
    results = {m["tool_call_id"] for m in msgs if m["role"] == "tool"}
    return {
        "orphan_tool_results": sorted(results - calls),
        "unanswered_tool_calls": sorted(calls - results),
        "failed_exchange_kept": bool(results) and bool(calls),
        "roles": " ".join(m["role"] for m in msgs),
    }


def approx_tokens(msgs):
    return sum(len(str(m.get("content", ""))) // 4 + 8 for m in msgs)


def demo():
    base = failed_exchange()
    builders = [
        ("drop_exchange", drop_exchange),
        ("rewrite_history", rewrite_history),
        ("new_user_turn", new_user_turn),
    ]
    for name, build in builders:
        msgs = build(base)
        v = validate(msgs)
        print("%-16s msgs=%d tokens=%d roles=[%s]"
              % (name, len(msgs), approx_tokens(msgs), v["roles"]))
        print("%-16s failed_exchange_kept=%s orphan=%s unanswered=%s"
              % ("", v["failed_exchange_kept"],
                 v["orphan_tool_results"], v["unanswered_tool_calls"]))


if __name__ == "__main__":
    demo()
drop_exchange    msgs=1 tokens=18 roles=[user]
                 failed_exchange_kept=False orphan=[] unanswered=[]
rewrite_history  msgs=1 tokens=29 roles=[user]
                 failed_exchange_kept=False orphan=[] unanswered=[]
new_user_turn    msgs=4 tokens=89 roles=[user assistant tool user]
                 failed_exchange_kept=True orphan=[] unanswered=[]

看第二行:drop_exchange 和 rewrite_history 的 orphan、unanswered 都是空的,校验"通过",但 failed_exchange_kept=False。所以别把配对校验当恢复能力的证明。真要上生产,至少再补两件事:给 tool result 带上结构化的 fault_kind(论文里客户端拿到精确类型表现最好,这也省得让模型从自由文本里猜错误类别),以及对静默损坏单独做状态校验——Loud/Quiet 已经把话说死了,投递层救不了它,那得靠最终状态比对和外部断言。

一个只动消息顺序就能拿到 10 个点以上成功率的改动,通常意味着框架把某件事想当然了。这次被想当然的是:错误信息"写了",就等于"送达了"。

相关阅读

问题反馈

本站是纯前端静态站,没有后端也没有账号系统,反馈走 GitHub Issues、讨论区或邮件。

粘贴到 issue 或邮件里能帮我更快定位问题,其中不含你输入的任何内容

其它:查看已有反馈 · 邮件反馈(无需 GitHub 账号):278975598@qq.com