受控修复路径:invalid_arguments 反馈后的恢复
Agent 辅助工程检查
前置要求
Day 74 的验证分层;确定性适配器的故障模式。
学习目标
运行注入的 invalid_arguments 故障,观察结构化错误观察,确认适配器在重试预算内恢复为一次完成且经外部验证的运行。
操作指引
1. 在 REPL 中于 tempfile 工作区内以 DeterministicModelAdapter(fault="invalid_arguments") 与 AgentConfig(max_steps=6, max_retries=2) 运行任务。
2. 第 1 步提案 read_note 且 filename 为 ../outside.txt;basename 规则拒绝:观察 {ok:false, error:invalid_arguments};retries 变为 1。
3. 下一次模型请求中,适配器依据历史(尚无成功的 list_notes)重新规划,发出 list_notes,再两次读取,最后 write_report——这就是受控修复路径:坏调用不会被静默原样重试,错误观察引导下一个动作。
4. 验证 RunResult:status completed、steps 5、retries 1、termination goal_reached;随后用 evaluate() 评分。
5. 与 Reflexion 式语言反馈对比:本适配器只重读失败观察,不保存推理文本——修复证据全部存在于 action/observation 轨迹中。
自主演练与记录
执行故障运行;记录 trace[0].observation.error、trace[1].observation.ok、steps、retries、status 与 termination;确认 report.txt 内容等于 expected_report()。
参照 tests/projects/test_agent_learning.py::test_invalid_arguments_are_observed_then_corrected_within_retry_budget。
import tempfile
from pathlib import Path
from projects.agent_learning.agent import DeterministicModelAdapter, AgentConfig, run_task, evaluate
from projects.agent_learning.fixtures import create_fixture, expected_report
with tempfile.TemporaryDirectory() as d:
ws = Path(d); create_fixture(ws)
r = run_task("summarize-notes", ws, DeterministicModelAdapter(fault="invalid_arguments"), AgentConfig(max_steps=6, max_retries=2))
assert r.trace[0]["observation"]["error"] == "invalid_arguments"
assert r.status == "completed" and r.retries == 1 and r.steps == 5
assert (ws / "report.txt").read_text() == expected_report()
以精确计数(steps=5、retries=1、completed/goal_reached)复现修复路径,并解释为什么同一个坏调用不会被逐字重试。
权威源资源与权利证明
Reflexion: Language Agents with Verbal Reinforcement Learning
对应章节 / 时间戳: Section 2 & 3 (Reflexion Architecture and Memory Buffer)
验证版本与日期: NeurIPS 2023 / arXiv:2303.11366v4 (Verified: 2026-10-30)
Rigorous framework analyzing dynamic error feedback, memory buffering of execution failures, and controlled self-reflection loops without updating model weights.
Reinforcement learning concepts, agent evaluation loops, and error feedback handling.
Error recovery state diagrams and retry budget algorithms are detailed in curriculum materials.
对比候选资源与选型分析 (2)
Single-turn generative text refinement; Reflexion operates across multi-turn external environment action-observation failures.
Domain-specific LLM-based agent for open-world Minecraft; Reflexion establishes domain-general verbal feedback control loops.
ReAct: Synergizing Reasoning and Acting in Language Models
对应章节 / 时间戳: Section 3 & 4 (ReAct Formulation and Synergy)
验证版本与日期: ICLR 2023 / arXiv:2210.03629v2 (Verified: 2026-10-30)
Foundational academic paper introducing the interleaved Thought-Action-Observation control loop in LLM agents, establishing formal interleaving of task reasoning and external tool execution.
Prompt engineering, token generation basics, and conversational interaction loops.
Complete algorithmic step traces, state loop diagrams, and control loop pseudocode are self-contained in curriculum materials.
对比候选资源与选型分析 (2)
Pure reasoning without environmental actions or external tool grounding; ReAct extends reasoning into an interactive environment action-observation loop.
Early neuro-symbolic modular router concept; ReAct offers simpler, prompting-native action-observation loop dynamics suitable for standard API models.