モデルリクエストとアクション・観測の制御ループ
Agent支援エンジニアリングチェック
前提条件
Day 70-72 のモデル評価の概念と、Agent ツールトラックで導入された境界付き Agent Learning Project(projects/agent_learning)。
学習目標
ツール使用 Agent の制御ループの 5 つの段階 - モデルリクエスト、アクション提案、ツールディスパッチ、構造化観測、ループ継続または終了 - を説明し、各段階を決定論的 projects.agent_learning ハーネスに対応付けます。
手順
参照資料: この活動に割り当てられた既存の読解・練習時間内で、Hugging Face Agents Course: Introduction to Agents の Unit 1: What is an Agent?; What are Tools?; agent workflow; Summary; Quiz を参照し、ローカル課題とのつながりを一つ自分の言葉で説明する。既存の演習と合格基準は維持し、外部資料が開けない場合は本コース独自の説明を使う。1. 制御ループ:各ステップでランタイムはタスク・会話履歴・利用可能なツールスキーマをモデルへ送信し、モデルは 1 つのアクション候補を返します。ランタイムはそれを検証して境界付きツールへディスパッチし、ツールの構造化観測を履歴へ追加し、終了条件が発火するまでループを繰り返します。
2. ReAct(Yao 他 2022)は実環境で推論トレースとアクションを交互に挟みます。本 Learning Project は意図的に action と observation のイベントだけを保持し、thought や chain_of_thought フィールドは一切記録しません。収集する証拠は隠れた推論ではなく観測可能な振る舞いです。
3. ハーネスの状態遷移図:
IDLE -> MODEL_REQUEST -> ACTION_PROPOSED -> TOOL_DISPATCH -> OBSERVATION ->(MODEL_REQUEST へ戻る)... -> TERMINATE
run_task の終了理由:goal_reached(write_report の観測が ok)、tool_failure(失敗した観測が max_retries を超過)、step_budget(ステップ数が先に max_steps へ到達)。
4. 境界付きプロジェクトでは:DeterministicModelAdapter.next_action(history) がモデルの役割を演じ、_tool_call(action, workspace) が検証と実行を行い、run_task がループと予算を管理し、evaluate() が事後にワークスペース成果物を独立して再採点します。
5. 正直な適用範囲:このフィクスチャはループ構造とエラー語彙を示すもので、JSON-RPC フレーミング・能力ネゴシエーション・ストリーミングは実装していません。これは教育用モデルであり、プロトコル準拠クライアントではありません。
演習と予測記録
実行する前に、フィクスチャ summarize-notes の予測アクション列(ツール名と引数)、最終 status・steps・retries・終了理由を書きなさい。
projects/agent_learning/agent.py の DeterministicModelAdapter.next_action を読みましょう。ポリシーは最初にノート一覧を取得し、alpha.txt と beta.txt を読み、両方を観測後にレポートを書き込みます。
# 予測トレース / predicted trace
predicted = [
{"name": "list_notes", "arguments": {}},
{"name": "read_note", "arguments": {"filename": "alpha.txt"}},
{"name": "read_note", "arguments": {"filename": "beta.txt"}},
{"name": "write_report", "arguments": {"content": "Alpha is the first item.\nBeta is the second item.\n"}}
]
# 予測 RunResult: status="completed", steps=4, retries=0, termination="goal_reached"
5 つのループ段階すべて、3 つの終了理由とその発火条件を独立に述べ、アクション・観測の証拠が隠れた思考連鎖を含まない理由を説明できること。
公式ソースリソースと権利証跡
Hugging Face Agents Course: Introduction to Agents
該当セクション・タイムスタンプ: Unit 1: What is an Agent?; What are Tools?; agent workflow; Summary; Quiz
検証バージョンと日付: Public edition checked 2026-11-01; moving pages may change
A sequenced introduction, examples and quizzes before formal ReAct/tool API references. Adopt the control-loop concepts, not framework-specific execution or private-reasoning logs.
Python, language-model messages and JSON; local agent exercises use only action/observation traces.
Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.
比較対象候補リソースと選定評価 (2)
Retained as the method-definition paper; not a self-contained beginner exercise course.
Retained for one protocol example; vendor message formats are not interchangeable.
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.
Toolformer: Language Models Can Teach Themselves to Use Tools
該当セクション・タイムスタンプ: Section 2 (Approach: Tool Use and Filtering)
検証バージョンと日付: NeurIPS 2023 / arXiv:2302.04761v1 (Verified: 2026-10-30)
Original paper demonstrating self-supervised discovery and execution of tool API calls (calculator, QA, search, calendar) via inline tokenized tool invocations.
Transformer autoregressive generation, API calling syntax, and self-supervised filtering.
Inline tool invocation formats and self-contained mock execution traces are provided in curriculum notes.
比較対象候補リソースと選定評価 (2)
Focuses on massive API retrieval and documentation formatting; Toolformer focuses on the fundamental token-level seam between model generation and tool execution.
Iterative search-and-execute augmentation; Toolformer provides clearer self-supervised API call tokenization syntax.