အဓိက အကြောင်းအရာသို့ ကျော်သွားရန်
OpenAI

၂၀၂၆ ဇန်နဝါရီ ၂၃

အင်ဂျင်နီယာနယ်ပယ်

Unrolling the Codex agent loop

By Michael Bolin, Member of the Technical Staff

ဖွင့်နေသည်…

Codex CLI(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) is our cross-platform local software agent, designed to produce high-quality, reliable software changes while operating safely and efficiently on your machine. We’ve learned a tremendous amount about how to build a world-class software agent since we first launched the CLI in April. To unpack those insights, this is the first post in an ongoing series where we’ll explore various aspects of how Codex works, as well as hard-earned lessons. (For an even more granular view on how the Codex CLI is built, check out our open source repository at https://github.com/openai/codex(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်). Many of the finer details of our design decisions are memorialized in GitHub issues and pull requests if you’d like to learn more.)

To kick off, we’ll focus on the agent loop, which is the core logic in Codex CLI that is responsible for orchestrating the interaction between the user, the model, and the tools the model invokes to perform meaningful software work. We hope this post gives you a good view into the role our agent (or “harness”) plays in making use of an LLM.

Before we dive in, a quick note on terminology: at OpenAI, “Codex” encompasses a suite of software agent offerings, including Codex CLI, Codex Cloud, and the Codex VS Code extension. This post focuses on the Codex harness, which provides the core agent loop and execution logic that underlies all Codex experiences and is surfaced through the Codex CLI. For ease here, we’ll use the terms “Codex” and “Codex CLI” interchangeably.

The agent loop

At the heart of every AI agent is something called “the agent loop.” A simplified illustration of the agent loop looks like this:

“Agent loop” ဟု ခေါင်းစဉ်တပ်ထားသော ပုံသည် AI စနစ်တစ်ခုက အသုံးပြုသူ တောင်းဆိုချက်ကို မည်သို့ လုပ်ဆောင်ပြီး tools ကို ခေါ်ကာ ရလဒ်များကို စောင့်ကြည့်သုံးသပ်ပြီး ၎င်း၏ plan ကို အပ်ဒိတ်လုပ်ကာ output များကို ပြန်ပေးသည်ကို ဖော်ပြထားသည်။ user input၊ model reasoning၊ tool actions နှင့် final response ကဲ့သို့သော အဆင့်များကို မြှားများဖြင့် ချိတ်ဆက်ထားသည်။

To start, the agent takes input from the user to include in the set of textual instructions it prepares for the model known as a prompt.

The next step is to query the model by sending it our instructions and asking it to generate a response, a process known as inference. During inference, the textual prompt is first translated into a sequence of input tokens(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်)—integers that index into the model’s vocabulary. These tokens are then used to sample the model, producing a new sequence of output tokens.

The output tokens are translated back into text, which becomes the model’s response. Because tokens are produced incrementally, this translation can happen as the model runs, which is why many LLM-based applications display streaming output. In practice, inference is usually encapsulated behind an API that operates on text, abstracting away the details of tokenization.

As the result of the inference step, the model either (1) produces a final response to the user’s original input, or (2) requests a tool call that the agent is expected to perform (e.g., “run ls and report the output”). In the case of (2), the agent executes the tool call and appends its output to the original prompt. This output is used to generate a new input that’s used to re-query the model; the agent can then take this new information into account and try again.

This process repeats until the model stops emitting tool calls and instead produces a message for the user (referred to as an assistant message in OpenAI models). In many cases, this message directly answers the user’s original request, but it may also be a follow-up question for the user.

Because the agent can execute tool calls that modify the local environment, its “output” is not limited to the assistant message. In many cases, the primary output of a software agent is the code it writes or edits on your machine. Nevertheless, each turn always ends with an assistant message—such as “I added the architecture.md you asked for”—which signals a termination state in the agent loop. From the agent’s perspective, its work is complete and control returns to the user.

The journey from user input to agent response shown in the diagram is referred to as one turn of a conversation (a thread in Codex). Though this conversation turn can include many iterations between the model inference and tool calls. Every time you send a new message to an existing conversation, the conversation history is included as part of the prompt for the new turn, which includes the messages and tool calls from previous turns:

“Multi-turn agent loop” ဟု ခေါင်းစဉ်တပ်ထားသော ပုံသည် AI အေးဂျင့်တစ်ခုက အသုံးပြုသူ input ကို ထပ်ခါတလဲလဲ လက်ခံကာ actions များ ဖန်တီးပြီး tools များနှင့် တိုင်ပင်ကာ state ကို update လုပ်ပြီး ရလဒ်များ ပြန်ပေးပုံကို ဖော်ပြထားသည်။ အေးဂျင့်၏ reasoning cycle ကို ဖော်ပြသည့် label များ၊ မြှားများနှင့် ဥပမာ tool outputs များ ပါဝင်သည်။

This means that as the conversation grows, so does the length of the prompt used to sample the model. This length matters because every model has a context window, which is the maximum number of tokens it can use for one inference call. Note this window includes both input and output tokens. As you might imagine, an agent could decide to make hundreds of tool calls in a single turn, potentially exhausting the context window. For this reason, context window management is one of the agent’s many responsibilities. Now, let’s dive in to see how Codex runs the agent loop.

Model inference

The Codex CLI sends HTTP requests to the Responses API(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) to run model inference. We’ll examine how information flows through Codex, which uses the Responses API to drive the agent loop.

Let’s explore how Codex creates the prompt for the first inference call in a conversation.

Building the initial prompt

As an end user, you don’t specify the prompt used to sample the model verbatim when you query the Responses API. Instead, you specify various input types as part of your query, and the Responses API server decides how to structure this information into a prompt that the model is designed to consume. You can think of the prompt as a “list of items”; this section will explain how your query gets transformed into that list.

In the initial prompt, every item in the list is associated with a role. The role indicates how much weight the associated content should have and is one of the following values (in decreasing order of priority): system, developer, user, assistant.

The Responses API(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) takes a JSON payload with many parameters. We’ll focus on these three:

The tools field is a list of tool definitions that conform to a schema defined by the Responses API. For Codex, this includes tools that are provided by the Codex CLI, tools that are provided by the Responses API that should be made available to Codex, as well as tools provided by the user, usually via MCP servers:

JavaScript

1
[
2
// Codex's default shell tool for spawning new processes locally.
3
{
4
"type": "function",
5
"name": "shell",
6
"description": "Runs a shell command and returns its output...",
7
"strict": false,
8
"parameters": {
9
"type": "object",
10
"properties": {
11
"command": {"type": "array", "description": "The command to execute", ...},
12
"workdir": {"description": "The working directory...", ...},
13
"timeout_ms": {"description": "The timeout for the command...", ...},
14
...
15
},
16
"required": ["command"],
17
}
18
}
19

20
// Codex's built-in plan tool.
21
{
22
"type": "function",
23
"name": "update_plan",
24
"description": "Updates the task plan...",
25
"strict": false,
26
"parameters": {
27
"type": "object",
28
"properties": {"plan":..., "explanation":...},
29
"required": ["plan"]
30
}
31
},
32

33
// Web search tool provided by the Responses API.
34
{
35
"type": "web_search",
36
"external_web_access": false
37
},
38

39
// MCP server for getting weather as configured in the
40
// user's ~/.codex/config.toml.
41
{
42
"type": "function",
43
"name": "mcp__weather__get-forecast",
44
"description": "Get weather alerts for a US state",
45
"strict": false,
46
"parameters": {
47
"type": "object",
48
"properties": {"latitude": {...}, "longitude": {...}},
49
"required": ["latitude", "longitude"]
50
}
51
}
52
]

Finally, the input field of the JSON payload is a list of items. Codex inserts the following items(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) into the input before adding the user message:

1. A message with role=developer that describes the sandbox that applies only to the Codex-provided shell tool defined in the tools section. That is, other tools, such as those provided from MCP servers, are not sandboxed by Codex and are responsible for enforcing their own guardrails.

The message is built from a template where the key pieces of content come from snippets of Markdown bundled into the Codex CLI, such as workspace_write.md(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) and on_request.md(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်):

ရိုးရိုးစာသား

1
<permissions instructions>
2
- description of the sandbox explaining file permissions and network access
3
- instructions for when to ask the user for permissions to run a shell command
4
- list of folders writable by Codex, if any
5
</permissions instructions>

2. (Optional) A message with role=developer whose contents are the developer_instructions value read from the user’s config.toml file.

3. (Optional) A message with role=user whose contents are the “user instructions,” which are not sourced from a single file but are aggregated across multiple sources(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်). In general, more specific instructions appear later:

4. A message with role=user that describes the local environment in which the agent is currently operating. This specifies the current working directory and the user’s shell(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်):

ရိုးရိုးစာသား

1
<environment_context>
2
<cwd>/Users/mbolin/code/codex5</cwd>
3
<shell>zsh</shell>
4
</environment_context>

အထက်ဖော်ပြပါ computation အားလုံးကို လုပ်ဆောင်ပြီး input ကို initialize လုပ်ပြီးနောက် Codex သည် conversation ကို စတင်ရန် user message ကို ပူးတွဲထည့်သွင်းသည်။

ယခင်ဥပမာများတွင် message တစ်ခုစီ၏ content ကို အဓိကထားခဲ့သော်လည်း input ၏ element တစ်ခုစီသည် type, role(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) နှင့် content ပါဝင်သော JSON object တစ်ခုဖြစ်သည်ကို သတိပြုပါ -

JSON

1
{
2
"type": "message",
3
"role": "user",
4
"content": [
5
{
6
"type": "input_text",
7
"text": "Add an architecture diagram to the README.md"
8
}
9
]
10
}

Codex သည် Responses API သို့ ပို့ရန် JSON payload အပြည့်အစုံကို တည်ဆောက်ပြီးသည်နှင့် ~/.codex/config.toml တွင် Responses API endpoint ကို မည်သို့ configure လုပ်ထားသည်အပေါ် မူတည်သော Authorization header ဖြင့် HTTP POST request ကို ပြုလုပ်သည် (သတ်မှတ်ထားပါက အပို HTTP headers နှင့် query parameters များကိုလည်း ထည့်သွင်းသည်)။

OpenAI Responses API server သည် request ကို လက်ခံရရှိသောအခါ JSON ကို အသုံးပြု၍ မော်ဒယ်အတွက် prompt ကို အောက်ပါအတိုင်း derive လုပ်သည် (သေချာစေရန် ပြောရလျှင် Responses API ၏ custom implementation တစ်ခုသည် ကွဲပြားသော ရွေးချယ်မှုတစ်ခု ပြုလုပ်နိုင်သည်) -

AI အေးဂျင့် loop တစ်ခုအတွင်း အဆင့်တစ်ဆင့်တည်းကို ပြထားသော snapshot ပုံ။ user request တစ်ခုက မော်ဒယ်ထဲသို့ ဝင်လာပြီး tool name ပါသော action တစ်ခု၊ thought တစ်ခုနှင့် tool input တစ်ခုကို ထုတ်ပေးသည်။ ပုံသည် tool ကို မခေါ်မီရှိသော ဤကြားခံ reasoning အဆင့်ကို အလေးပေးပြထားသည်။

မြင်နိုင်သကဲ့သို့ prompt ၏ ပထမ items သုံးခု၏ အစီအစဉ်ကို client က မဟုတ်ဘဲ server က သတ်မှတ်သည်။ သို့သော် ထို items သုံးခုအနက် system message ၏ content ကိုသာ server က ထိန်းချုပ်ထားပြီး tools နှင့် instructions ကိုတော့ client က သတ်မှတ်သည်။ ထို့နောက် JSON payload ထဲရှိ input ကို ဆက်ထည့်ကာ prompt ကို ပြီးပြည့်စုံစေသည်။

ယခု ကျွန်ုပ်တို့တွင် prompt ရရှိပြီးဖြစ်သောကြောင့် မော်ဒယ်ကို sample ယူရန် အဆင်သင့်ဖြစ်ပါပြီ။

ပထမ turn

Responses API သို့ ဤ HTTP request သည် Codex အတွင်း conversation တစ်ခု၏ ပထမ “turn” ကို စတင်ပေးသည်။ server သည် Server-Sent Events (SSE(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်)) stream ဖြင့် တုံ့ပြန်သည်။ event တစ်ခုစီ၏ data သည် "type" ဖြင့် စတင်သော JSON payload ဖြစ်ပြီး ၎င်းမှာ ဤကဲ့သို့ ဖြစ်နိုင်သည် (event အပြည့်အစုံစာရင်းကို ကျွန်ုပ်တို့၏ API docs(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) တွင် ကြည့်နိုင်သည်) -

ရိုးရိုးစာသား

1
data: {"type":"response.reasoning_summary_text.delta","delta":"ah ", ...}
2
data: {"type":"response.reasoning_summary_text.delta","delta":"ha!", ...}
3
data: {"type":"response.reasoning_summary_text.done", "item_id":...}
4
data: {"type":"response.output_item.added", "item":{...}}
5
data: {"type":"response.output_text.delta", "delta":"forty-", ...}
6
data: {"type":"response.output_text.delta", "delta":"two!", ...}
7
data: {"type":"response.completed","response":{...}}

Codex သည် event stream ကို စားသုံးပြီး(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) client က အသုံးပြုနိုင်သော internal event objects များအဖြစ် ပြန်လည်ထုတ်ဝေသည်။ response.output_text.delta ကဲ့သို့ event များကို UI တွင် streaming ပံ့ပိုးရန် အသုံးပြုသော်လည်း response.output_item.added ကဲ့သို့ event များကို နောက်ဆက်တွဲ Responses API calls များအတွက် input ထဲသို့ ပူးတွဲထည့်သွင်းသော objects များအဖြစ် ပြောင်းလဲသည်။

Responses API သို့ ပထမ request တွင် response.output_item.done events နှစ်ခု ပါဝင်သည်ဟု ယူဆကြပါစို့ - တစ်ခုမှာ type=reasoning နှင့် တစ်ခုမှာ type=function_call ဖြစ်သည်။ tool call ၏ response နှင့်အတူ မော်ဒယ်ကို ပြန်မေးမြန်းသောအခါ ဤ events များကို JSON ၏ input field ထဲတွင် ကိုယ်စားပြုရမည် - 

JavaScript

1
[
2
/* ... original 5 items from the input array ... */
3
{
4
"type": "reasoning",
5
"summary": [
6
"type": "summary_text",
7
"text": "**Adding an architecture diagram for README.md**\n\nI need to..."
8
],
9
"encrypted_content": "gAAAAABpaDWNMxMeLw..."
10
},
11
{
12
"type": "function_call",
13
"name": "shell",
14
"arguments": "{\"command\":\"cat README.md\",\"workdir\":\"/Users/mbolin/code/codex5\"}",
15
"call_id": "call_8675309..."
16
},
17
{
18
"type": "function_call_output",
19
"call_id": "call_8675309...",
20
"output": "<p align=\"center\"><code>npm i -g @openai/codex</code>..."
21
}
22
]

နောက်ဆက်တွဲ query ၏ အစိတ်အပိုင်းအဖြစ် မော်ဒယ်ကို sample ယူရန် အသုံးပြုသော resulting prompt သည် ဤကဲ့သို့ ဖြစ်မည် -

“Snapshot 2” ဟု အမည်တပ်ထားသော ပုံသည် tool call တစ်ခုပြီးနောက် AI အေးဂျင့်ကို ပြထားသည်။ မော်ဒယ်သည် tool observation ကို လက်ခံရရှိပြီး thought အသစ်နှင့် action အသစ်ကို ထုတ်ပေးသည်။ မြှားများက input၊ observation နှင့် output များကို ချိတ်ဆက်ကာ အေးဂျင့်က ၎င်း၏ reasoning loop ကို မည်သို့ ထပ်လဲလုပ်ဆောင်သည်ကို ဖော်ပြထားသည်။

အထူးသဖြင့် prompt အဟောင်းသည် prompt အသစ်၏ တိတိကျကျ prefix ဖြစ်သည်ကို သတိပြုပါ။ ၎င်းမှာ ရည်ရွယ်ထားခြင်းဖြစ်ပြီး အဘယ်ကြောင့်ဆိုသော် ထိုသို့ဖြစ်ခြင်းက prompt caching ကို အသုံးချနိုင်စေသဖြင့် နောက်ဆက်တွဲ request များကို ပိုမိုထိရောက်စေသောကြောင့် ဖြစ်သည် (performance အပိုင်းတွင် ဆက်လက်ဆွေးနွေးပါမည်)။

အေးဂျင့် loop ၏ ပထမပုံကို ပြန်ကြည့်လျှင် inference နှင့် tool calling အကြား iteration အများအပြား ရှိနိုင်သည်ကို မြင်ရပါသည်။ turn ၏ အဆုံးကို ဖော်ပြသည့် assistant message တစ်ခုကို နောက်ဆုံးလက်ခံရသည်အထိ prompt သည် ဆက်လက်ကြီးထွားလာနိုင်ပါသည် -

ရိုးရိုးစာသား

1
data: {"type":"response.output_text.done","text": "I added a diagram to explain...", ...}
2
data: {"type":"response.completed","response":{...}}

Codex CLI တွင် assistant message ကို အသုံးပြုသူထံ တင်ပြပြီး conversation ကို ဆက်လက်လုပ်ဆောင်ရန် ယခု အသုံးပြုသူ၏ “turn” ဖြစ်ကြောင်း composer ကို focus လုပ်ပေးပါသည်။ အသုံးပြုသူက တုံ့ပြန်ပါက ယခင် turn မှ assistant message နှင့် အသုံးပြုသူ၏ message အသစ် နှစ်ခုလုံးကို turn အသစ် စတင်ရန် Responses API request ၏ input ထဲသို့ ပူးတွဲထည့်သွင်းရမည် -

JavaScript

1
[
2
/* ... all items from the last Responses API request ... */
3
{
4
"type": "message",
5
"role": "assistant",
6
"content": [
7
{
8
"type": "output_text",
9
"text": "I added a diagram to explain the client/server architecture."
10
}
11
]
12
},
13
{
14
"type": "message",
15
"role": "user",
16
"content": [
17
{
18
"type": "input_text",
19
"text": "That's not bad, but the diagram is missing the bike shed."
20
}
21
]
22
}
23
]

တစ်ဖန် conversation ကို ဆက်လက်လုပ်ဆောင်နေသောကြောင့် Responses API သို့ ပို့သော input ၏ အရှည်သည် ဆက်လက်တိုးလာနေပါသည် -

“Snapshot 3” ဟု အမည်တပ်ထားသော ပုံသည် AI အေးဂျင့် loop ၏ နောက်ဆုံးအဆင့်ကို ပြထားသည်။ tool ရလဒ်များကို လက်ခံရရှိပြီးနောက် မော်ဒယ်သည် အဆုံးသတ် စဉ်းစားချက်တစ်ခုနှင့် အသုံးပြုသူထံ ပြန်ပို့သော နောက်ဆုံးအဖြေကို ထုတ်ပေးသည်။ မြှားများက tool output မှ ပြီးစီးသော response သို့ ကူးပြောင်းမှုကို ပြသထားသည်။

ဤအဆက်မပြတ်ကြီးထွားလာသော prompt သည် performance အတွက် ဘာကို ဆိုလိုသလဲဆိုတာ လေ့လာကြပါစို့။

Performance ဆိုင်ရာ စဉ်းစားချက်များ

“စကားပြောဆိုမှုတစ်လျှောက် Responses API သို့ ပို့သော JSON ပမာဏအရ agent loop က quadratic မဟုတ်ဘူးလား” ဟု သင်မေးနိုင်ပါသည်။ ထိုမေးခွန်းသည် မှန်ပါသည်။ ဤပြဿနာကို လျော့ပါးစေရန် Responses API တွင် optional previous_response_id(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) parameter ကို ပံ့ပိုးပေးသော်လည်း Codex သည် လက်ရှိတွင် ၎င်းကို အသုံးမပြုပါ။ အဓိကအကြောင်းရင်းမှာ request များကို အပြည့်အဝ stateless ထားလိုခြင်းနှင့် Zero Data Retention (ZDR) configuration များကို ပံ့ပိုးလိုခြင်းတို့ ဖြစ်သည်။

previous_response_id ကို ရှောင်ခြင်းက Responses API provider အတွက် လုပ်ငန်းစဉ်များကို ရိုးရှင်းစေပါသည်၊ အဘယ်ကြောင့်ဆိုသော် request တိုင်းသည် stateless ဖြစ်ကြောင်း သေချာစေသောကြောင့် ဖြစ်သည်။ ၎င်းကြောင့် Zero Data Retention (ZDR)(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ကို ရွေးချယ်ထားသော customer များကို ပံ့ပိုးရန်လည်း လွယ်ကူစေသည်၊ အဘယ်ကြောင့်ဆိုသော် previous_response_id ကို ပံ့ပိုးရန် လိုအပ်သော data ကို သိမ်းဆည်းရခြင်းသည် ZDR နှင့် ဆန့်ကျင်နေသောကြောင့် ဖြစ်သည်။ ZDR customer များသည် ယခင် turn များမှ proprietary reasoning messages များ၏ အကျိုးကျေးဇူးကို မဆုံးရှုံးကြပါ၊ အကြောင်းမှာ ဆက်နွယ်နေသော encrypted_content ကို server ပေါ်တွင် decrypt လုပ်နိုင်သောကြောင့် ဖြစ်သည်။ (OpenAI သည် ZDR customer ၏ decryption key ကိုသာ သိမ်းထားပြီး ၎င်းတို့၏ data ကိုတော့ မသိမ်းပါ။) ZDR ကို ပံ့ပိုးရန် Codex တွင် ပြုလုပ်ခဲ့သော သက်ဆိုင်ရာ ပြောင်းလဲမှုများအတွက် PRs #642(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) နှင့် #1641(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ကို ကြည့်ပါ။

ယေဘုယျအားဖြင့် မော်ဒယ် sampling ၏ cost သည် network traffic ၏ cost ထက် ပိုကြီးသောကြောင့် sampling ကို ထိရောက်အောင်လုပ်ခြင်းသည် ကျွန်ုပ်တို့၏ အဓိက ရည်မှန်းချက်ဖြစ်သည်။ ထို့ကြောင့် prompt caching သည် အလွန်အရေးကြီးပြီး ယခင် inference call မှ computation ကို ပြန်လည်အသုံးပြုနိုင်စေသည်။ cache hit ရရှိသောအခါ မော်ဒယ် sampling သည် quadratic မဟုတ်ဘဲ linear ဖြစ်လာသည်။ ကျွန်ုပ်တို့၏ prompt caching (ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်)documentation တွင် ယင်းကို ပိုမိုအသေးစိတ် ရှင်းပြထားပါသည် -

prompt အတွင်း တိတိကျကျ prefix တူညီမှု ရှိသည့်အခါမှသာ cache hit ဖြစ်နိုင်သည်။ caching ၏ အကျိုးကျေးဇူးများ ရရှိစေရန် instructions နှင့် examples ကဲ့သို့ static content များကို prompt ၏ အစတွင်ထားပြီး user-specific information ကဲ့သို့ variable content များကို အဆုံးတွင် ထားပါ။ ၎င်းသည် images နှင့် tools များအပေါ်လည်း သက်ဆိုင်ပြီး request များအကြား ၎င်းတို့သည် တူညီနေရမည်။

ဤအချက်ကို စိတ်ထဲထားကာ Codex တွင် “cache miss” ဖြစ်စေနိုင်သော operation အမျိုးအစားများကို စဉ်းစားကြပါစို့ -

  • conversation အလယ်တွင် မော်ဒယ်အတွက် ရရှိနိုင်သော tools များကို ပြောင်းလဲခြင်း။
  • Responses API request ၏ target ဖြစ်သော model ကို ပြောင်းလဲခြင်း (လက်တွေ့တွင် ၎င်းက မူလ prompt ၏ တတိယ item ကို ပြောင်းလဲစေသည်၊ အဘယ်ကြောင့်ဆိုသော် ၎င်းတွင် model-specific instructions ပါဝင်သောကြောင့် ဖြစ်သည်)။
  • sandbox configuration, approval mode သို့မဟုတ် current working directory ကို ပြောင်းလဲခြင်း။

prompt caching ကို ထိခိုက်စေနိုင်သော Codex CLI features အသစ်များကို မိတ်ဆက်ရာတွင် Codex team သည် အထူးသတိထားရပါမည်။ ဥပမာတစ်ခုအနေဖြင့် MCP tools အတွက် ကျွန်ုပ်တို့၏ ကနဦးပံ့ပိုးမှုတွင် tools များကို အစဉ်တကျ မတူညီစွာ enumerate လုပ်မိသည့် bug တစ်ခု(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ရှိခဲ့ပြီး cache misses ဖြစ်စေခဲ့သည်။ MCP servers များသည် notifications/tools/list_changed(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) notification မှတစ်ဆင့် ၎င်းတို့ ပေးသော tools စာရင်းကို အချိန်နှင့်တပြေးညီ ပြောင်းလဲနိုင်သောကြောင့် MCP tools များသည် အထူးရှုပ်ထွေးနိုင်သည်ကို သတိပြုပါ။ ရှည်လျားသော conversation အလယ်တွင် ဤ notification ကို လေးစားလိုက်နာခြင်းက စရိတ်ကြီးမားသော cache miss တစ်ခု ဖြစ်စေနိုင်သည်။

ဖြစ်နိုင်သည့်အခါ conversation အလယ်တွင် ဖြစ်ပေါ်သော configuration changes များကို earlier message တစ်ခုကို ပြင်ဆင်မည့်အစား အပြောင်းအလဲကို ထင်ဟပ်စေရန် input ထဲသို့ message အသစ် တစ်ခု ပူးတွဲထည့်သွင်းခြင်းဖြင့် ကိုင်တွယ်ပါသည် -

performance အတွက် cache hits ရရှိစေရန် ကျွန်ုပ်တို့ အလွန် ကြိုးပမ်းပါသည်။ ကျွန်ုပ်တို့ စီမံခန့်ခွဲရမည့် နောက်ထပ် အရေးကြီးသော resource တစ်ခုလည်း ရှိသေးသည် - context window ဖြစ်သည်။

context window မကုန်သွားစေရန် ကျွန်ုပ်တို့၏ ယေဘုယျ strategy သည် token အရေအတွက် threshold တစ်ခုကျော်သွားသောအခါ conversation ကို compact လုပ်ခြင်းဖြစ်သည်။ တိတိကျကျဆိုရလျှင် conversation ကို ကိုယ်စားပြုနိုင်သော items စာရင်းအသစ်နှင့် ပိုသေးငယ်သော items စာရင်းတစ်ခုဖြင့် input ကို အစားထိုးပြီး အေးဂျင့်သည် ယခုအချိန်အထိ ဖြစ်ပျက်ခဲ့သမျှကို နားလည်မှုရှိစွာ ဆက်လက်လုပ်ဆောင်နိုင်စေသည်။ အစောပိုင်း compaction implementation(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) တစ်ခုတွင် အသုံးပြုသူက /compact command ကို ကိုယ်တိုင် invoke လုပ်ရပြီး ရှိပြီးသား conversation နှင့် summarization(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) အတွက် custom instructions များကို အသုံးပြုကာ Responses API ကို query လုပ်ရသည်။ Codex သည် resulting assistant message အတွင်းရှိ summary ကို subsequent conversation turns အတွက် input အသစ်အဖြစ်(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) အသုံးပြုခဲ့သည်။

ထိုနောက် Responses API သည် compaction ကို ပိုမိုထိရောက်စွာ လုပ်ဆောင်ပေးသော အထူး /responses/compact endpoint(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ကို ပံ့ပိုးနိုင်အောင် တိုးတက်လာခဲ့သည်။ ၎င်းသည် ယခင် input အစား အသုံးပြုကာ conversation ကို ဆက်လက်လုပ်ဆောင်နိုင်ပြီး context window ကိုလည်း လွတ်စေသော items စာရင်းတစ်ခု(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ကို ပြန်ပေးသည်။ ဤစာရင်းတွင် မူလ conversation အပေါ် မော်ဒယ်၏ latent understanding ကို ထိန်းသိမ်းထားသော opaque encrypted_content item ပါဝင်သည့် အထူး type=compaction item တစ်ခု ပါရှိသည်။ ယခု Codex သည် auto_compact_limit(ဝင်းဒိုးအသစ်တွင် ဖွင့်မည်) ကျော်လွန်သွားသောအခါ conversation ကို compact လုပ်ရန် ဤ endpoint ကို အလိုအလျောက် အသုံးပြုပါသည်။

နောက်ထပ်လာမည့်အရာ

Codex အေးဂျင့် loop ကို မိတ်ဆက်ခဲ့ပြီး မော်ဒယ်ကို query လုပ်သောအခါ Codex က ၎င်း၏ context ကို မည်သို့ ဖန်တီးထိန်းချုပ်သည်ကို လေ့လာခဲ့ပါသည်။ လမ်းတစ်လျှောက်တွင် Responses API အပေါ် အေးဂျင့် loop တစ်ခု တည်ဆောက်သူတိုင်းအတွက် သက်ဆိုင်သော လက်တွေ့စဉ်းစားချက်များနှင့် best practices များကိုလည်း အထူးဖော်ပြခဲ့ပါသည်။

အေးဂျင့် loop သည် Codex ၏ အခြေခံကို ပံ့ပိုးပေးသော်လည်း ၎င်းသည် အစသာ ဖြစ်ပါသည်။ လာမည့်ပို့စ်များတွင် CLI ၏ architecture ကို နက်ရှိုင်းစွာ လေ့လာပြီး tool use ကို မည်သို့ အကောင်အထည်ဖော်ထားသည်ကို ရှာဖွေကာ Codex ၏ sandboxing model ကိုလည်း ပိုမိုနီးကပ်စွာ ကြည့်ရှုမည်ဖြစ်သည်။

စာရေးသူ

Michael Bolin

ကျေးဇူးတင်လွှာ

Codex CLI ကို တည်ဆောက်ခဲ့သော အဖွဲ့တစ်ခုလုံးအား အထူးကျေးဇူးတင်ရှိပါသည်။