程式碼代理需要多少靜態結構?一項關於確定性錨定的研究
How Much Static Structure Do Code Agents Need? A Study of Deterministic Anchoring
June 25, 2026
作者: Zhihao Lin, Mingyi Zhou, Yizhuo Yang, Li Li
cs.AI
摘要
基於大語言模型的程式碼代理透過關鍵字搜尋探索程式碼庫,卻忽略了定義軟體實際運作方式的結構關係,例如呼叫圖、繼承層級與配置依賴。這使得代理的導航具有隨機性,且難以在不同運行之間重現。我們探討輕量級靜態分析是否能為此類代理提供確定性錨點:以純文字註解形式注入穩定的結構事實,藉此約束機率探索,使導航更具可預測性。我們以OpenAI的Codex作為強基線,系統性地注入不同粒度的結構註解,並衡量其對定位、軌跡行為及執行間穩定性的影響。研究發現了所謂的「確定性錨定效應」:靜態結構並非透過讓代理「更聰明」來發揮作用,而是主要透過使導航更有紀律且可重現。三項觀察結果支持此發現:(1) 錨定有效:輕量級呼叫/繼承拓撲提升了函式層級定位(Func@5提升2.2個百分點),並縮短了軌跡(減少1.6個互動回合);(2) 錨定具有規模敏感性:最佳粒度與方向性取決於程式碼庫特性,密集語意會出現報酬遞減,而樞紐密集型專案則受益於僅包含「誰呼叫我」的單向反向連結,無須前向邊;(3) 錨定具穩定性:標記將連結跟隨率從0.15-0.18提升至0.21-0.24,執行間變異數約減少一半,並在中等規模程式碼庫中提升單次運行的可靠性(Pass@1提升3.4個百分點),代價是輸入令牌約增加10%。這些觀察結果提供了實務指引:在中等專案中預設使用輕量拓撲,在大型程式碼庫中裁剪前向邊,並為隱式依賴場景保留密集標記。
English
LLM-based code agents navigate repositories through keyword search but miss the structural relationships, such as call graphs, inheritance hierarchies, and configuration dependencies, that define how software actually works. This makes agent navigation stochastic and difficult to reproduce across runs. We investigate whether lightweight static analysis can provide deterministic anchors for these agents: stable structural facts injected as plain-text comments that constrain probabilistic exploration and make navigation more predictable. Starting from a strong baseline, Codex from OpenAI, we systematically inject varying granularities of structural annotations and measure their effects on localization, trajectory behavior, and run-to-run stability. Our study identifies what we call the deterministic anchoring effect: static structure helps less by making agents "smarter" and more by making their navigation disciplined and reproducible. Three observations support this finding: (1) Anchoring works: lightweight call/inheritance topology improves function-level localization (+2.2pp Func@5) and shortens trajectories (-1.6 interaction rounds); (2) Anchoring is scale-sensitive: the optimal granularity and directionality depend on repository characteristics, where denser semantics show diminishing returns and hub-heavy projects benefit from inverse-only links that expose "who-calls-me" without forward edges; (3) Anchoring stabilizes: tags raise link-following rate from 0.15-0.18 to 0.21-0.24, roughly halve run-to-run variance, and improve single-run reliability (Pass@1 +3.4 pp) on medium-scale repositories, at the cost of roughly 10% more input tokens. These observations suggest practical guidelines: default to lightweight topology on medium projects, prune forward edges in large repositories, and reserve dense tags for implicit-dependency cases.