HeadlinesBriefing favicon HeadlinesBriefing.com

OpenAI Codex Agent Loop Explained

OpenAI News •
×

OpenAI published a technical deep dive into the Codex CLI agent loop. The post explains how the local software agent orchestrates models, tools, and prompts using the Responses API. This is the first in a series exploring the architecture since its April launch, with source code available on GitHub.

The core loop starts with user input, which is formatted into a prompt for model inference. The model can then issue a tool call, which the agent executes. The output is fed back into the prompt, repeating until the model produces a final assistant message. This cycle manages the conversation thread and context window.

Codex CLI sends HTTP requests to a configurable Responses API endpoint. This could be OpenAI's hosted service, a local instance using Ollama or LM Studio, or a cloud provider like Azure. The API constructs the model's prompt from instructions, tools, and user input, abstracting tokenization details for developers.