Building a Self-Healing Agent Loop
Key point
Introduced an Agent loop that automatically repairs outdated API/SDK examples using Codex.
Details
This covers a closed-loop Agent workflow that automatically finds and fixes outdated API/SDK examples and re-validates them. It's a structure where the agent produces a result, validation gives feedback, and that feedback drives the next fix.
The example uses 3 intentionally outdated notebooks from the OpenAI Cookbook. Codex CLI is run in headless mode to repeat review-repair-validate, with the initial reviews run in parallel to collect issues from all three notebooks at once.
- Review: Returns only structured findings without touching the files.
- Repair: Applies minimal fixes to a copy, reflecting the review results and the most recent validation delta.
- Validate: Actually runs the notebook and passes remaining issues back as
remaining_delta.
Before running, a pinned CLI version @openai/[email protected] is installed for reproducibility, OPENAI_API_KEY is set, and gpt-5.4-mini and gpt-5.5 are used as the default models. Reasoning effort is set to low, and the shared contract includes the preferred embedding model text-embedding-3-large along with replacement rules such as client.chat.completions.create -> client.responses.create, qdrant.search -> qdrant.query_points, and oaieval CLI -> the latest Evals API, while keeping samples self-contained and removing manual result file placeholders.
Review, repair, and validation are linked via a JSON schema. Review outputs only findings, repair returns a summary of changes and updated paths, and validation passes the remaining delta as the next input. As the remaining delta from validation becomes the next repair input, the prompts also become increasingly specific. The key point is that this pattern isn't limited to notebooks alone, but applies broadly to any task where quality can be measured with reliable feedback.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.