⚡ PromptLoot

Home › AI Agents

Which Agent Layer Is Failing? Prompt, Context, Loop or Harness

A diagnostic prompt that finds which layer of your AI agent is actually broken (the prompt, the context, the loop, or the harness) before you start rewriting the prompt.

Added

You are debugging an AI agent that isn't doing what I want. Before anyone rewrites the prompt, find which layer is failing. I'll paste: what I asked for, what the agent did, the system prompt or rules files, and a transcript or log of the run (tool calls included if I have them).

Treat the agent as four layers:
1. Prompt: the instructions themselves (system prompt, CLAUDE.md, AGENTS.md, SKILL.md, the task message).
2. Context: what the model could actually see when it acted (files, retrieved docs, memory, earlier turns, tool results), and what got cut off or summarized away.
3. Loop: how the agent plans, calls tools, checks results, retries, and decides it is done.
4. Harness: the code and settings around the model: tool definitions, permissions, hooks, timeouts, step limits, model choice, and how output is parsed or verified.

## Step 1: Restate the failure
One sentence on what should have happened and one on what did. Name the first moment the run went wrong, quoting the transcript line.

## Step 2: Test each layer
For each layer, answer with evidence from what I pasted:
- Prompt: Is the instruction that was broken actually written down? Is it clear, or does another line contradict it? Is it buried in a long file?
- Context: Did the model have the information it needed at that moment? Was a key file, doc, or earlier decision missing, stale, or truncated? Was there too much irrelevant context?
- Loop: Did it skip a check, stop early, retry the same failing action, or mark itself done without verifying?
- Harness: Did a tool return an error, a wrong format, or nothing? Was a permission, timeout, or step limit hit? Is the model too weak or too strong for this job? Did a parser drop part of the output?

Mark each layer: likely cause, possible, or ruled out.

## Step 3: Verdict
- The single most likely failing layer and why, in 3 sentences or fewer.
- The smallest fix at that layer. If the fix belongs in the harness (a hook, a test, a permission, a verify step), say so instead of adding more prompt text. Prompt pleading ("ALWAYS", "NEVER", all caps) doesn't fix context, loop, or harness problems.
- One cheap experiment that would confirm the diagnosis before I change anything, such as re-running with the missing file pasted in, or with a step limit raised.

## Step 4: Guard against repeats
One test, check, or eval I can add so this failure gets caught next time.

Rules: quote the transcript instead of guessing. If the logs don't show enough to decide, say which log or setting you'd need to see.

How to use it

  1. Click Copy template.
  2. Paste into ChatGPT, Claude, Grok, Cursor, or your agent framework.
  3. Replace the [BRACKETED] parts with your details.

Pairs well with: Lean CLAUDE.md: Trim a Bloated Rules File to 40 Lines

Sponsor this page · Reach builders who use AI daily. Get details

FAQ

Why does my AI agent ignore its instructions?

Often the instruction isn't the problem. The model may not have had the right files in context, the loop may have skipped a check, or a tool may have failed silently. Find the failing layer first, then fix that layer instead of adding more prompt text.

What are the layers of an AI agent?

A useful split is four layers: the prompt (instructions), the context (what the model can see at each step), the loop (plan, act, check, repeat), and the harness (tools, permissions, hooks, limits, model choice, and output parsing).

Should I fix agent bugs by rewriting the prompt?

Only when the prompt layer is the cause. If the agent lacked information, add it to context; if it stopped without checking, add a verify step to the loop; if a tool failed, fix the harness. Rewriting the prompt for those just makes it longer.

Does this work for Claude Code, Cursor, and Codex?

Yes. Paste the rules file, your request, and the session transcript from any coding agent or agent framework. The same four layers apply to custom agents built on an SDK.

Get 3 new templates every week

Free. Unsubscribe anytime.

Related templates

AI Agent Run Postmortem Prompt (Find the Real Fix)

When an AI agent does something wrong, reconstruct what happened from logs and decide the right fix: a prompt edit, a rules-file change, a test, or a hard permission limit.

AI Agent Harness Starter Pack: Rules, Hooks, Status & Verify

Set up a simple agent harness: a short rules file, a status file the agent keeps current, a verify command, and hooks that block 'done' until checks pass.

System Prompt Regression Test Set (Evals for Prompts & Skills)

Edit your system prompt, CLAUDE.md, or agent skill without fear: build a small eval set, rerun it after every change, and catch regressions before users do.

Browse all AI Agents templates

New on PromptLoot

Check Current Docs First: Stop Agents Using Outdated APIs

Rules that make Claude Code, Cursor, and Codex check your installed versions and current docs before calling any API, cite the version, and flag deprecations.

Minimal Diff Rules: Stop AI Agents Rewriting Unrelated Code

Rules for Claude Code, Cursor, and Codex: change only what you asked, no drive-by renames, refactors, or reformatting, and list every changed file.
PromptLoot Pro Pack · 200+ advanced templates, agent workflows, and Cursor rules bundles. Coming soon