跳到正文
FunCoding

搜索

搜索文档、Skill 和 MCP

loop-engineering

Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns. Invoke when designing or debugging a skill that iterates (search-verify-retry, scan-until-dry, fetch-retry-gate).

代码质量与审查1.3kskills/loop-engineering/SKILL.md

安装

把这段话发给 Claude Code、Codex 或 Cursor。智能体会先检查安全性,你确认后才安装。

读取 https://funcoding.ai/skills/huytieu/cog-second-brain/loop-engineering/install.md ,按里面的步骤帮我安装这个 Skill。

SKILL.md

COG Loop Engineering

TL;DR: Some COG skills are not one-shot prompts. They are loops: act, observe, verify, decide whether to continue. This skill is the shared vocabulary those skills use. The iron rule: trust deterministic checks, never the agent's own "looks done" self-report. Every loop must declare its verifier, its stopping conditions, and which pattern it follows.

This is a reference and design aid, not a content-generating workflow. Skills that loop (daily-brief, knowledge-consolidation, url-dump, weekly-checkin, and research/triage skills like auto-research and scout) link here instead of restating the rules. Invoke it directly when you are building or fixing an iterative skill.

Why loops

A chain runs fixed steps: A then B then C. A loop is dynamic: the agent takes an action, reads real feedback (a fetched page, a date stamp, a file count), reasons about it, and repeats until a goal is met or a stop condition fires. Most knowledge-work that "keeps going until good enough" is a loop, and COG benefits from naming the loop explicitly rather than hoping a single prompt nails it.

The COG loop

   ┌──────────────────────────────────────────────┐
   │  1. Gather    pull context (vault + sources)   │
   │  2. Act       one step: search / fetch / scan  │
   │  3. Observe   read the real result             │
   │  4. Verify    run the deterministic check      │
   │  5. Update    write progress to a vault file   │
   │  6. Decide    continue?  → loop                │
   │               stop?      → finish + report     │
   └──────────────────────────────────────────────┘

Step 4 is the load-bearing one. A loop without a verifier is just a chain that repeats.

Termination conditions (use layers, never one)

A robust loop needs several exits so it always halts:

ExitWhat it isExample
Deterministic verifierA mechanical pass/fail that confirms the goal"Publication date is within 7 days"
Hard iteration capMax passes, no matter what"Stop after 5 searches per topic"
Budget guardMax time / tool calls / tokens"Stop after 20 fetches total"
No-progress detectionRecent passes changed nothing"2 searches in a row found nothing new"
Human escalationHand a stuck loop back to the user"Asked twice, still unclear: ask the user"

Pick the verifier plus at least one safety exit (cap or budget) for every loop. No-progress detection is what stops the quiet infinite loops that a cap alone misses.

Verification first (COG's rule, applied to loops)

COG is verification-first: no hallucinations, sources required. Inside a loop that means:

  • Prefer mechanical checks. A date comparison, a source count, a "required field is non-empty", a "file marked consolidated" check cannot be gamed and cannot be hallucinated.
  • Reserve judgment-based checks for the genuinely unquantifiable (is this theme actually new? is this summary faithful?). When you must use judgment, state confidence and link evidence.
  • Never accept the agent's own "I think this is complete." That is the single most common way loops produce confident garbage.

In-loop context management

Long loops fill the window with old tool output and start to drift ("context rot"). Counter it:

  • Externalize state to the vault. Write progress to the output file as you go. The vault file is the memory; the conversation is scratch.
  • Compact and prune. Summarize finished passes into a line or two. Drop raw page text once you have extracted what you need.
  • Isolate sub-agents. In agent_mode: team, give each worker only the slice it needs and take back only its conclusion, so one subtask runs in a clean window. Never paste one worker's raw output into the next worker's prompt.

Named patterns

PatternShapeWhere COG uses it
Act-observe (ReAct)reason → act → observe → repeatbase of every COG loop
Reflect-retry (Reflexion)on failure, write the lesson, retry differentlyurl-dump / scout fetch retries, daily-brief re-search
Plan-execute-verifyplan steps, run them, verify eachknowledge-consolidation passes
Evaluator-optimizergenerate, score against criteria, repeat until it passesdaily-brief item verify, url-dump quality gate
Orchestrator-workerssplit into subtasks, run in fresh windows, synthesizeteam-mode scans, auto-research threads, team-brief
Loop-until-drykeep going until K passes in a row surface nothing newknowledge-consolidation theme extraction
Human-in-the-loopescalate or ask when the loop is stuck or the call is the user'sweekly-checkin reflection, onboarding

Failure modes and fixes

FailureFix
Context overflow / driftcompact, prune, externalize to vault, isolate sub-agents
Silent infinite loopno-progress detection plus a hard cap
Hallucinated successtrust the deterministic verifier, never self-report
Compounding errorsverify early and every pass, not only at the end
Cost blowupbudget guard, and stop at "good enough", not "perfect"
Goal driftkeep the goal and stop conditions written at the top of the loop's state

How skills use this

A skill's ## Loop Engineering section should be short and concrete. It names:

  1. The loop in one or two lines (what repeats).
  2. The verifier (the mechanical pass/fail).
  3. The termination conditions (verifier plus safety exits).
  4. The pattern(s) from the table above.

It does not restate this skill. It points here.

相似的 Skill

claude-api
anthropics/skills180k

claude-api

Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).

代码质量与审查

ponytail-review
DietrichGebert/ponytail158k

ponytail-review

Quality review of a change: is the logic right, is it safe, does it hold under real load, is risky code tested, is it fast enough, and is every line needed. Reads the connected code, not only the diff. Each finding is explained in plain English. Use for "review this", "code review", "review the last commit", "review my PR", "is this over-engineered", /ponytail-review.

代码质量与审查

code-review-and-quality
addyosmani/agent-skills103k

code-review-and-quality

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

代码质量与审查

documentation-and-adrs
addyosmani/agent-skills103k

documentation-and-adrs

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

代码质量与审查

code-simplification
addyosmani/agent-skills103k

code-simplification

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

代码质量与审查

understand
Egonex-AI/Understand-Anything86k

understand

Analyze a codebase to produce an interactive knowledge graph for understanding architecture, components, and relationships

代码质量与审查