mcpField
A
agent-instinct-system

agent-instinct-system

github.com/itallstartedwithaideaエージェントワークフロー4478 回インストール28 週間前に更新
リポジトリ

agent-instinct-system について

agent-instinct-systemは、コード変更、ツール呼び出し、出力の前に段階的な安全チェックを行うスキルです。即時の反射、ゲート、詳細評価により、保護対象ファイルの変更や範囲外の操作などを検出します。

主な機能

  1. 01段階的な実行前チェック
  2. 02保護対象ファイルと操作の検証
  3. 03範囲・構文・依存関係の検証
  4. 04タスク適合性と影響の評価
  5. 05実行後の監査フィードバック

活用シーン

  1. 01保護対象ファイルの削除防止
  2. 02本番操作前の予算上限チェック
  3. 03指定されたタスク範囲内での操作

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/itallstartedwithaidea/agent-skills --skill agent-instinct-system

インストール後、Claude Code で/agent-instinct-systemを入力して読み込まれたか確認します。

詳細

エージェント本能システム

googleadsagent.ai™ による Agent Skills™ の一部です

説明

エージェント本能システムは、認知に先立つ反射を実装します。これは、コード変更、ツール呼び出し、出力生成の前に毎回実行される自動的な安全性チェックと検証です。生物の反射が意識的な思考よりも速く生物を危害から守るように、エージェントの本能は慎重な推論よりも速く、コードベースやシステムを損傷から守ります。これらの本能はタスク固有のロジックよりも下位のレベルで動作し、エージェントが何をしているかにかかわらず作動する汎用的な安全レイヤーを形成します。

googleadsagent.ai™ の Buddy™ エージェント向けに開発されました。Google Ads API の呼び出しを一度誤るだけで、クライアントの月間予算全額を使い切ってしまう可能性があるため、本能システムは決して破ってはならない不変条件を適用します。入札単価を変更する前に予算上限を確認します。破壊的な操作には確認シグナルが必要です。ファイルの削除は保護リストと照合して検証されます。エージェントがこうした処理を「覚えて」おく必要はなく、これらのチェックは自動的に実行されます。

本能システムは、3 つの階層に分かれています。反射(「このファイルは保護リストに含まれているか」など、即時に行われるコストゼロのチェック)、ゲート(「この変更はリンターを通過するか」など、軽量な検証)、評価(「この変更は明示されたタスクに沿っているか」など、よりコストの高いチェック)です。階層が上がるほどレイテンシーは増えますが、より微妙な問題を検出できます。

使用する場面

  • ミスが実害につながる本番システム上でエージェントが動作する場合
  • 1 回の検証だけでは不十分なため、多層防御が必要な場合
  • 複数のエージェントやチームメンバーが同じコードベースを同時に扱う場合
  • エージェントが破壊的な操作(削除、デプロイ、API の変更)を扱う場合
  • コンプライアンス要件により、AI が生成した変更に対して実行前の検証が義務付けられている場合
  • 事後に問題を検出するのではなく、ミスの種類そのものを防ぎたい場合

仕組み

graph TD
    A[Agent Intent] --> B[Tier 1: Reflexes]
    B -->|Block| C[Immediate Rejection]
    B -->|Pass| D[Tier 2: Gates]
    D -->|Block| E[Rejection + Guidance]
    D -->|Pass| F[Tier 3: Assessments]
    F -->|Block| G[Rejection + Alternative]
    F -->|Pass| H[Action Execution]
    H --> I[Post-Action Audit]
    I --> J[Instinct Learning]
    J --> K{New Pattern?}
    K -->|Yes| L[Add Reflex/Gate]
    K -->|No| M[Log + Continue]

エージェントが行動する意図(ファイルの書き込み、ツールの呼び出し、出力の生成)を形成すると、その意図は本能の各階層を順に通過します。Tier 1 の反射は、保護対象ファイルのリスト、禁止操作のパターン、予算上限のチェックなど、マイクロ秒単位で実行されるハードコードされたチェックです。Tier 2 のゲートでは、構文チェック、依存関係の検証、スコープの検証など、軽量な検証を実行します。Tier 3 の評価では、タスクとの整合性の検証、影響の推定、副作用の予測など、より詳細な分析を行います。実行後の監査結果は本能システムにフィードバックされ、ニアミスから新たな保護パターンを学習できるようになります。

実装

本能エンジンのコア:

type InstinctTier = "reflex" | "gate" | "assessment";

interface Instinct {
  name: string;
  tier: InstinctTier;
  check(intent: AgentIntent): Promise<InstinctResult>;
}

interface InstinctResult {
  allow: boolean;
  reason?: string;
  alternative?: string;
}

class InstinctEngine {
  private instincts: Map<InstinctTier, Instinct[]> = new Map([
    ["reflex", []],
    ["gate", []],
    ["assessment", []],
  ]);

  register(instinct: Instinct): void {
    this.instincts.get(instinct.tier)!.push(instinct);
  }

  async evaluate(intent: AgentIntent): Promise<InstinctResult> {
    for (const tier of ["reflex", "gate", "assessment"] as InstinctTier[]) {
      for (const instinct of this.instincts.get(tier)!) {
        const result = await instinct.check(intent);
        if (!result.allow) {
          return { ...result, reason: `[${instinct.name}] ${result.reason}` };
        }
      }
    }
    return { allow: true };
  }
}

組み込みの反射:

