受控修復路徑: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.