失

失控循环护栏(Agent Loop Guard)

作者:注册老炮@MedXpert I SynomosAIv6

当用户说『agent卡死了』『一直在重复同样动作』『跑飞了烧光token』『怎么给agent设步数上限』,或 agent 出现无限循环/重复调用/原地打转时使用。把 agent 的运行当『受控进程』:监控步数上限·重复动作·状态无进展,触发即熔断并产出诊断。理论根基:LGD 三律(有籍·有证·有门禁)。触发词:agent卡死、无限循环、重复动作、跑飞、步数上限、loop guard、token烧光、失控循环。

下载量
281
点赞
71
价格
免费

技能文档

---
name: agent-loop-guard
display_name: 失控循环护栏(Agent Loop Guard)
display_name_en: "Agent Loop Guard"
description: "当用户说『agent卡死了』『一直在重复同样动作』『跑飞了烧光token』『怎么给agent设步数上限』,或 agent 出现无限循环/重复调用/原地打转时使用。把 agent 的运行当『受控进程』:监控步数上限·重复动作·状态无进展,触发即熔断并产出诊断。理论根基:LGD 三律(有籍·有证·有门禁)。触发词:agent卡死、无限循环、重复动作、跑飞、步数上限、loop guard、token烧光、失控循环。"
version: 1.0.1
agent_created: true
author: 诺声(Logos)@SynomosAI
license: MIT
license_scope: 代码(.py 文件)MIT;本 SKILL.md 与其中理论文本不在 MIT 覆盖范围内(见文末「License & attribution」)
allowed-tools: Read, Glob, Grep
category: AI工程方法
platforms: [windows, macos, linux]
read_when:
  - agent 疑似陷入无限循环或重复调用同一工具
  - token/费用异常飙升,怀疑 agent 跑飞
  - 想给 agent 设最大步数 / 无进展熔断
  - 用户抱怨「它一直在绕圈」
tags: [失控循环, loop guard, 步数上限, agent监控, token控制, 熔断, 可靠性, AI工程]
slug: agent-loop-guard
title: 失控循环护栏(Agent Loop Guard)
copyright: SynomosAI
description_zh: "当用户说『agent卡死了』『一直在重复同样动作』『跑飞了烧光token』『怎么给agent设步数上限』,或 agent 出现无限循环/重复调用/原地打转时使用。把 agent 的运行当『受控进程』:监控步数上限·重复动作·状态无进展,触发即熔断并产出诊断。理论根基:LGD 三律(有籍·有证·有门禁)。触发词:agent卡死、无限循环、重复动作、跑飞、步数上限、loop guard、token烧光、失控循环。"
description_en: "Guard against runaway agent loops: step limits, repeated-action detection, budget alerts and controlled-intervention patterns for stuck, looping or burning agents."
classification:
  skillhub: ["security-compliance"]
  iso_25010: ["Security"]
risk_tier: medium
risk_rationale: "门禁批量补丁默认 medium:调用 API/读写文件/本地执行,最小权限,密钥走 Secret;若实际涉对外代执行(push/发布/发送/上架)须人工复评,改 high。"
ai_protocol: true
spec: usk/1.0
interface:
  type: cli
  entry_point: scripts/loop_guard.py
  runtime: python3
  call_pattern: args
input_schema:
  - name: trace
    type: string
    description: 运行轨迹文本(内联)
    required: true
  - name: max_steps
    type: int
    description: 最大步数,默认30
    required: false
  - name: repeat
    type: int
    description: 重复容忍次数,默认3
    required: false
  - name: json
    type: bool
    description: JSON 输出
    required: false
output_schema:
  stdout: 循环检测结论与风险等级
  exit_code:
    type: integer
    description: "0=OK/PASS; 1=findings/warnings; 2=usage or argument error"
capabilities:
  - loop_detection
  - trace_analysis
  - safety
permissions:
  network: false
  filesystem: false
  subprocess: false
requirements:
  python_packages: []
  min_python: "3.8"
changelog: "1.0.1: Bilingual rewrite (full EN+ZH, English first); 1.0.0: initial upload (USK v3)"
---

> 凡自治之物 · LGD 治理学 · 创造术家族 | 评测协议:skill-quality-gate(外部公开评测门禁文档)

## English

### When to use
1. The user says the agent "froze", "ran away" or "burned through tokens".
2. The system detects repeated calls of the same action with no real progress.
3. The user asks how to set a "step limit" or suspects the flow is out of control.
4. Internal monitoring accumulates "no gate" risk (LGD state).

### Usage
- Core script: `loop_guard.py` (root of the skill dir).
- Key flags: `--check_loop` for loop detection; `--enable_firewall` for circuit-breaking.
- Config: env vars `LGD_MAX_STEPS=10` and `TOKEN_BUDGET_LIMIT` activate automated monitoring.

