Loop Detectionのロゴ

Loop Detection

コミュニティ
Omar-Obando
loop-detection

Use when identifying and preventing infinite loops, detecting loop patterns, implementing loop exit strategies, and creating loop safety mechanisms. Includes loop analysis, timeout patterns, and loop monitoring. Based on programming best practices and loop safety patterns.

概要

公開者Omar-Obando
リポジトリqwen-orchestrator
スキル名loop-detection
スター
53
フォーク
13
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    Omar-ObandoがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Loop Detection」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/Omar-Obando/qwen-orchestrator/tree/main/skills/loop-detection
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Omar-Obando/qwen-orchestrator.git /tmp/qwen-orchestrator
mkdir -p .claude/skills
cp -r /tmp/qwen-orchestrator/skills/loop-detection .claude/skills/loop-detection
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでLoop Detectionを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にLoop Detectionを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Loop Detectionは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Loop Detection Skill — Monitor & Loop Guardian

Overview

This skill provides comprehensive guidance for detecting and preventing infinite loops. It covers loop pattern identification, exit strategy implementation, timeout patterns, and loop monitoring following programming best practices and loop safety patterns.

When to Use

Use this skill when:

  • Identifying potential infinite loops in code
  • Detecting loop patterns in algorithms
  • Implementing loop exit strategies
  • Adding timeout mechanisms to loops
  • Creating loop safety guards
  • Analyzing loop termination conditions
  • Implementing loop counters
  • Creating loop monitoring
  • Detecting loop stagnation
  • Implementing loop backoff strategies
  • Creating loop retry mechanisms
  • Adding loop progress tracking
  • Implementing loop cancellation
  • Creating loop documentation
  • Analyzing loop performance
  • Detecting loop resource leaks
  • Implementing loop limits
  • Creating loop validation
  • Detecting loop edge cases
  • Implementing loop error handling
  • Creating loop optimization strategies
  • Adding loop logging
  • Implementing loop health checks

Do NOT use this skill when:

  • Writing application business logic (use domain-driven skill)
  • Designing database schemas (use database-design skill)
  • Writing API endpoint specifications (use api-design skill)
  • Performing security audits (use security-auditor skill)
  • Writing SQL queries (use sql-best-practices skill)
  • Designing multi-page website layouts (use design-system skill)
  • Analyzing deployment configurations (use deployment skill)
  • Writing documentation (use documentation-best-practices skill)

Loop Patterns

Common Loop Patterns

┌─────────────────────────────────────────────────────────────┐
│              Loop Patterns                                  │
├─────────────────────────────────────────────────────────────┤
│  While Loop:                                                │
│  while condition:                                           │
│      # Loop body                                            │
│      # Must modify condition                                │
│                                                              │
│  For Loop:                                                  │
│  for i in range(n):                                         │
│      # Loop body                                            │
│      # Uses counter or iterator                             │
│                                                              │
│  Do-While Loop:                                             │
│  do {                                                       │
│      # Loop body                                            │
│  } while (condition);                                       │
│                                                              │
│  Nested Loop:                                               │
│  for i in range(n):                                         │
│      for j in range(m):                                     │
│          # Nested loop body                                 │
│                                                              │
│  Infinite Loop:                                             │
│  while true:                                                │
│      # Must have break condition                            │
│      if exit_condition:                                     │
│          break                                              │
└─────────────────────────────────────────────────────────────┘

Loop Exit Strategies

┌─────────────────────────────────────────────────────────────┐
│              Loop Exit Strategies                           │
├─────────────────────────────────────────────────────────────┤
│  1. Counter-Based:                                          │
│     for i in range(max_iterations):                         │
│         if condition:                                       │
│             break                                           │
│                                                              │
│  2. Condition-Based:                                        │
│     while not done:                                         │
│         if success:                                         │
│             done = True                                     │
│                                                              │
│  3. Timeout-Based:                                          │
│     start_time = time.now()                                 │
│     while time.now() - start_time < timeout:                │
│         if condition:                                       │
│             break                                           │
│                                                              │
│  4. State-Based:                                            │
│     while state != 'completed':                             │
│         state = update_state(state)                         │
│                                                              │
│  5. Resource-Based:                                         │
│     while resources_available():                            │
│         process_resource()                                  │
└─────────────────────────────────────────────────────────────┘

Loop Safety Mechanisms

Timeout Pattern

python
# ✅ Good: Timeout-based loop
import time

def process_with_timeout(max_duration=30):
    start_time = time.time()
    while not task_completed():
        if time.time() - start_time > max_duration:
            raise TimeoutError("Loop timed out")
        time.sleep(0.1)

Counter Pattern

python
# ✅ Good: Counter-based loop
def process_with_max_iterations(max_iterations=1000):
    count = 0
    while not task_completed():
        if count >= max_iterations:
            raise RuntimeError("Max iterations reached")
        count += 1
        process_iteration()

