エージェント実行状態マシンとアクション/観測トレース
Agent支援エンジニアリングチェック
前提条件
第73〜75日のエージェントループとツールプロトコル学習、およびTicket 22の境界付きエージェントプロジェクト(projects/agent_learning)。
学習目標
境界付きエージェントが保持する完全な実行状態(アクション/観測トレース、ステップカウンタ、リトライカウンタ)を特定し、3つの合法終了状態(goal_reached, tool_failure, step_budget)を列挙する。
手順
1. projects/agent_learning/agent.py を開き run_task を読みます。
- 実行ごとの可変状態: trace({action, observation} ペアの追記専用リスト)、retries(ok=false の観測回数)、暗黙のステップカウンタ len(trace)。
- 終了遷移: write_report が ok=true を返す -> status=completed, termination=goal_reached。retries が max_retries(=2) を超過 -> status=failed, termination=tool_failure。どちらでもなくループ終了 -> status=budget_exhausted, termination=step_budget。
2. 意図的に存在しないものを確認します: 思考連鎖フィールドも隠れたスクラッチパッドもなく、トレースが永続化される全状態です(project.json の evidence.forbidden_fields が thought と chain_of_thought を列挙)。
3. 本番のチェックポイント機構と比較します: LangGraph のチェックポインタは各スーパーステップでグラフ状態を永続化し、Temporal はイベント履歴のリプレイで状態を再構築します。本トレースは同じ思想の最小イベントログです。
4. python -m projects.agent_learning.cli evaluate --fixture summarize-notes --output /tmp/agent-run.json を実行し、result.status と result.termination を確認します。
演習と予測記録
実行前に通常実行の4ステップトレースを予測し、CLIを実行して各ステップの遷移(アクション提案 -> 観測記録 -> カウンタ更新)を記録してください。steps=4, retries=0, termination=goal_reached で終了することを確認します。
completed を生む唯一の遷移は write_report 観測の ok=true です。他の成功ステップはトレースに追記されるだけです。
steps=4: list_notes -> read_note(alpha.txt) -> read_note(beta.txt) -> write_report。ステップ4で write_report 観測が ok を返したため status が completed になります。ok=false の観測が無いため retries は0のまま。termination='goal_reached'。
コードを実行せずに、失敗した観測で増加するカウンタ(retries)、健全な実行を終了させる上限(max_steps=6)、成功時に早期終了させる唯一のアクション(write_report)を答えられる。
公式ソースリソースと権利証跡
LangGraph Persistence: Checkpoints, Threads, and State Snapshots
該当セクション・タイムスタンプ: Persistence: Checkpointer vs. store (checkpoints keyed by thread_id); the page now redirects to docs.langchain.com
検証バージョンと日付: LangGraph documentation (Verified: 2026-10-30)
Primary reference for agent-run checkpointing: LangGraph checkpointers persist graph state at every super-step so interrupted runs resume from the last committed snapshot, the production analogue of this project's action/observation trace.
Agent loop fundamentals, tool calling, and JSON state serialization.
The checkpoint/replay exercise is implemented directly against the projects/agent_learning trace JSON; no framework installation is required.
比較対象候補リソースと選定評価 (2)
Temporal persists event histories for replay-based recovery of arbitrary workflows; LangGraph targets agent graphs specifically and stays closer to the learner's tool-loop mental model.
Provider-scoped SDK sessions; LangGraph's explicit checkpoint model exposes the underlying state-transition semantics more transparently.
Temporal Documentation: Durable Execution and Event History Replay
該当セクション・タイムスタンプ: What is Temporal?: Durable Execution
検証バージョンと日付: Temporal documentation (Verified: 2026-10-30)
Standard industrial reference for durable execution: workflow state is rebuilt by replaying a persisted event history through deterministic code, exactly the checkpoint/replay mechanism learners reproduce against the agent trace.
State machines, event logs, and deterministic replay concepts.
Replay semantics are exercised offline against the deterministic adapter; Temporal itself is never installed.
比較対象候補リソースと選定評価 (2)
Agent-specific checkpointing; Temporal supplies the general event-sourced replay model that motivates the exercise.
Temporal's predecessor with equivalent replay semantics; Temporal's docs are more actively maintained.