- Codex CLI को लोकल environment में सुरक्षित और दक्ष तरीके से उच्च-गुणवत्ता वाले software changes करने वाले agent के रूप में डिज़ाइन किया गया है
- इसकी मुख्य संरचना agent loop है, जो user input, model inference और tool calls को चक्रीय रूप से जोड़कर सार्थक काम कराती है
- इस loop के दौरान बनने वाले prompt composition, context window management, और prompt caching performance और reliability के प्रमुख तत्व के रूप में काम करते हैं
- Codex, Responses API के जरिए model से संचार करता है, और हर request एक पूर्ण JSON payload से बनी होती है, जिससे stateless व्यवहार बना रहता है
- यह संरचना Zero Data Retention (ZDR), prompt caching, और automatic compaction जैसी उन्नत सुविधाओं को संभव बनाती है, और बड़े पैमाने के agent design की नींव तैयार करती है
Codex एजेंट लूप का अवलोकन
- Codex CLI, user, model, और tools के बीच interaction को orchestrate करने वाली loop structure के केंद्र में काम करता है
- user input लेकर model को भेजे जाने वाला prompt तैयार किया जाता है
- जब model response बनाता है या tool call का अनुरोध करता है, तो agent उसे चलाता है और उसका परिणाम फिर prompt में जोड़ देता है
- जब model आगे कोई tool call नहीं करता और assistant message बनाता है, तो एक turn समाप्त हो जाता है
- हर turn, conversation का हिस्सा होता है, और पिछली messages व tool call history अगली request के prompt में शामिल होती हैं
- क्योंकि prompt की लंबाई model की context window सीमा से प्रभावित होती है, Codex को इसका प्रबंधन करना पड़ता है
Responses API और Codex की संचार संरचना
- Codex CLI, model inference के लिए Responses API को HTTP requests भेजता है
- API endpoint configuration के अनुसार अलग हो सकता है, और OpenAI, ChatGPT, Azure, तथा local (LM Studio, Ollama आदि) environments में इस्तेमाल किया जा सकता है
- API request एक JSON payload से बनी होती है, और इसके मुख्य fields इस प्रकार हैं
- system/developer messages: model का मूल context सेट करना
- instructions: वे tools की सूची जिन्हें model call कर सकता है
- tools: Codex CLI, Responses API, और user (MCP server आदि) द्वारा दी गई tool definitions
- input: message list जिसमें conversation history और environment information शामिल होती है
- Codex,
~/.codex/config.toml settings और project के भीतर AGENTS.md, skills files आदि को पढ़कर user instructions और environment information को अपने-आप insert करता है
Prompt composition और event handling
- Codex, हर message को JSON object (
type, role, content) के रूप में बनाकर Responses API को भेजता है
- server, इसी JSON के आधार पर model prompt generate करता है और SSE (Server-Sent Events) stream के रूप में response लौटाता है
response.output_text.delta event streaming output के लिए उपयोग होता है
response.output_item.added event अगली request के input में जोड़ा जाता है, जिससे loop जारी रहता है
- इसे इस तरह डिज़ाइन किया गया है कि पिछला prompt, नए prompt का बिल्कुल सटीक prefix बने, ताकि prompt caching का लाभ लिया जा सके
Performance optimization: caching और stateless design
- Codex,
previous_response_id का उपयोग नहीं करता, इसलिए पूरी तरह stateless request structure बनाए रखता है
- इससे Zero Data Retention (ZDR) customers के समर्थन और data retention को न्यूनतम रखने में मदद मिलती है
- prompt caching, समान prefix का पुन: उपयोग करके sampling cost को linear बनाती है
- cache hit केवल prompt के exact prefix match पर ही होता है
- tools list, model, sandbox settings, और working directory में बदलाव cache miss कराते हैं
- MCP tools में dynamic changes से cache loss हो सकता है, इसलिए Codex नई messages insert करने के तरीके से बदलावों को reflect करता है
Context window management और automatic compaction
- जब conversation लंबी हो जाती है, तो context window overflow से बचाने के लिए conversation compaction किया जाता है
- शुरुआत में
/compact command से manual summarization किया जाता था, लेकिन अब Responses API के /responses/compact endpoint का स्वत: उपयोग होता है
- यह endpoint
type=compaction item और encrypted encrypted_content लौटाता है, ताकि model की समझ बनी रहे
- Codex, auto_compact_limit पार होने पर अपने-आप compaction चलाता है, जिससे conversation continuity बनी रहती है
निष्कर्ष और आगे की दिशा
- Codex का agent loop, model inference, tool calls, caching, और context management को एकीकृत करने वाली मुख्य संरचना है
- यह संरचना high-performance, stateless, और security-focused agent design को संभव बनाती है
- आगे की posts में CLI architecture, tool usage implementation, और sandboxing model जैसी Codex की आंतरिक संरचना पर और चर्चा की जाएगी
अभी कोई टिप्पणी नहीं है.