jpskill.com
🛠️ 開発・MCP コミュニティ

control-loop-extraction

Extract and analyze agent reasoning loops, step functions, and termination conditions. Use when needing to (1) understand how an agent framework implements reasoning (ReAct, Plan-and-Solve, Reflection, etc.), (2) locate the core decision-making logic, (3) analyze loop mechanics and termination conditions, (4) document the step-by-step execution flow of an agent, or (5) compare reasoning patterns across frameworks.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o control-loop-extraction.zip https://jpskill.com/download/18854.zip && unzip -o control-loop-extraction.zip && rm control-loop-extraction.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18854.zip -OutFile "$d\control-loop-extraction.zip"; Expand-Archive "$d\control-loop-extraction.zip" -DestinationPath $d -Force; ri "$d\control-loop-extraction.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して control-loop-extraction.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → control-loop-extraction フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] control-loop-extraction

制御ループの抽出

フレームワークのソースコードから、コアとなるエージェントの推論ループを抽出し、文書化します。

プロセス

  1. ループの特定 - メインのエージェント実行ループを見つけます。
  2. パターンの分類 - ReAct、Plan-and-Solve、Reflection、または Tree-of-Thoughts のいずれかを特定します。
  3. ステップ関数の抽出 - LLM → パース → 決定の流れを文書化します。
  4. 終了条件のマッピング - すべてのループ終了条件をカタログ化します。

推論パターンの特定

パターンシグネチャ

ReAct (Reason + Act)

# Signature: Thought → Action → Observation cycle
while not done:
    thought = llm.generate(prompt)      # Reasoning
    action = parse_action(thought)       # Action selection
    observation = execute(action)        # Environment feedback
    prompt = update_prompt(observation)  # Loop continuation

Plan-and-Solve

# Signature: Upfront planning, then execution
plan = llm.generate("Create a plan for...")
for step in plan.steps:
    result = execute_step(step)
    if needs_replan(result):
        plan = replan(...)

Reflection

# Signature: Act → Self-critique → Adjust
while not done:
    action = llm.generate(prompt)
    result = execute(action)
    critique = llm.generate(f"Evaluate: {result}")
    if critique.needs_adjustment:
        prompt = adjust_approach(critique)

Tree-of-Thoughts

# Signature: Branch → Evaluate → Select
thoughts = [generate_thought() for _ in range(n)]
scores = [evaluate(t) for t in thoughts]
best = select_best(thoughts, scores)

ステップ関数の分析

「ステップ関数」は、エージェント実行の最小単位です。以下を抽出します。

  1. 入力の組み立て - LLM のコンテキストがどのように構築されるか
  2. LLM の呼び出し - 実際のモデル呼び出し
  3. 出力のパース - 生の出力が構造化されたアクションになる方法
  4. アクションのディスパッチ - ツール実行と最終応答ルーティングのどちらか

主要なコードパターン

# Common step function structure
def step(self, state):
    # 1. Assemble input
    messages = self._build_messages(state)

    # 2. Call LLM
    response = self.llm.invoke(messages)

    # 3. Parse output
    parsed = self._parse_response(response)

    # 4. Dispatch
    if parsed.is_tool_call:
        return self._execute_tool(parsed.tool, parsed.args)
    else:
        return AgentFinish(parsed.final_answer)

終了条件のカタログ

一般的な終了パターン

条件 実装 リスク
ステップ制限 if step_count >= max_steps 有効な実行を途中で終了させる可能性があります
トークン制限 if total_tokens >= max_tokens 思考の途中で切り捨てられる可能性があります
明示的な終了 if action.type == "finish" LLM の協力に依存します
タイムアウト if elapsed > timeout 実時間で予測不能です
ループ検出 if state in seen_states 状態のハッシュ化が必要です
エラーしきい値 if error_count >= max_errors 回復可能なエラーで終了する可能性があります

アンチパターン: 終了ガードがない場合

# DANGEROUS: No exit condition
while True:
    result = agent.step()
    if result.is_done:  # What if LLM never outputs done?
        break

修正: 常にステップカウンターを含めます。

for step in range(max_steps):
    result = agent.step()
    if result.is_done:
        break
else:
    logger.warning("Hit max steps limit")

出力テンプレート

## 制御ループ分析: [Framework Name]

### 推論トポロジー
- **パターン**: [ReAct | Plan-and-Solve | Reflection | Tree-of-Thoughts | Hybrid]
- **場所**: `path/to/agent.py:L45-L120`

