Est.

Replacing the Prompt Rewrite Loop With Structural Graph Constraints

Explicit graph rules can check agent changes where prompts can't.

Sponsored by Graphide

The Graph & Build Editors
· 8 min read · Updated
Cover illustration for “Replacing the Prompt Rewrite Loop With Structural Graph Constraints”
Agent Workflows · November 19, 2026 · 8 min read · 1,904 words

An interactive codebase graph for AI agent steering is useful when it turns architecture into an enforceable contract. To replace the prompt rewrite loop with structural graph constraints, give agents explicit dependencies and boundaries to work within, then check their changes against those rules. Declared structural constraints are enforced deterministically without relying on natural-language instructions to hold.

Why the prompt rewrite loop is the wrong control surface for agents

Another round of prompt edits produces another subtly wrong diff. The agent follows the requested change but introduces a dependency that should not exist, or places logic across a boundary the developer thought was clear. The developer strengthens the instruction, reruns the agent, and inspects the next result. This feels like steering the system directly. Yet the architectural rule still exists only as something the agent must interpret.

A well-designed execution loop is better than naive prompting because it gives the agent feedback and opportunities to correct mistakes. But feedback does not itself define an architectural contract. If the verifier cannot recognize a forbidden dependency, another iteration offers no dependable way to reject it. The loop can improve the candidate without correcting the control mechanism. Its effectiveness depends on what the surrounding system can actually check.

Natural language has no inherent memory of the codebase it describes. A constraint in a prompt does not acquire enforcement across sessions merely because its wording is precise, and it does not become machine-checkable through repetition. Developers therefore spend cycles refining words when the missing artifact is an explicit structural rule. The distinction is between instruction and enforcement. Prompt tuning can make the intended change clear, but it cannot replace a contract built into the structure being changed.

Why verbal constraints don't hold as agents work deeper into a codebase

CGFuse (2026) identifies a mismatch between sequential token processing and the structure of software. Transformer-based models process code as token patterns and have only an implicit grasp of structure, so some information about control flow and data dependencies is lost. Codebase constraints operate over different objects. They concern dependencies, call relationships, and module boundaries, so a fluent description of those relationships is not equivalent to an explicit model of them.

A request to avoid circular dependencies describes a rule, but does not establish a check over the dependency graph. An instruction to keep authentication logic in its own module also depends on interpretation unless that module boundary is encoded. Existing code can make that interpretation harder. An agent may copy a familiar pattern that was approved before, even when the architectural assumption that once made it safe no longer holds.

In longer sessions, such errors have more time to build on each other. Without clear stop conditions and structural permission boundaries, an agent can keep going in the wrong direction while making changes that look sound on their own. ICLR 2026 Graph-CAD research offers an analogy to code agents through text-to-CAD generation, where flat generation without an explicit structural intermediate representation allows local errors to accumulate and cascade.

How do you give an AI coding agent a codebase map with enforceable boundaries?

Shankara et al. (2026) describe a concrete sequence for grounding generation in system structure. Metadata is extracted from the target system and translated into knowledge graphs that model structural dependencies. An agent traverses the graph to retrieve context across multiple hops, then constructs a constraint-enforcing prompt grounded in that evidence. The agent can reason from explicit relationships rather than rely only on patterns it finds in nearby code.

In this mechanism, generation is conditioned on the prompt, the dependency graph, and retrieved evidence together. The graph specifies valid object-acquisition paths and dependency compositions, making relationships explicit as part of the task. Natural language still has a role. It communicates the requested change, while the structural model defines the relationships that change must respect. The control surface shifts because the prompt no longer has to serve as both instruction and architectural memory.

Grounding and enforcement nevertheless remain distinct functions. A graph-backed prompt gives the agent factual structure, while a machine-checkable constraint establishes whether a proposed change satisfies a declared rule. That distinction prevents an important overclaim. Merely showing an agent a graph does not make its output deterministic. Determinism applies to the evaluation of encoded constraints, such as whether a dependency introduces a cycle or crosses a forbidden boundary.

The Graph-CAD research backs the intermediate representation principle by predicting high-level structure and constraints first, then using that graph to guide generation. This narrows the search space instead of asking generation to discover every relationship while producing executable code. Projectional Decoding, presented at FSE Companion '26, proposes maintaining a partial graph model as the primary artifact representation throughout generation. Each new token refines that model. The proposed framework enables incremental semantic validation, making violations detectable as they form, before a diff is completed.

ContextCov (2026) helps show where this approach works in practice. Dependency cycles, undeclared imports, and explicitly encoded boundary crossings belong to the deterministic class that programmatic checks can evaluate. Responsibility boundaries and long-term architectural tradeoffs still need to be interpreted. A useful codebase map therefore supports both context retrieval and explicit validation, without treating them as interchangeable. Visual navigation can help developers understand the structure, but enforceable rules are what turn that understanding into a control plane.

What happens to teams that skip structural enforcement as agent session depth grows

As sessions touch more files, it gets harder to pin down structural errors in review. A reviewer must assess not only whether each edit looks reasonable, but also whether the combined changes preserve relationships across the system. The diff is a late checkpoint. Large refactors demand an architecture-level pass precisely because locally acceptable edits can combine into a globally invalid result, and manually finding subtle defects in massive pull requests can overwhelm reviewers.

