CH 03 · Building the Prompt · 03/12
Read as one pageHow it works: assembling one request
Putting the pieces together, here is the order Codex inserts items into input before adding your actual message:
- A
developermessage describing the sandbox and permission rules (applies to the built-in shell tool). - Optional
developerinstructions from config. - A
usermessage with the aggregatedAGENTS.md/ skills instructions. - A
usermessage describing the environment (<environment_context>with cwd and shell). - Finally, your actual user message.
At the commit the Real code slides quote, the code keeps that shape with two changes: the developer pieces are bundled into one developer message, and the developer instructions from config now come after the AGENTS.md and environment messages. The idea is unchanged: standing instructions first, your message last.
Then on later turns, the previous turns' items (assistant messages, tool calls, tool results) are appended, along with any context section that changed (a new working directory, say), and the old prompt stays an exact prefix of the new one. That prefix property is not an accident; it is engineered, again for caching.
Finished this idea?
Your learning progress stays in this browser.