### ステップ関数
- **入力の組み立て**: [コンテキスト構築の説明]
- **LLM 呼び出し**: [メソッドとパラメータ]
- **パーサー**: [出力の構造化方法]
- **ディスパッチロジック**: [ツールと終了の決定]

### 終了条件
1. [コード参照付きの条件 1]
2. [コード参照付きの条件 2]
3. ...

### ループ検出
- **方法**: [ヒューリスティック | 状態ハッシュ | なし]
- **実装**: [コード参照または N/A]

統合ポイント

  • 前提条件: エージェントファイルを特定するための codebase-mapping
  • 入力として供給: パターン比較のための comparative-matrix
  • 入力として供給: 新しいループ設計のための architecture-synthesis
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Control Loop Extraction

Extracts and documents the core agent reasoning loop from framework source code.

Process

  1. Locate the loop - Find the main agent execution loop
  2. Classify the pattern - Identify ReAct, Plan-and-Solve, Reflection, or Tree-of-Thoughts
  3. Extract the step function - Document the LLM → Parse → Decide flow
  4. Map termination - Catalog all loop exit conditions

Reasoning Pattern Identification

Pattern Signatures

ReAct (Reason + Act)

# Signature: Thought → Action → Observation cycle
while not done:
    thought = llm.generate(prompt)      # Reasoning
    action = parse_action(thought)       # Action selection
    observation = execute(action)        # Environment feedback
    prompt = update_prompt(observation)  # Loop continuation

Plan-and-Solve

# Signature: Upfront planning, then execution
plan = llm.generate("Create a plan for...")
for step in plan.steps:
    result = execute_step(step)
    if needs_replan(result):
        plan = replan(...)

Reflection

# Signature: Act → Self-critique → Adjust
while not done:
    action = llm.generate(prompt)
    result = execute(action)
    critique = llm.generate(f"Evaluate: {result}")
    if critique.needs_adjustment:
        prompt = adjust_approach(critique)

Tree-of-Thoughts

# Signature: Branch → Evaluate → Select
thoughts = [generate_thought() for _ in range(n)]
scores = [evaluate(t) for t in thoughts]
best = select_best(thoughts, scores)

Step Function Analysis

The "step function" is the atomic unit of agent execution. Extract:

  1. Input Assembly - How context is constructed for the LLM
  2. LLM Invocation - The actual model call
  3. Output Parsing - How raw output becomes structured actions
  4. Action Dispatch - Tool execution vs. final response routing

Key Code Patterns

# Common step function structure
def step(self, state):
    # 1. Assemble input
    messages = self._build_messages(state)

    # 2. Call LLM
    response = self.llm.invoke(messages)

    # 3. Parse output
    parsed = self._parse_response(response)

    # 4. Dispatch
    if parsed.is_tool_call:
        return self._execute_tool(parsed.tool, parsed.args)
    else:
        return AgentFinish(parsed.final_answer)

Termination Condition Catalog

Common Termination Patterns

Condition Implementation Risk
Step limit if step_count >= max_steps May cut off valid execution
Token limit if total_tokens >= max_tokens May truncate mid-thought
Explicit finish if action.type == "finish" Relies on LLM cooperation
Timeout if elapsed > timeout Wall-clock unpredictable
Loop detection if state in seen_states Requires state hashing
Error threshold if error_count >= max_errors May exit on recoverable errors

Anti-Pattern: No Termination Guard

# DANGEROUS: No exit condition
while True:
    result = agent.step()
    if result.is_done:  # What if LLM never outputs done?
        break

Fix: Always include a step counter:

for step in range(max_steps):
    result = agent.step()
    if result.is_done:
        break
else:
    logger.warning("Hit max steps limit")

Output Template

## Control Loop Analysis: [Framework Name]

### Reasoning Topology
- **Pattern**: [ReAct | Plan-and-Solve | Reflection | Tree-of-Thoughts | Hybrid]
- **Location**: `path/to/agent.py:L45-L120`

### Step Function
- **Input Assembly**: [Description of context building]
- **LLM Call**: [Method and parameters]
- **Parser**: [How output is structured]
- **Dispatch Logic**: [Tool vs Finish decision]

### Termination Conditions
1. [Condition 1 with code reference]
2. [Condition 2 with code reference]
3. ...

### Loop Detection
- **Method**: [Heuristic | State hash | None]
- **Implementation**: [Code reference or N/A]

Integration Points

  • Prerequisite: codebase-mapping to identify agent files
  • Feeds into: comparative-matrix for pattern comparison
  • Feeds into: architecture-synthesis for new loop design