Plan-execute-verify
Plan-execute-verify (PEV) adds a verification step after each execution. After executing a plan step, the agent verifies the result meets quality standards, retrying or adjusting if verification fails. This catches errors early instead of at the end.
Plan → execute → verify cycle
It adds cost per step, but catching errors early is far cheaper than discovering a wrong answer at the end and re-running everything. Use PEV for high-stakes workflows where correctness matters more than speed.
class PEVAgent:
def solve(self, goal, max_retries=2):
plan = self.plan(goal)
results = []
for step in plan:
retry_count = 0
while retry_count <= max_retries:
result = self.execute_step(step)
verification = self.verify_step(step, result)
if verification["success"]:
results.append({"step": step, "status": "verified"})
break
retry_count += 1
else:
results.append({"step": step, "status": "failed"})
return results
def verify_step(self, step, result):
prompt = f"""Verify this step result:
Step: {step}
Result: {result}
Is the result correct and complete? (yes/no)
Explain any issues found."""
response = self.llm.generate(prompt).content
return {"success": "yes" in response.lower(), "details": response}PEVAgent with plan, execute, and verify phases.
Quiz: Quiz
Loading practice…
Ordering exercise: Order the pev cycle
Loading practice…
Flashcards: Flashcards
Loading practice…
With verification loops in place, your agents catch errors at each step instead of at the end. Next, we look at blackboard systems where multiple agents collaborate through shared memory.