ContextCov: Deriving and Enforcing Executable Constraints from Agent Instruction Files
Organizations: University of Washington Seattle, Washington, USA
Abstract
As Large Language Model (LLM) agents increasingly execute complex, autonomous software engineering tasks, developers rely on natural language instruction files such as AGENTS.md to express project-specific coding conventions, tooling restrictions, and architectural boundaries. However, because these instructions remain passive text, agents frequently violate documented constraints due to context window saturation or conflicting local context. In autonomous settings without real-time human supervision, such violations rapidly compound into technical debt. To ground autonomous agents in repository constraints, we introduce ContextCov, a framework that transforms passive natural language instructions into executable guardrails. Unlike prompt-only or reflection-only compliance approaches, ContextCov compiles documented constraints into three complementary checks: static AST queries for code patterns, runtime shell shims that intercept prohibited commands, and architectural validators that enforce structural rules. Acting as an automated, continuous reviewer, ContextCov intercepts agent actions and returns immediate, reproducible violation traces, enabling self-correction before non-compliant changes are finalized. We evaluate ContextCov on SWE-bench Lite (12 repositories, 300 tasks). Compared to prompt-only and LLM reflection baselines, ContextCov achieves 88.3% constraint compliance (vs. 67.0% and 50.3%) with 3.4x lower feedback cost, while maintaining functional correctness. The source code and evaluation results are available at https://github.com/reSHARMA/ContextCov.
Figures & tables
| Extraction & Synthesis (RQ1) | Harness Resolution (RQ3) | ||||||||||||
| Repository | Lines | Seg. | Src | Proc | A-D | A-S | Chk | Van. | % | LR | CC | ||
| astropy | 151 | 54 | 25 | 17 | 15 | 12 | 69 | 6 | 3 | 50 | 3 | 2 | |
| django | 110 | 61 | 35 | 22 | 5 | 11 | 73 | 114 | 68 | 60 | 70 | 77 | |
| matplotlib | 157 | 71 | 30 | 24 | 20 | 9 | 83 | 23 | 8 | 35 | 10 | 9 | |
| seaborn | 106 | 44 | 15 | 23 | 13 | 0 | 51 | 4 | 2 | 50 | 2 | 2 | 0 |
| flask | 102 | 52 | 25 | 38 | 15 | 1 | 79 | 3 | 1 | 33 | 1 | 1 | 0 |
| Oracle Compliance & Feedback Rounds | Post-hoc LLM Critic | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Method | Clean | Rate | Avg. viol. | Rounds | Rnds | Hit cap | Patch source | Clean | Avg. | Total | |
| ContextCov | 265 | 88.3% | 0.14 | 1.67 | 1.31 | 29 (10%) | ContextCov finals | 30.1% (88/292) | 292 | 1.15 | 336 |
| Vanilla | 201 | 67.0% | 0.62 | — | — | — | Vanilla finals | 29.2% (87/298) | 298 | 1.15 | 344 |
| LLM Reflection | 151 | 50.3% | 1.01 | 2.85 | 2.30 | 85 (28%) | LLM Refl. finals | 50.3% (151/300) | 300 | 1.01 | 304 |
| Method | Resolved | Rate | vs Van. | vs other FB | Unique |
| ContextCov | 172 | 57.3% | +22 | +32 | 9 |
| LLM Reflection | 157 | 52.3% | +23 | +17 | 10 |
| Vanilla | 159 | 53.0% | — | +25 | 2 |
| McNemar paired tests (discordant cells: A only / B only) | |||||
| Vanilla vs. ContextCov : 9 / 22 | |||||
| Vanilla vs. LLM Reflection: 25 / 23 | |||||
| Method | Oracle | Pass | Fail | Total |
|---|---|---|---|---|
| ContextCov | Clean | 156 | 109 | 265 |
| Dirty | 16 | 19 | 35 | |
| LLM Refl. | Clean | 85 | 66 | 151 |
| Dirty | 72 | 77 | 149 | |
| Vanilla | Clean | 110 | 91 | 201 |
| Dirty | 49 | 50 | 99 |
| Metric | Method | Mean | Sum |
|---|---|---|---|
| LLM input chars | LLM Refl. | 19,455 | 5.84M |
| ContextCov | 6,292 | 1.89M | |
| Feedback time (s) | LLM Refl. | 133.7 | 40,110 |
| ContextCov | 27.7 | 8,310 | |
| Mean | Median | ||
| End-to-end (s) | LLM Refl. | 461.4 | 379.2 |
Runtime Enforcement for AI Agents
Runtime enforcement for AI agents checks and constrains actions as they execute, helping prevent unsafe or unauthorized effects.
See all 273 papers