PlannerGeneratorEvaluator (PGE) runs three agents. A planner expands your short prompt into a plan of numbered steps and a set of scoring criteria. For each step, a generator does the work and a separate evaluator scores it against the criteria. A step that scores below a threshold goes back to the generator with the evaluator’s feedback, up to a retry limit. Keeping the maker and the grader apart stops the generator from grading its own work.
All three agents share one Markdown file on disk. Every call gets the whole file, and every reply is appended to it, so the file is a complete record of the run.
Reference: PlannerGeneratorEvaluator.
How one step runs
1. Run the harness
model_name sets the model for all three agents. max_steps caps how many plan steps run, and max_retries_per_step caps the retries after a failed evaluation.
output_type="dict" returns the whole conversation as a list of messages:
The harness reads the number of steps from the plan (the highest
Step N) and runs only the first max_steps of them. With max_steps=2, a plan of five steps stops after step 2, so the output covers only part of the plan. Raise max_steps (default 10) for a complete result.2. Read the result
Afterrun(), harness.last_result holds the run’s numbers, the plan and one log per step. output_path is the shared file.
'feeding schedule clarity': 9.0. A step that needed a retry has one set of scores per attempt. In one run, step 2 first scored 1.0 on coverage of common mistakes, then passed on its retry with 7.0. The file starts with a # PGE Harness Shared State header and your prompt, followed by one timestamped section per agent call: [PLANNER OUTPUT], [STEP 1 CONTRACT PROPOSAL], [STEP 1 CONTRACT REVIEW], [STEP 1 WORK LOG], [STEP 1 EVALUATION], and a final [HARNESS SUMMARY].
The finished work is in the generator’s work logs: the [Step N Output ...] messages, or the WORK LOG sections of the file. Each run() rewrites the file and clears the conversation, so one harness can run many prompts. The file name includes the harness id; pass shared_state_path to choose it.
3. Use a stronger grader and allow more retries
Each role can have its own model:planner_model_name, generator_model_name and evaluator_model_name override model_name. A stronger evaluator gives stricter, more useful feedback. Here output_type="final" returns only the last message, the closing summary.
PGE Harness completed: 0/2 steps passed, 6 total retries, 98.6s elapsed. Shared state: .... In that run, the gpt-5.4 evaluator held both steps to its thresholds. Step 1 failed on worked example correctness (2.0, needs 8.0), fixed it on the retry, then fell short on brevity and focus (6.0 and 4.0, needs 7.0). After its retries ran out, the harness moved on. A step that fails every attempt is logged with passed=False, and the run still completes.
How a step passes
The evaluator’s reply is read in this order:- Score table rows like
| clarity | 7 | 8 | FAIL |. Each score is compared with the threshold in its own row. The built-in evaluator prompt asks for this table, so this is the usual case. - Inline scores like
Clarity: 7/10. Each is compared with the threshold the planner set for that criterion, then withdefault_thresholds, then with 6.0. - No scores. An
Overall Status: PASSorFAILline decides; with neither, the step passes.
default_thresholds={"accuracy": 8.0} only takes effect when the evaluator writes inline scores and the criterion is named exactly accuracy (names are compared in lowercase).
total_retries counts every failed evaluation, including the last one on a step that runs out of retries. A step that fails three times with max_retries_per_step=2 adds 3 and moves on.
4. Give the agents tools
Pass your ownplanner_agent, generator_agent or evaluator_agent to add tools, MCP servers or any other Agent setting. A custom agent keeps its own model and system prompt; the matching *_model_name and *_system_prompt arguments are not applied to it. Here the generator saves its work to files and the evaluator can open them.
max_loops=2 gives each agent room to call its tool and then answer, and output_type="final" makes each run return only that answer. In our run both steps passed and the folder held four files. The generator is also asked to write each step’s contract, so it saved those too: step1_contract.md, step1_output.md, step2_contract.md and step2_output.md.
Other methods
harness(task)is the same asharness.run(task).batched_run(tasks)runs the harness on each prompt one after another and returns a list of results.get_harness_result()returns the harnessid,name,shared_state_pathand the conversation.harness.usagesums the token usage of the three agents.
run() raises ValueError for an empty task. The constructor raises ValueError when max_steps is below 1, max_retries_per_step is below 0, or model_name is empty.
Next steps
- PlannerGeneratorEvaluator reference
- PlannerWorkerSwarm guide for parallel workers instead of one generator
- Runnable scripts