PromptABCD
FeaturesLearnHow it worksUse casesFAQGuideBlogContext Blocks
Sign inGet started free
Sign inSign up
PromptABCD

A calm home for your best AI prompts. Save them once, find them in seconds, reuse them forever.

Product

  • Features
  • Chrome Extension
  • Free Courses
  • How it works
  • Use cases
  • Blog
  • Context Blocks
  • Export Anywhere
  • FAQ

Resources

  • User guide
  • Learn prompting
  • Sign in
  • Get started free

© 2026 PromptABCD. All rights reserved.

Privacy PolicyTerms and Conditions
Home/Blog/Agent Loop Engineering/Rewriting the Goal Mid-Loop: Self-Reprompting
Agent Loop Engineering

Rewriting the Goal Mid-Loop: Self-Reprompting

An agent chasing a goal it had misread wasted 20 steps before failing. Agent self-reprompting lets a loop rewrite its own objective as it learns. Here's how to build it without letting it drift.

August 25, 2026·9 min read
ShareShare
⚡Featured Prompt— copy and use right now
def agent_loop(state, max_steps=15):
    original_goal = state.goal
    working_goal = state.goal
    for step in range(max_steps):
        action = model_decide(state, tools + [reframe_goal])
        if action.name == "reframe_goal":
            proposed = action.args["new_goal"]
            if consistent_with_original(proposed, original_goal):
                working_goal = proposed          # accept refinement
                state = set_goal(state, working_goal)
            else:
                state = add_note(state, "Reframe rejected: drifts from "
                                 "the user's actual request.")
            continue
        if action.name == "finish":
            return action.args["answer"]
        state = update_state(state, action, run_tool(action))
    return force_answer(state)

An agent I watched spent twenty steps diligently pursuing a goal it had misunderstood from the first message. The user asked it to "find why the report numbers don't match," and the agent locked onto "find the report" — it spent the whole run hunting for a document when the actual task was reconciling a discrepancy. It failed twenty steps later, having never questioned its own framing. The fix wasn't a better initial prompt. It was agent self-reprompting: letting the loop rewrite its own goal as it learns what the task actually is.

This guide shows how to build self-reprompting that helps an agent correct a misread or refine a vague goal — without letting it quietly drift away from what the user actually wanted.

Quick-Start (Copy This Right Now)

Here's a loop that can revise its own working goal, with a guard against drift.

hljs python
[object Object], ,[object Object],(,[object Object],):
    original_goal = state.goal
    working_goal = state.goal
    ,[object Object], step ,[object Object], ,[object Object],(max_steps):
        action = model_decide(state, tools + [reframe_goal])
        ,[object Object], action.name == ,[object Object],:
            proposed = action.args[,[object Object],]
            ,[object Object], consistent_with_original(proposed, original_goal):
                working_goal = proposed          ,[object Object],
                state = set_goal(state, working_goal)
            ,[object Object],:
                state = add_note(state, ,[object Object],
                                 ,[object Object],)
            ,[object Object],
        ,[object Object], action.name == ,[object Object],:
            ,[object Object], action.args[,[object Object],]
        state = update_state(state, action, run_tool(action))
    ,[object Object], force_answer(state)

What this does: It gives the agent a

reframe_goal
action to rewrite its working goal, but checks each proposed rewrite against the original user request and rejects rewrites that drift — so agent self-reprompting sharpens the goal without letting the agent wander off into a different task.

Understanding the Variables

The central tension in self-reprompting is refinement versus drift, and everything hinges on telling them apart.

Refinement is when the agent makes the goal more accurate to what the user meant. "Find the report" becoming "reconcile the discrepancy between the two reports' totals" is a refinement — it's closer to the user's real intent, corrected by what the agent learned. This is the behavior you want.

Drift is when the agent changes the goal to something easier or different from what the user asked. "Reconcile the discrepancy" quietly becoming "summarize the first report" is drift — the agent has swapped the hard real task for an easier adjacent one. This is the behavior that makes self-reprompting dangerous.

The guard between them is a consistency check against the original goal. The original user request is the anchor; every reframe must stay faithful to it. Without this anchor, self-reprompting degenerates into an agent talking itself into whatever it feels like doing — which is worse than a fixed goal, because at least a fixed goal stays honest about the task.

Why allow reframing at all, given the drift risk? Because the alternative — a permanently fixed goal — has its own serious failure mode, the one from the opening: an agent that misreads the task at step one and then pursues the misreading with perfect diligence to a useless conclusion. A fixed goal can't self-correct a bad initial framing, and initial framings are wrong more often than people expect, because the agent commits to an interpretation before it has done any of the work that would reveal the interpretation is off. Agent self-reprompting exists to fix exactly this: it lets the agent notice, midway, that it misunderstood, and correct course. The design challenge is capturing that upside without opening the door to drift, which is why the whole technique lives or dies on the faithfulness guard.

⚡ Pro tip: Treat the first reframe in a run as the most valuable and the most suspect. Early reframes often catch a genuine initial misread — high value. But they also happen before the agent has gathered much evidence, so they're the ones most likely to be a guess dressed as a correction. Require early reframes to cite the specific finding that justifies them, so a step-two reframe has to point at real evidence rather than a hunch.

