OpenAI Reveals Inner Workings of Its AI Coding Agent

Key Points
- OpenAI and Anthropic have open‑sourced their coding CLI clients on GitHub.
- The core "agent loop" coordinates user input, model responses, and tool calls.
- The loop repeats: build prompt, query model, execute requested tools, and re‑query.
- Prompt components include system, developer, user, and assistant roles.
- Instructions come from user config files or default CLI bundles.
- Tools defined include shell commands, planning utilities, web search, and MCP‑based custom tools.
- Input field captures sandbox permissions, environment context, and the user’s message.
- Web interfaces for ChatGPT and Claude remain closed source.
- Transparency lets developers examine and build upon the agent architecture.
OpenAI and Anthropic have both placed their coding CLI clients on GitHub, letting developers see the code that powers their AI‑assisted programming tools. A recent post by Bolin explains the core "agent loop" that coordinates user input, model responses, and tool calls. The loop repeatedly builds a prompt, sends it to the model, and either returns a final answer or executes a requested tool before querying the model again. The initial prompt is assembled from distinct components—system, developer, user, and assistant—each with a specific role, and includes instructions, tool definitions, sandbox settings, environment context, and the user’s message.
Agent Loop Overview
The central mechanism behind OpenAI’s coding assistant is an "agent loop" that orchestrates the interaction between a user, the AI model, and the software tools the model may invoke. The loop begins when a user provides input, which the agent transforms into a textual prompt for the model. The model then generates a response. That response can be a direct answer for the user or a request to call a tool, such as executing a shell command, performing a web search, or accessing a custom function via a Model Context Protocol server. If a tool call is requested, the agent runs the tool, captures its output, appends that output to the original prompt, and sends the updated prompt back to the model. This cycle repeats, with the model continually receiving richer context, until it stops requesting tools and produces a final assistant message for the user.
Prompt Construction Details
The initial prompt sent to OpenAI’s Responses API is built from several distinct fields, each assigned a role that determines its priority in the conversation. The instructions field originates either from a configuration file supplied by the user or from default instructions bundled with the CLI client. The tools field enumerates the functions the model is allowed to call, covering built‑in capabilities like shell commands, planning utilities, web search features, and any custom tools provided through Model Context Protocol (MCP) servers. The input field contains a series of items describing sandbox permissions, optional developer instructions, the current working directory as environment context, and finally the user’s actual message. Together, these components form a structured prompt that guides the model’s behavior throughout the agent loop.
Open‑Source Availability
Both OpenAI and Anthropic have chosen to open‑source their coding CLI clients on GitHub, providing developers with direct access to the implementation details of these AI‑driven programming assistants. This transparency allows the community to examine how prompts are assembled, how tool calls are managed, and how the looping logic operates. In contrast, the web interfaces for ChatGPT and Claude remain closed source, meaning their underlying code is not publicly available.
Implications for Developers
By exposing the CLI clients, OpenAI and Anthropic enable developers to study and potentially extend the agent loop architecture. Understanding the role‑based prompt construction and the iterative tool‑execution cycle can inform the design of new AI‑assisted development tools, custom integrations, and enhanced workflows that leverage the same underlying principles. The detailed description of the agent loop serves as a blueprint for building transparent, controllable AI agents that can safely interact with external tools while maintaining a clear conversational context.