Manuscript Offprint

arXiv:2610.38214

Skeleton Coding: Program Structure as a Specification for Agents

Aditya Golatkar, Alessandro Achille, Renos Zabounidis, Vlad Sobal, Yangruibo Ding, Baishakhi Ray, Jonathan Buck, Guy Van den Broeck, Maryam Fazel, Pietro Perona, Wei Xia, Stefano Soatto

Abstract

Coding agents are typically provided end-to-end behavioral specifications that the code they produce should satisfy, such as tests and input-output examples. How many such specifications must a developer provide, and which ones, for the agent to produce the developer's intended program? We argue that this cannot be determined a priori, for it depends on the structure of the implementation, which is left to the agent to decide. An agent first commits to a structure—a decomposition into data types, modules, and functions—which fixes a class of candidate programs; behavioral specifications then select a program within that class. A set of tests that suffices for one structure may leave another badly underdetermined, requiring different edge cases or exponentially more examples. Since the structure is chosen by the agent, developers cannot ensure their specification is complete without reverse-engineering it from thousands of lines of generated code. To resolve this, we introduce Skeleton Coding, in which developers jointly specify the structure—in high-level, code-like format—alongside behavioral specifications. Theoretically, we model AI-assisted coding as a control problem, and show that skeletons can reduce exponentially the number of tests developers must supply to steer an agent toward an acceptable program. Empirically, across four models and three benchmarks, the best-performing skeleton specifications reduce mean test error by 48.4% relative to the best end-to-end behavioral specifications. Even when the agent can query a complete reference implementation, adding a skeleton reduces mean test error relatively by up to 27.0%. Skeletons also narrow the average gap between small and large models by about 52.4% while lowering implementation cost by 15-26×, and reduce code erosion by 24.7% on average.

1 Introduction

Coding agents are shifting the role of developers from writing code to controlling an agent into producing an acceptable code base. This raises a key question: how can developers specify their intent and safely guide the agent toward producing an acceptable program, while minimizing their effort?

A common ideal has been to move toward the separation of concerns [1] offered by specification-driven development [2]: The developer's job should not be to dictate how to implement the code base, but to specify what behavior any acceptable result must have — through prompts, examples, tests, or formal contracts — and verify that the result fulfills that intent.

*Equal contribution sorted alphabetically Corresponding authors: agolatka@amazon.com, aachille@amazon.com

Figure

(a)

(b)

(c)

Figure 1: Behavioral specifications do not pinpoint correct programs. (Left) We ask a coding agent to implement a code base from ProgramBench given its documentation and a fraction of its test suite. We then measure error rate across the hidden suite. On average, no number of tests provided results in a program that passes all hidden tests. (Middle) Even providing a full behavioral specification is not enough: We measure the pass rate with access to an oracle providing the full and exact input-output behavior. Even so, adding a skeleton with local contracts increases the pass rate averaged across models by 10.9% relative to the same setup without a skeleton on ProgramBench. (Right) A skeleton specifying the local contract for slicing a strided view.

Ideally, this separation of concerns between the what and the how promises to free developers from the laborious task of writing code. However, we show that it can actually exponentially increase the effort required.

The separation fails because how many tests are needed, and which ones, is not a property of the function being implemented but of the structure of its implementation. Consider for example implementing the indexing rules of NumPy: fully specifying all their edge cases takes many tests and examples, yet most of them follow naturally from a single structural choice — implementing arrays as strided views of memory [3, 4] — which no example or end-to-end test can express. Yet it is the agent, not the developer, that chooses the structure. A test suite that suffices for one design can leave another badly underdetermined, so a developer cannot know whether their tests are sufficient without further extensive manual testing, or inspection of thousands of lines of generated code.

Based on this, we argue that the most effective control action for developers is to partially break the separation, and jointly specify structure and behavior. To this effect, we introduce Skeleton Coding, in which developers specify the structure of an application directly, in high-level, code-like form: data types, module boundaries, function signatures, data flow, per-function contracts, and invariants — leaving the actual implementation to the agent (Section A.1). These are the decisions where skilled developers traditionally add the most value, and that end-to-end tests cannot express.

