Loop Engineering logo

Loop Engineering

CommunityPopular
huytieu
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).

Overview

Publisherhuytieu
RepositoryCOG-second-brain
Skill nameloop-engineering
Stars
1.2K
Forks
138
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by huytieu on GitHub. Read the source before you install it.

Installation

Install the Loop Engineering AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/huytieu/COG-second-brain.git /tmp/COG-second-brain
mkdir -p .claude/skills
cp -r /tmp/COG-second-brain/skills/loop-engineering .claude/skills/loop-engineering
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Loop Engineering in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Loop Engineering on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Loop Engineering is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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.

Frequently asked questions

What does the Loop Engineering AI skill do?

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).

Why use Loop Engineering on TypingMind?

Because you install it once and use it with any model. Loop Engineering is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Loop Engineering in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/huytieu/COG-second-brain/tree/main/skills/loop-engineering. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Loop Engineering?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Loop Engineering?

As many as you like. As long as a model supports skills, you can use Loop Engineering with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Loop Engineering AI skill free?

Yes. It is published on GitHub by huytieu under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