Xpersona
E

Execution Loop

CLAWHUB · Unverified

Agent 执行循环控制。当 agent 提前停止、偏离任务、或在 headless 模式下需要执行控制时使用。不适用于工具重试(用 tool-governance)。参见 context-memory(阶段边界 handoff)、quality-verification(编辑后检查)。 Skill: Execution Loop Owner: lanyasheng Summary: Agent 执行循环控制。当 agent 提前停止、偏离任务、或在 headless 模式下需要执行控制时使用。不适用于工具重试(用 tool-governance)。参见 context-memory(阶段边界 handoff)、quality-verification(编辑后检查)。 Tags: agent-reliability:2.0.0, harness:2.0.0, latest:2.4.0 Version history: v2.4.0 | 2026-04-08T07:49:09.053Z | user Add settings.json configs, hookSpecificOutput formats, manual workarounds, failure modes v2.2.0 | 2026-04-08T

62
Rank
84
Safety
974
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 974 downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s179bk63dv96y90hw97xaay4fx83t7yr:execution-loop
  1. Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-lanyasheng-execution-loop/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

97,650 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: execution-loop
version: 2.0.0
description: Agent 执行循环控制。当 agent 提前停止、偏离任务、或在 headless 模式下需要执行控制时使用。不适用于工具重试(用 tool-governance)。参见 context-memory(阶段边界 handoff)、quality-verification(编辑后检查)。
license: MIT
triggers:
  - agent keeps stopping
  - ralph
  - persistent execution
  - 不要停
  - doubt gate
  - task completion
  - headless mode
  - agent drifts
  - adaptive complexity
author: OpenClaw Team
---

# Execution Loop

控制 agent 的执行循环:阻止提前停止、检测任务完成、防止任务漂移。

## When to Use

- Agent 只完成一部分就停了 → Ralph persistent loop
- Agent 说"可能"就声称完成 → Doubt gate
- 长 session 中偏离原始任务 → Drift re-anchoring
- 有明确任务清单 → Task completion verifier
- 用 `-p` headless 模式 → Headless execution control

## When NOT to Use

- 工具反复失败 → 用 `tool-governance`
- 上下文快用完 → 用 `context-memory`
- Session 挂死 → 用 `error-recovery`

---

## Patterns

| # | Pattern | Type | Description |
|---|---------|------|-------------|
| 1.1 | Ralph persistent loop | [script] | Stop hook 在 agent 尝试 end_turn 时检查 `ralph.json` 状态,未达 max 则 block 并注入续航指令。核心保障是 5 个安全阀(context >=95%、401/403、cancel TTL、闲置 2h、迭代上限),安全阀优先级高于一切 block 逻辑——context 即将溢出时 Ralph 必须让路,否则 session 崩溃。支持 shell/prompt/agent 三种 hook 实现,高价值任务用 agent-type 做语义级完成度验证。 → [详见](references/ralph.md) |
| 1.2 | Doubt gate | [script] | Strip 代码块和引用后扫描 agent 回复中的 hedging 词("likely""maybe""可能""应该是"等),命中则 block 并要求提供日志、测试结果等具体证据。用 `$TMPDIR/doubt-gate-<session>` 守卫文件做单轮去重——同一轮触发过一次后无条件放行,防止 agent 永远无法停止。与 Ralph 正交叠加:Ralph 管"别停",Doubt Gate 管"别含糊地停"。 → [详见](references/doubt-gate.md) |
| 1.3 | Adaptive complexity triage | [design] | 执行前根据文件数、安全/迁移关键词做 triage,将任务分为 Trivial→Express 到 Critical→Full+Gate 五档,每档启用不同的 hook 组合。关键约束:triage 不确定时默认 Standard 而非 Express,因为 Express 跳过验证——安全修复被误判为 Trivial 会不经验证直接提交。文件计数是极简启发式,生产环境建议用一次 Haiku 调用替代。 → [详见](references/adaptive-complexity.md) |
| 1.4 | Task completion verifier | [script] | Stop hook 读取 `.harness-tasks.json`(`{tasks: [{name, done}]}`),存在 `done: false` 条目则 block 并将未完成项注入 reason。与 Ralph 互补:Ralph 只做迭代计数,Task Completion 提供语义级的"为什么不能停"。确定性校验、零 API 成本,但 agent 可能只标记完成而实际没做好,需配合 quality-verification 二次验证。 → [详见](references/task-completion.md) |
| 1.5 | Drift re-anchoring | [script] | 每 N 轮(默认 10)将原始任务描述通过 `hookSpecificOutput.additionalContext` 重新注入对话,作为防漂移锚点。在 Ralph 持续执行中尤其必要——agent 不停意味着 drift 没有天然修正点,第 5 轮开始"顺手"重构不相关代码,第 10 轮已经在优化 CI 配置。与 Ralph、Task Completion 三者各管一个维度:别停 / 为什么不能停 / 别跑偏。 → [详见](references/drift-reanchor.md) |
| 1.6 | Headless execution control | [config] | `-p` 模式没有 Stop 事件循环,Ralph 不生效。替代方案是三维控制:`--max-turns` 限轮数,prompt 结构化(系统指令放前 ~2000 token 利用 prefix cache),budget 注入让 agent 感知资源约束做优先级决策。Pipeline 场景每阶段告知当前位置和剩余预算。 → [详见](references/headless-config.md) |
| 1.7 | Iteration-aware messaging | [design] | Ralph 的 block 消息如果每次相同,agent 会进入 compliance mode——表面继续实际反复生成"我已完成大部分"的变体。解法是按迭代阶段动态切换消息角度:早期(1-5)方向引导,中期(6-15)反合理化要求逐条对照,后期(16-30)反循环鼓励换方法,收尾(30+)切换优先级做 graceful handoff。基于 prompt-hardening P5 反推理阻断原则。 → [详见](references/iteration-aware-messaging.md) |

