Codex CLI as an MCP Tool Inside an Agents-SDK Loop
An outer-planner/inner-coder loop from an official OpenAI recipe: an Agents SDK orchestrator plans and verifies while Codex CLI, wrapped as an MCP server, performs one bounded code change per turn.
Implementation note
When to use: workflows needing separation between planning and coding — you want an orchestrator that decides what to do and verifies outcomes, with the code-touching capability isolated behind a tool boundary. From an official OpenAI recipe. How it works: Codex CLI is wrapped as an MCP server, and an OpenAI Agents SDK orchestrator drives it in a loop: the outer agent plans the work and verifies results, while each inner Codex call performs exactly one bounded code change per turn. The MCP boundary makes the coder a discrete, inspectable tool call rather than an open-ended session. Safety: the outer-planner, inner-coder split is the structural rail — the agent that changes code is not the agent that judges whether the change succeeded, and each code mutation is bounded to one tool invocation. Put iteration and budget caps in the orchestrator loop, since it, not Codex, controls how many turns run.
More automation loops
Run workflows with dynamic sub-agents
Split a task into packets, run sub-agents in parallel, synthesize results, and verify completion.
Run agent turns until goal met
Agent executes repeated turns toward a condition, with a lightweight evaluator checking progress after each turn until the goal is reached.
Run agent until goal met
Queue agent turns with goal context until your objective is achieved, treating the goal as untrusted data.