A 2026 arXiv large-codebase case illustrates the consequence. An AI coding agent dismantled a core architectural invariant across scores of files, with neither a test oracle nor human code review available to catch the change. This was not an isolated bad function. The failure crossed enough of the codebase that evaluating individual edits could not substitute for checking the invariant the system was supposed to preserve.

The corrective process separated the agent writing the code from the agent checking it. The checker ran in a fresh session and compared the code against a document frozen before the code existed. That separation supplied an independent reference point. Without structural enforcement, though, catching the error depended entirely on following the process, including keeping the reference unchanged and the checking context independent.

How teams doing this well have implemented structural enforcement in practice

Stripe's “minions” ship a large volume of pull requests weekly from Slack reactions. At that volume, per-pull-request human architectural review is impractical without automated structural enforcement. The production constraint is therefore the surrounding system. This example does not, by itself, establish which graph mechanisms the company uses.

Cisco's spec-driven development reduced an eight-person team to three people supported by five digital agents while tripling output. By the end of 2026, Cisco aims to have six products built entirely with AI, with no human lines of code. The specification supplies a structural prior for the work. This is a different form of control from an import-graph validator, but it likewise places an explicit contract ahead of generation rather than relying on review to reconstruct intent afterward.

GitHub Copilot Code Review reached general availability in March 2026, with agent skills and MCP reaching general availability in July 2026. Its reviews address architectural effects, pattern violations, and cross-cutting concerns. However, architectural commentary and deterministic enforcement are different guarantees, because a review can identify a concern without establishing that every encoded dependency rule has passed.

lastminute.com enforces its rules with dependency-cruiser, which statically analyzes import graphs and fails the build when a change breaks architectural rules. It uses danger.js to surface those violations as actionable comments on merge requests. The rule has an executable consequence. Developers receive feedback in the review workflow, but acceptance depends on the build check rather than on whether someone notices the dependency in a diff.

The open-source project morshoto/framekit opened a CI issue in October 2026 to replace text-pattern checks with an import-aware, cycle-aware policy that would be enforced on production entrypoints. The proposed policy requires the current valid production graph to pass, while dependency cycles and undeclared package imports must fail. This change remains at the proposal stage. Its specificity shows the project-level enforcement model, where the validator evaluates actual dependency relationships rather than searching source text for suggestive patterns.

The legitimate objections to graph constraints and where they actually apply

The strongest objection is that architectural quality exceeds what a graph validator can decide. Contextual interpretation, responsibility allocation, long-term maintainability, and tradeoffs between otherwise valid designs remain open to judgment. Executable guardrails handle only part of the supervision load. A change can satisfy every declared dependency rule and still be a poor design, so passing graph checks cannot stand in for human oversight of the interpretive class.

Enforcement must evaluate dependency data generated from the exact source revision under test, because a stale committed graph cannot establish the validity of changed code. Regeneration adds latency at CI gates. Teams with fast deploy cycles have a legitimate reason to scrutinize that cost, but making regeneration optional would weaken the check itself. The required response is to make current dependency data part of the CI contract.

Over-constraining generation can also reduce quality on dimensions the constraints do not describe. Naive constrained decoding may narrow the generation space so much that the model produces worse code even though it meets the specified restrictions. More constraints are not automatically better controls. The appropriate boundary is to enforce architectural requirements while leaving implementation choices to the model where those choices do not violate the contract.

A current graph cannot resolve an unencoded design dispute, and a validator cannot judge a tradeoff merely because its inputs are structured. Those limitations leave substantial work for developers. Within the deterministic class, however, graph enforcement can catch violations early, automatically, and with zero ambiguity about whether a declared rule passed.

What the developer's role becomes when the graph is the control surface

The developer's leverage shifts from correcting individual agent outputs to defining the boundaries that future outputs must respect. Amazon's October 2026 SDE guideline frames the developer role and its output as not defined by the use of AI. The relevant contribution is the constraint envelope. In graph-constrained work, that envelope includes module boundaries, permitted dependency directions, and disallowed cycles expressed in a form the build system can evaluate.

Cisco's model emphasizes specifications, framekit's proposed checks make dependency policy executable, and Anthropic's recommendation for a second-agent checker separates generation from verification. None removes the need for system design. Instead, architects and senior engineers concentrate on constraints and context engineering, including deciding what can be checked mechanically and what needs an independent judgment.

The practical workflow is to map the repository, define the constraints that must hold, and run enforcement in CI so violations block merges. The command sequence in the notes uses gr init to map the repository, constraints defined on the graph, and gr check in CI to enforce them. Architecture then becomes a versioned contract that exits non-zero when violated, rather than a diagram or prompt whose authority depends on the next agent interpreting it correctly.

Sources

  1. Published as a conference paper at ICLR 2026
  2. "Graph-Constrained Code Generation for Deep Metadata Environments" by Pradeep Shankara, Anil Nagalla et al.
  3. Projectional Decoding: Towards Semantic-Aware LLM Generation
  4. The Alignment Problem in Constrained Code Generation
  5. Codified Context: Infrastructure for AI Agents in a Complex Codebase
  6. ContextCov: Deriving and Enforcing Executable Constraints from Agent Instruction Files
  7. Architectural Guardrails for AI-Generated Code
Filed underAgent Workflows

More in Agent Workflows