CH 03 · Building the Prompt · 10/12
Read as one pageRead the source yourself
Five stops, in the order a request is assembled. Every link is pinned to the commit this chapter quotes.
- Codex base text. Find
BASE_INSTRUCTIONSinmodel_info.rs, openprompt.md, and notice the personality heading is## Personality.strip_personality_sectiononly deletes a line that is exactly# Personality, so this file loses nothing. The h1 it does delete is in the cataloginstructions_templatestrings inmodels.json. - Project files. In
agents_md.rs, finddirs.reverse. The byte budget isproject_doc_max_bytesa little earlier inload_project_instructions. Then openconfig_toml.rsand confirmDEFAULT_PROJECT_DOC_MAX_BYTESis32 * 1024. - Environment. In
environment.rs, findrender_diffand write down which fields count as a change. The session that records those messages isrecord_context_updates_and_set_reference_context_iteminsession/mod.rs. - pi's prompt and pi's tools. In
system-prompt.ts, readbuildSystemPromptSections. The preamble is plain text. Every other section is wrapped in a tag of the same name.<project_context>holds the AGENTS.md and CLAUDE.md files, andrenderProjectContextwraps each file in<project_instructions>.<cwd>is the working directory with backslashes flipped to forward slashes. Then inopenai-completions.ts,convertToolsis the function from the tool-schema slide. - OpenCode's prompt, chosen by model family. In
optimize.ts,OpenAIPluginreturns the GPT text only when the model id containsgpt, and the Astra variant when it also containsastra. That plugin's mode isoverride, so the text replaces the default system prompt.AnthropicPluginreturns the Claude text when the id containsclaude, and its mode isappend, so the text is added after the default. Both plugins leave the prompt alone when the agent already has a system prompt of its own.SessionSystemPrompt.renderfills${OPENCODE_TOOL_GUIDANCE}from the tool names present (shell,write,edit). The environment block is a different mechanism:builtins.tsbuilds a<env>string (working directory, workspace root, whether this is a git repo, platform, and a note to prefer the app temp directory over/tmp). Itschangedrenderer says the environment is now the new value, andInstructions.diffskips any key whose hash did not change.
Exercise: clone pi at the commit in those links, open openai-completions.ts, and find the line that adds strict only when the provider supports it. The comment above that line tells you what always sending the field would do. Do not leave the edit in place.
Finished this idea?
Your learning progress stays in this browser.