扩展模式(跨 turn 状态对象、多层停止条件、三维预算约束、流式工具执行)→ [详见](referen

_meta.json

{
  "ownerId": "kn7ecyzc2xkecxz46jd7gvwxgs822fyc",
  "slug": "execution-loop",
  "version": "2.4.0",
  "publishedAt": 1775634549053
}

references/adaptive-complexity.md

# Pattern 1.3: Adaptive Complexity Scoring(任务复杂度自适应)

## 问题

所有任务使用相同的 harness 配置——简单的拼写修复和复杂的架构重构都走同样的 Ralph + Handoff + Verification 全流程。简单任务 overhead 太高,复杂任务可能保障不足。

来源:`rubenzarroca/sdd-autopilot` — 8 阶段 pipeline 的复杂度分类

## 原理

在执行前做 triage——评估任务复杂度,自动选择执行模式。

### 复杂度分级

| 等级 | 判断标准 | 执行模式 |
|------|---------|---------|
| Trivial | 单文件、< 10 行改动、无依赖 | Express(跳过 plan/verify) |
| Low | 单文件、可能需要测试更新 | Light(plan + implement) |
| Medium | 2-5 文件、涉及跨模块修改 | Standard(plan + implement + verify) |
| High | 5+ 文件、架构变更、新 API | Full(plan + implement + verify + review) |
| Critical | 安全修复、数据迁移、生产变更 | Full + Agent-type 验证门禁(Pattern 1.1 模式 C) |

### 执行模式映射

| 模式 | 启用的 Pattern |
|------|---------------|
| Express | 仅 Pattern 6.5(原子写入) |
| Light | + Pattern 2.1(工具错误升级) |
| Standard | + Pattern 1.1(Ralph)+ Pattern 3.5(Context 估算) |
| Full | + Pattern 3.1(Handoff)+ Pattern 6.3(Hook Bracket)+ Pattern 6.1(Post-Edit 诊断) |
| Full+Gate | + Pattern 1.1 模式 C(Agent-type 验证) + Pattern 2.5(Scoped Hooks) |

## 实现

在 session 启动时(UserPromptSubmit hook + `once: true`)做 triage:

```bash
# 分析 prompt 中的文件数、改动范围、关键词
FILES_MENTIONED=$(echo "$PROMPT" | grep -oE '[a-zA-Z_/]+\.(py|ts|rs|go|cpp|java)' | wc -l)
HAS_SECURITY=$(echo "$PROMPT" | grep -qiE 'security|vulnerability|CVE|auth|密钥|安全' && echo 1 || echo 0)
HAS_MIGRATION=$(echo "$PROMPT" | grep -qiE 'migration|migrate|数据迁移' && echo 1 || echo 0)

if [ "$HAS_SECURITY" = "1" ] || [ "$HAS_MIGRATION" = "1" ]; then
  LEVEL="critical"
elif [ "$FILES_MENTIONED" -gt 5 ]; then
  LEVEL="high"
elif [ "$FILES_MENTIONED" -gt 1 ]; then
  LEVEL="medium"
elif [ "$FILES_MENTIONED" -eq 1 ]; then
  LEVEL="low"
else
  LEVEL="trivial"
fi
```

## 安全规则

**MUST:当 triage 不确定时,默认 Standard,NEVER 默认 Express。** Express 跳过验证——如果一个安全修复被误判为 Trivial,agent 会不经验证直接提交。

**MUST:Express 模式不应用于任何写入生产代码的操作。** Express 适合只读分析、文档更新、配置微调。

## 已知局限

文件计数 triage 是极简启发式。已知失败场景:
- "Fix the auth bug" 提到 0 个文件但可能涉及 10+ 文件
- 带连字符/数字的文件名(`my-component.ts`, `v2.config.js`)匹配不到
- 上下文信息(是否涉及安全、数据库、支付)比文件数更重要

**生产建议**:用 LLM triage(一次 Haiku 调用评估复杂度)替代 regex 启发式。

## Tradeoff

- Triage 本身会消耗一些 token(但远少于在简单任务上运行全流程的 overhead)
- 误判复杂度会导致过度/不足保障——文件计数只是起点,需要持续优化
- 历史数据可以提升 triage 准确度(追踪实际 vs 预估复杂度)

references/cancel-ttl.md

# Pattern 1.1-sub: Cancel Signal with TTL

## 问题

用户发送取消信号后,如果新 session 复用了同一个 session-id,旧的取消信号会错误地阻止新 session。

## 原理

取消信号带 30 秒过期时间。过期后自动忽略。来自 OMC 的 `CANCEL_SIGNAL_TTL_MS = 30000`。

## 信号格式

```json
{
  "requested_at": "2026-04-05T10:30:00Z",
  "expires_at": "2026-04-05T10:30:30Z",
  "reason": "user_abort"
}
```

## 使用

```bash
# 发送取消信号
scripts/ralph-cancel.sh <session-id> [reason]
# 创建 sessions/<session-id>/cancel.json(30 秒后过期)
```

## Ralph stop hook 的检查逻辑

- 存在且未过期 → 停止 ralph,设置 `deactivation_reason: "cancelled"`,允许 agent 退出
- 存在但已过期 → 删除信号文件,继续 ralph 循环
- 不存在 → 继续 ralph 循环

## 为什么是 30 秒

OMC 选择 30 秒是因为:
- 足够覆盖 Stop hook 的检查周期(通常 1-5 秒内触发)
- 不会太长以至于影响后续 session
- 用户手动取消后 30 秒内必然会触发至少一次 Stop hook 检查

references/doubt-gate.md

# Pattern 1.2: Doubt Gate(投机检测断路器)

## 问题

Agent 声称任务完成,但回答中包含投机性语言——"可能是"、"我认为"、"大概"——没有提供具体证据。这和 Pattern 2.2(权限否决追踪)解决的是相反的问题:Pattern 2.2 处理 agent 被拒绝后换表述重试,Doubt Gate 处理 agent 以不确定的态度"完成"任务。

来源:`johnlindquist/plugin-doubt-gate`

## 原理

Stop hook 在 agent 尝试结束时,strip 代码块和引用块后扫描剩余文本中的 hedging 关键词("likely"、"maybe"、"might"、"probably"、"not sure"、"I think"、"I believe"、"可能"、"大概"、"也许"、"应该是")。如果匹配到,返回 `{"decision":"block"}`,强制 agent 回到活跃状态,必须提供具体证据(日志、断言、测试运行结果)才能再次尝试停止。

### 防止无限循环

设置 `stop_hook_active` 守卫标志。如果本轮已经触发过一次 doubt gate,下次 stop 无条件放行。防止 agent 永远无法停止。

## 实现

```json
{
  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "bash scripts/doubt-gate.sh"
      }]
    }]
  }
}
```

```bash
# doubt-gate.sh — 核心逻辑
INPUT=$(cat)
LAST_MSG=$(echo "$INPUT" | jq -r '.last_assistant_message // ""')
# Strip code blocks and blockquotes
PROSE=$(echo "$LAST_MSG" | sed '/^```/,/^```/d; /^>/d')
# Check for hedging keywords
if echo "$PROSE" | grep -qiE 'likely|maybe|might|probably|not sure|I think|I believe|可能|大概|也许|应该是'; then
  # Check guard: already fired this turn?
  GUARD_FILE="$TMPDIR/doubt-gate-${SESSION_ID}"
  if [ -f "$GUARD_FILE" ]; then
    rm -f "$GUARD_FILE"
    echo '{"continue":true}'
  else
    touch "$GUARD_FILE"
    echo '{"decision":"block","reason":"Your response contains speculative language. Provide concrete evidence (logs, test results, or code verification) before completing."}'
  fi
else
  echo '{"continue":true}'
fi
```

## 与 Ralph 的关系

Ralph 阻止 agent 过早停止(基于迭代计数)。Doubt Gate 阻止 agent 以不确定的方式停止(基于内容分析)。两者可叠加:Ralph 在前(决定是否继续迭代),Doubt Gate 在后(即使 Ralph 允许停止,如果内容有投机语言也会 block)。

## Tradeoff

- 可能误报——agent 在解释可能性时使用"可能"是合理的
- 需要 strip 代码块,否则代码注释中的 hedging 词会误触发
- 守卫标志防止无限循环,但意味着 agent 第二次尝试时即使仍然投机也会被放行

Sponsored

Ads related to Execution Loop and adjacent AI workflows.