const PROTECTED_FILES_REFLEX: Instinct = {
  name: "protected-files",
  tier: "reflex",
  async check(intent) {
    const protectedPatterns = [
      /\.env($|\.)/,
      /credentials\./,
      /secrets?\./,
      /\.pem$/,
      /id_rsa/,
      /package-lock\.json$/,
      /yarn\.lock$/,
    ];
    if (intent.type === "file_write" || intent.type === "file_delete") {
      const blocked = protectedPatterns.some(p => p.test(intent.target));
      if (blocked) {
        return { allow: false, reason: `"${intent.target}" is a protected file` };
      }
    }
    return { allow: true };
  },
};

const DESTRUCTIVE_OP_REFLEX: Instinct = {
  name: "destructive-operation",
  tier: "reflex",
  async check(intent) {
    const destructive = ["rm -rf", "DROP TABLE", "DELETE FROM", "git push --force"];
    if (intent.type === "shell_command") {
      const cmd = intent.content.toLowerCase();
      const match = destructive.find(d => cmd.includes(d.toLowerCase()));
      if (match) {
        return {
          allow: false,
          reason: `Destructive operation detected: "${match}"`,
          alternative: "Use a safer alternative or request explicit confirmation",
        };
      }
    }
    return { allow: true };
  },
};

const BUDGET_CEILING_REFLEX: Instinct = {
  name: "budget-ceiling",
  tier: "reflex",
  async check(intent) {
    if (intent.type === "api_call" && intent.metadata?.estimatedCost) {
      const sessionBudget = intent.metadata.sessionBudget || 10.0;
      const spent = intent.metadata.sessionSpent || 0;
      if (spent + intent.metadata.estimatedCost > sessionBudget) {
        return {
          allow: false,
          reason: `Would exceed session budget ($${spent} + $${intent.metadata.estimatedCost} > $${sessionBudget})`,
        };
      }
    }
    return { allow: true };
  },
};

ゲート:スコープの検証:

class ScopeValidationGate:
    """Ensures the agent's action is within the stated task scope."""

    def __init__(self, allowed_paths: list[str], allowed_operations: list[str]):
        self.allowed_paths = [re.compile(p) for p in allowed_paths]
        self.allowed_operations = set(allowed_operations)

    async def check(self, intent):
        if intent["type"] not in self.allowed_operations:
            return {
                "allow": False,
                "reason": f"Operation '{intent['type']}' not in allowed set: {self.allowed_operations}",
            }
        if intent.get("target"):
            if not any(p.match(intent["target"]) for p in self.allowed_paths):
                return {
                    "allow": False,
                    "reason": f"Path '{intent['target']}' outside allowed scope",
                    "alternative": f"Allowed paths: {[p.pattern for p in self.allowed_paths]}",
                }
        return {"allow": True}

ベストプラクティス

  1. 反射動作はゼロコストに保ちます — Tier 1 の反射動作は I/O を伴わず、1ms 未満で実行する必要があります。ネットワーク呼び出しやモデル推論が必要な処理は、より上位のティアに配置してください。
  2. 拒否を次の行動につなげます — ブロックされたすべての意図に理由を含め、可能な場合はエージェントが代わりに実行できる別のアクションを提示してください。
  3. 拒否リストから始め、許可リストへ移行します — まず危険性が知られている操作をブロックし、その後、明示的に安全な操作のみを許可するよう段階的に制限を強化してください。
  4. すべてのインスティンクトの発動を記録します — ブロックされた意図と許可された意図をすべて、監査とインスティンクトの学習のために記録してください。
  5. 「信頼できる」タスクでもインスティンクトを省略しないでください — インスティンクトシステムは安全網です。利便性のために迂回すると、その目的が完全に損なわれます。
  6. インシデントから新しいインスティンクトを導き出します — 本番環境で発生したインシデントごとに、再発を防ぐ新しい反射動作またはゲートを少なくとも1つ追加してください。
  7. 敵対的な意図でインスティンクトをテストします — 各インスティンクトを回避するように設計した意図を作成し、それらを検出できることを確認してください。
  8. インスティンクトの設定にバージョンを付けます — 環境(dev/staging/prod)ごとに有効なインスティンクトを追跡し、変更を監査してください。

プラットフォームの互換性

機能Claude CodeCursorCodexGemini CLI
アクション前フック✅ PreToolUse✅ ルール✅ 指示✅ システムプロンプト
ファイル保護✅ 完全対応✅ 完全対応✅ サンドボックス✅ 完全対応
シェルコマンドのフィルタリング✅ 完全対応✅ 完全対応✅ サンドボックス✅ 完全対応
予算の適用✅ カスタムフック✅ 拡張機能✅ カスタム✅ カスタム
アクション後の監査✅ PostToolUse✅ ルール✅ カスタム✅ カスタム

関連するスキル

  • 敵対的な攻撃への耐性 - プロンプトインジェクションやデータ流出に対する多層防御で、インスティンクトレベルの保護を補完します
  • 検証ループ - インスティンクトがアクションを承認した後に出力を検証する、アクション後の評価パイプラインです
  • 自己修復エージェント - インスティンクトゲートが失敗を検出したときに作動する、自律的なエラー復旧機能です

キーワード

agent-instincts, pre-flight-checks, safety-gates, reflexes, destructive-operation-prevention, scope-validation, budget-ceiling, protected-files, defense-in-depth, agent-skills


© 2026 googleadsagent.ai™ | Agent Skills™ | MIT License

コメント