Formally, the coding agent faces an identification problem [5, 6, 7]. Let H\mathcal{H} be the programs the agent can produce and G⊆H\mathcal{G} \subseteq \mathcal{H} the developer's goal set of acceptable programs. Given input-output observations DD of a reference program, the agent must find a program in G\mathcal{G}. It first commits to a design—a decomposition into data types, modules, and functions—which restricts the search to a class HS\mathcal{H}_S, and tests then select a program within it. Even when the training of the model results in a strong prior, some tasks require exponentially many observations before the agent succeeds with

Figure

Figure 2: Value of different types of specifications. We generate specifications of different kinds and measure the error rate of a coding agent using them. No matter the format, behavioral specifications that describe only end-to-end behavior underperform specifications that describe the developer's intended structure. Of the structural specifications, code-like specifications that describe function signatures and invariants outperform design files in natural language. Adding overly detailed specifications decreases the accuracy of smaller models.

high probability. Figure 1 (left) illustrates the problem: supplying more tests raises the pass rate, yet on average no number of tests yields a program that passes the full suite. From the developer's side, this is a control problem: find the cheapest specification DD that makes the agent sample a program from G\mathcal{G} (Section 2). Unfortunately, the optimal DD depends on HS\mathcal{H}_S, which the developer does not see.

Skeleton coding addresses the issue by letting the developer supply HS\mathcal{H}_S. Instead of carving out the goal set one test at a time, developers can shrink the hypothesis class and provide the optimal tests for it. This can cut the number of needed tests exponentially, for several reasons. First, skeletons can quickly reduce the dimension of the hypothesis space. But, less intuitively, even when two skeletons lead to search spaces of the same size, a well-chosen hypothesis class may need exponentially fewer tests to identify the correct program than a poorly chosen one (Theorem 2.1). Second, with end-to-end tests alone the program's internal state is hidden: an error in one component is visible only if it propagates to the output. By exposing intermediate interfaces, a skeleton makes that state observable, so for example a dataflow composing nn function can be identified with O(n)O(n) local tests, whereas end-to-end tests may need O(2n)O(2^n) (Theorem 2.2). Third, some requirements, such as internal implementation details, are not observable from outputs at all and no number of tests can enforce them. A skeleton can instead state them directly (Theorem 2.3).

Developers rarely begin with a complete specifications; they adapt it to correct issues and steer the agent toward the goal. However, since prompting a model does not perform Bayesian conditioning [8], there is no guarantee that providing additional specifications will eventually converge to the goal. However, adding formally verifiable contracts [9, 10, 11] to the skeletons circumvent the issue (Theorem 3.1). Even when informal contracts are not used, an imperfect verifier can still ensure faster convergence to a valid implementation (Theorem 3.2).

Because skeletons resemble code, teams can version, diff, review, and revise them alongside the implementation as requirements evolve. A persistent skeleton also records which decisions are

Figure

Figure 3: Skeletons and tests shrink the set of programs the agent considers: (a) Without a skeleton, the agent's prior spreads over all programs. (b) Fixing a skeleton restricts the agent to programs with that skeleton. (c) Each set of end-to-end tests further keeps only the programs that agree with the reference on the tested inputs.

requirements, so agents can rewrite cleanly when adding functionality instead of accreting patches to preserve accidental behavior, a major contributor to “AI code slop” on long-lived code bases [12].

Empirical results. To show the value of skeletons and structural specifications, we compare the pass-rate with and without skeletons across various coding benchmarks and architectures. On SCBench [12] and SDDBench (Section B), structural specifications raise mean pass rate from 72% to 89% and from 29.0% to 74.2%, whereas even the best purely behavioral specifications gain at most 9.4 percentage points (Figure 2). Surprisingly, on ProgramBench [13], where the coding agent is provided with a full behavioral-specifications (an oracle binary), skeletons still raise relative pass rate by 10.9% (Figure 1, right). Skeletons also narrow the gap between small and large models [14]: with a detailed skeleton, a small model comes within 5–8 percentage points of the largest model's pass rate at 15–26× lower implementation cost (Figure 5). Aside from outperforming behavioral specifications, our proposed code-like skeletons outperform structural specifications provided as prose design documents (Figure 6). In terms of code maintainability, skeletons reduce code erosion by 24.7% where behavioral specifications increase it (Figure 7). In iterative repair, they reach similar error rates with 32% fewer queries to the reference executable (Figure 8).

References (43)