Backoff Pattern

python
# ✅ Good: Exponential backoff
import time

def retry_with_backoff(max_retries=5, base_delay=1):
    for attempt in range(max_retries):
        try:
            return perform_task()
        except Exception as e:
            if attempt == max_retries - 1:
                raise
            delay = base_delay * (2 ** attempt)
            time.sleep(delay)

Loop Detection Techniques

Static Analysis

┌─────────────────────────────────────────────────────────────┐
│              Static Analysis                                │
├─────────────────────────────────────────────────────────────┤
│  Check for:                                                 │
│  - Missing loop termination condition                       │
│  - Loop variable not updated                                │
│  - Condition always true                                    │
│  - No break statements                                      │
│  - Infinite recursion in loops                              │
│                                                              │
│  Tools:                                                     │
│  - Linters (ESLint, Pylint)                                 │
│  - Static analysis tools (SonarQube)                        │
│  - IDE warnings                                             │
└─────────────────────────────────────────────────────────────┘

Dynamic Analysis

┌─────────────────────────────────────────────────────────────┐
│              Dynamic Analysis                               │
├─────────────────────────────────────────────────────────────┤
│  Monitor at runtime:                                        │
│  - Loop iteration count                                     │
│  - Execution time                                           │
│  - Resource usage                                           │
│  - State changes                                            │
│                                                              │
│  Techniques:                                                │
│  - Add counters to loops                                    │
│  - Log loop progress                                        │
│  - Monitor memory usage                                     │
│  - Track execution time                                     │
└─────────────────────────────────────────────────────────────┘

Loop Health Monitoring

┌─────────────────────────────────────────────────────────────┐
│              Loop Health Monitoring                         │
├─────────────────────────────────────────────────────────────┤
│  Metrics:                                                   │
│  - Iteration count                                          │
│  - Duration per iteration                                   │
│  - Total loop duration                                      │
│  - Memory usage per iteration                               │
│  - CPU usage per iteration                                  │
│                                                              │
│  Alerts:                                                    │
│  - Iteration limit exceeded                                 │
│  - Duration threshold exceeded                              │
│  - Resource usage spike                                     │
│  - No progress detected                                     │
└─────────────────────────────────────────────────────────────┘

Loop Best Practices

Loop Design Checklist

┌─────────────────────────────────────────────────────────────┐
│              Loop Design Checklist                          │
├─────────────────────────────────────────────────────────────┤
│  [ ] Loop has clear termination condition                   │
│  [ ] Loop variable is properly updated                      │
│  [ ] Loop has timeout mechanism                             │
│  [ ] Loop has max iteration limit                           │
│  [ ] Loop handles edge cases                                │
│  [ ] Loop has error handling                                │
│  [ ] Loop has progress logging                              │
│  [ ] Loop has cancellation support                          │
│  [ ] Loop has resource cleanup                              │
│  [ ] Loop has documentation                                 │
└─────────────────────────────────────────────────────────────┘

Loop Documentation Template

python
def process_items(items, max_iterations=1000, timeout=30):
    """
    Process items with safety mechanisms.

    Args:
        items: List of items to process
        max_iterations: Maximum number of iterations (default: 1000)
        timeout: Maximum duration in seconds (default: 30)

    Returns:
        Processed items list

    Raises:
        RuntimeError: If max iterations reached
        TimeoutError: If timeout exceeded
    """
    start_time = time.time()
    count = 0

    for item in items:
        count += 1
        if count >= max_iterations:
            raise RuntimeError("Max iterations reached")
        if time.time() - start_time > timeout:
            raise TimeoutError("Loop timed out")

        # Process item
        process(item)

    return items

Real-World Impact

Before this skill:

  • Infinite loops causing crashes
  • Resource exhaustion
  • No loop monitoring
  • Difficult debugging
  • Production outages

After this skill:

  • Safe loops with exit strategies
  • Proper resource management
  • Loop monitoring and alerts
  • Easy debugging
  • Production stability

Cross-References

  • debugging - For loop debugging
  • performance - For loop optimization
  • testing-strategy - For loop testing

References

よくある質問

AIスキル「Loop Detection」では何ができますか?

Use when identifying and preventing infinite loops, detecting loop patterns, implementing loop exit strategies, and creating loop safety mechanisms. Includes loop analysis, timeout patterns, and loop monitoring. Based on programming best practices and loop safety patterns.

TypingMindでLoop Detectionを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Loop Detectionはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにLoop Detectionをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/Omar-Obando/qwen-orchestrator/tree/main/skills/loop-detectionを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Loop Detectionを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Loop Detectionで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもLoop Detectionを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Loop Detection」は無料ですか?

はい。Omar-ObandoがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