⚡ Pro tip: Always keep the original user goal immutable and separate from the working goal. The working goal can evolve; the original never changes and is what every reframe is checked against. The moment you let the agent overwrite the original, you've lost your anchor and drift becomes undetectable — there's nothing left to measure faithfulness against.

Step-by-Step: Building Safe Self-Reprompting

Start by separating the two goals in your state — the immutable original and the mutable working goal — and make the consistency check the gate between them.

hljs python
[object Object], ,[object Object],(,[object Object],):
    ,[object Object],
    verdict = model_judge(
        ,[object Object],
        ,[object Object],
        ,[object Object],
        ,[object Object],
        ,[object Object],
    )
    ,[object Object], verdict.startswith(,[object Object],)

What this does: It asks a model to judge whether a proposed goal rewrite still serves the user's real intent rather than merely resembling it, gating reframes on faithfulness so refinements pass and drift gets caught.

Next, give the agent clear triggers for when reframing is appropriate, so it reframes for the right reasons rather than whenever it's frustrated.

hljs text
Reframe your goal only when you discover concrete evidence that your
current framing is wrong - a finding that contradicts your assumption,
or a clarification of what the user actually needs. Do NOT reframe
because the task is hard. Difficulty is not a reason to change the goal.

What this does: It restricts reframing to evidence-driven corrections and explicitly forbids the most common abuse — swapping to an easier goal when the real one gets hard — so self-reprompting stays a correction tool, not an escape hatch.

Finally, log every reframe with its before, after, and the consistency verdict, so you can audit whether the agent's self-reprompting is genuinely helping.

⚡ Pro tip: Show the user when the agent reframed, not just the final answer. "I interpreted your request as reconciling the two totals rather than finding a single report — here's what I found" lets the user catch a wrong reframe immediately. A silent reframe that was subtly wrong produces a confident answer to the wrong question, which is the exact failure self-reprompting is supposed to prevent.

Pro-Level Variations

For a research agent, allow the working goal to accumulate refinements as it learns — each new finding can sharpen the question — but pin every refinement to the original research intent so a long investigation doesn't slowly become a different investigation.

For a task-automation agent, be stricter: reframing should be rare and always surfaced to the user, because an automation agent that quietly changes its own goal can take real actions toward the wrong objective. A operations engineer I know allows reframing only as a suggestion the user must confirm, never an automatic switch.

For a debugging agent, self-reprompting is especially valuable — the initial framing of a bug is often wrong, and letting the agent revise "fix the timeout" into "fix the connection leak causing the timeout" as it learns is exactly the adaptivity you want, as long as it stays tied to resolving the original symptom.

That debugging example points at the healthiest pattern for agent self-reprompting generally: reframes that add specificity while preserving intent. "Fix the timeout" and "fix the connection leak causing the timeout" serve the identical user goal — the timeout stops happening — but the second is sharper, informed by what the agent learned. Contrast that with "fix the timeout" becoming "document the timeout behavior," which preserves the topic but abandons the intent; the user wanted it fixed, not described. The faithfulness check has to be tuned to catch that second kind while waving through the first, and the clearest test is asking whether the reframe would still satisfy the user if they saw it. A sharper version of their request satisfies them; a sideways swap to an easier adjacent task does not.

⚡ Pro tip: When tuning the faithfulness judge, feed it your real rejected and accepted reframes as few-shot examples rather than relying on an abstract "faithful or drift" instruction. The line between refinement and drift is genuinely subtle, and a handful of concrete examples from your own agent's history calibrates the judge far better than any general definition. Your past drift cases are the best training data for catching the next one.

Troubleshooting Common Issues

If the agent reframes too readily and drifts, your consistency check is too lenient or your trigger criteria are too vague. Tighten the faithfulness judgment and make the triggers concrete — reframe only on specific contradicting evidence, never on difficulty.

If the agent never reframes even when clearly pursuing a misread goal, the trigger is too abstract or the reframe action isn't salient enough. Give concrete examples of when to reframe, and make sure the action is offered every step.

If reframes are faithful but the user is still surprised by the result, you're not surfacing the reframe. Always show the user how the agent interpreted and re-interpreted the goal, so a subtle drift you didn't catch gets caught by the person who actually knows their intent.

⚠️ Common mistake: Letting the agent reframe without anchoring to the original request. Self-reprompting without a fixed anchor is just an agent rationalizing its way to whatever task it prefers, and it drifts a little more with each reframe until the final answer addresses a question the user never asked. The immutable original goal and the faithfulness check are not optional extras — they're the entire thing that separates useful self-correction from confident wandering.

Your Turn

Separate the immutable original goal from the mutable working goal, gate every reframe on a faithfulness check against the original, restrict reframing to evidence-driven corrections, and surface reframes to the user. Start strict — reject more reframes than you accept — and loosen only once you trust the guard.

The faithfulness-check prompt and the reframe triggers take real tuning to balance correction against drift. Once you've got wording that catches drift while allowing genuine refinement, keep it. A prompt library like PromptABCD is a natural home for your self-reprompting guards and triggers, so your next agent can adapt its goal safely instead of either rigidly pursuing a misread or wandering off task.

self-repromptingagent loopsgoal managementadaptationcontrol flow

Save the prompts from this post

PromptABCD is a free prompt manager. Paste, organize, and reuse your best AI prompts — no more hunting through chat history.

Start free →
← PreviousBuilding a Loop That Asks for Help When Stuck
Share this post:
ShareShare