### Flow
1. **Trigger watch**: scan conversation/log streams for "stuck" signals.
2. **State capture**: current step count, token burn rate, action-sequence fingerprint.
3. **Rule match**: run loop-detection; test circuit-break conditions.
4. **Intervention**: on confirmed infinite loop or stall, fire a system-level circuit break.
5. **Diagnosis**: structured report with root cause, remaining-token estimate, fix suggestions.
6. **Recovery**: on user instruction, lift the limit and enter a new controlled monitoring cycle.

### Evidence & safety
- Evidence: TBD. Version: 1.0.1. Security: no independent scan (TBD).

## 中文

### 何时用
1. 当用户明确提及 Agent"卡死"、"跑飞"或"烧光 token"等异常状态时。
2. 当系统检测到 Agent 处于重复调用同一动作的循环,且任务执行无实质性进展时。
3. 当用户询问如何设置"步数上限"或质疑当前流程失控时。
4. 当内部监控算法识别到"无门禁"状态持续累积风险时。

### 用法
- **核心脚本**:直接执行 `loop_guard.py`(位于根目录)。
- **关键命令**:`--check_loop` 循环检测;`--enable_firewall` 开启熔断保护。
- **配置说明**:设定环境变量 `LGD_MAX_STEPS=10` 与 `TOKEN_BUDGET_LIMIT` 激活自动化监控。

### 流程
1. **触发监听**:在对话流或 Agent 日志中实时扫描"卡死"及异常行为信号。
2. **状态采集**:收集当前执行步骤、Token 消耗速率及动作序列指纹数据。
3. **规则比对**:运行检测算法,验证是否满足熔断条件。
4. **干预决策**:确认无限循环或状态停滞,立即触发系统级熔断。
5. **诊断生成**:输出根因分析、Token 剩余量评估及修复建议的结构化报告。
6. **执行恢复**:等待用户指令后解除限制,进入新一轮受控监控周期。

### 证据与安全声明
- 证据:TBD(暂无评测/徽章链接;产生后在此更新实际链接)
- 版本:1.0.1
- 安全:未做独立安全扫描(TBD),结论待补;补全前不作推荐背书。

使用说明

# agent-loop-guard · 失控循环护栏

[![LGD Powered](lgd-powered.png)](https://github.com/zhaoxinghua09-cell/lgd-theory)

**EN** — An agent run is a *controlled process*. Monitor step cap · repeated actions · no-progress, and trip a circuit breaker before it burns tokens spinning in place. Ships a zero-dependency `loop_guard.py`.

**中文** — 把 agent 运行当受控进程:监控步数上限·重复动作·状态无进展,触发即熔断并出诊断。零依赖 `loop_guard.py`。

## Why it beats "hope it terminates"

| Pain | This skill |
|---|---|
| Infinite A↔B loop | Repeated (tool,args) → trip |
| Re-clicking same tool | k identical calls → break |
| Token bill explodes | Step cap hard-stops |
| "Why did it loop?" | Trajectory + diagnosis saved |

## What's inside

- `SKILL.md` — 3-signal breaker + 3-step flow + 铁律
- `scripts/loop_guard.py` — zero-dependency CLI: read action trace, rate loop risk, suggest break + diagnosis

```bash
python scripts/loop_guard.py --trace trace.txt --max-steps 30 --repeat 3
python scripts/loop_guard.py --trace trace.txt --json
```

## Benchmark vs alternatives

| Tool | Gap this fills |
|---|---|
| Manual timeout | Detects *repetition*, not just wall-clock |
| "Just set a timeout" | No per-step loop diagnosis |
| Post-hoc log scan | Real-time gate, stop before burn |

Theoretical root: **LGD Three Laws** (registered · evidenced · gated). Pairs with `skill-quality-gate` and `context-engineering`.

---

© 2026  / SynomosAI·China (ORCID 0009-0001-0512-1237) · 代码 MIT · 理论文本保留所有权利

---

## License & attribution
**分层许可(务必并读;代码许可不覆盖文档与理论文本)**

- **代码**(本包 `.py` 文件):**MIT**
- **本 `README.md` / `SKILL.md` 及其中的理论文本、方法论与一切理论表述**:**不在 MIT 覆盖范围内**,保留所有权利(All rights reserved)

```
© 2026 SynomosAI · China. All rights reserved.
理论署名 (attribution) : LGD(Lifecycle Governance Doctrine / 全程治理论)— SynomosAI initiative
名称状态 (name status)  : "SynomosAI" — 未申请实体注册、未申请商标注册
                        (not a registered legal entity; no trademark registered)
生产参考部署 (production reference, self-reported) : 无(未声明外部生产参考部署)
                    ← 非认证、非背书、非监管认可(not a certification or endorsement)
代码许可 (code license) : 本包未附 LICENSE 文件(许可待定)
                    本文本与理论表述不在任何代码许可覆盖范围内
引用格式 (cite as)      : 本资产无 DOI
```
(上列为《LGD 对外表述规范》§3.2 统一块,**整体复制、未删改**;发布/重提前须照最新版本复核。)

如何安装此技能?

访问技能市场,点击「安装」按钮,按提示将技能包放入 AI 编程助手的 skills 目录即可。

浏览技能市场

支持平台:Qoder · QoderWork · Claude · Codex 等 AI 编程助手