Spaces:
Sleeping
Sleeping
File size: 17,972 Bytes
68e2d3b 5ac6a8d 68e2d3b 6fc3f63 68e2d3b 912886b 82e5dcb c254d67 cd187fa c254d67 68e2d3b 08ad9c8 68e2d3b 08ad9c8 68e2d3b 08ad9c8 68e2d3b 08ad9c8 68e2d3b 08ad9c8 68e2d3b cd187fa 68e2d3b ed332e1 cd187fa ed332e1 68e2d3b 5ac6a8d 68e2d3b cd187fa 68e2d3b 82e5dcb 68e2d3b d9fcb25 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | # Enterprise Contract Guardian β training LLMs to reason about API blast radius
> This is the public mini-blog/writeup for our OpenEnv Hackathon submission.
*Submission to the Meta PyTorch OpenEnv Hackathon Γ Scaler School of Technology Grand Finale (Apr 25β26, 2026). Theme #3.1: World Modeling β Professional Tasks. Scaler AI Labs Bonus Track.*
---
## TL;DR
We built **Enterprise Contract Guardian**, an OpenEnv environment that trains LLM agents to reason about API contract blast radius across microservices.
The key result: both untrained Qwen2.5-72B and untrained Qwen2.5-7B scored **0.01** on `detect_breaking_changes`. After **300 GRPO steps**, Qwen2.5-7B + LoRA scored **0.67** on the same task. This shows the environment taught a targeted capability that model scale alone did not solve.
The agent learns to:
- detect API contract violations,
- trace which downstream services break,
- propose backward-compatible fixes,
- and verify that the fix does not cascade into another outage.
---
## Who this is for
This writeup is for people interested in training LLM agents on realistic professional workflows rather than toy environments. If you care about API reliability, CI/CD gates, platform engineering, OpenEnv environments, or RL training with verifiable reward signals, this is the problem we are targeting.
By the end, you should understand:
- what the environment simulates,
- what actions the agent can take,
- how the reward signal teaches the behavior,
- what we trained with GRPO,
- and where the trained model improved.
## What we built
We built a hosted OpenEnv environment called **Enterprise Contract Guardian**.
Live environment: https://huggingface.co/spaces/pushpam14/api-contract-validator
Primary HF Space writeup: https://huggingface.co/spaces/pushpam14/api-contract-validator/blob/main/BLOG.md
Trained adapter: https://huggingface.co/pushpam14/api-contract-validator-grpo-7b
Training run: https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/reports/Enterprise-Contract-Guardian-GRPO-training-Qwen-7B-LoRA-300-steps---VmlldzoxNjY3MTAxMA?accessToken=3dhumexjta1umyk04rq6dx47iww4t25utt3j0x7063b7pvzzibp8jah29grhlwpb
Source code: https://github.com/kumarpushpam17-personal/Hackathon
GitHub README: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/README.md
The end result is a training environment where an LLM agent interacts with a simulated enterprise API ecosystem and learns to reason about contract changes, downstream consumers, and backward-compatible fixes.
## Reviewer quick path
If you only have a few minutes:
1. Open the live environment: https://huggingface.co/spaces/pushpam14/api-contract-validator
2. Read the headline result in [Section 5](#5-results): `detect_breaking_changes` improves from **0.01 β 0.67** after GRPO.
3. Inspect the two committed plots: reward curve and three-way before/after comparison.
4. Verify training proof: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/results/TRAINING_RUN_PROOF.md
5. Reproduce one live episode with the `curl` command in [Section 8](#8-try-it-yourself).
For full setup, action schema, reward tables, and local run instructions, use the GitHub README: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/README.md
For the deep technical reference (every tool documented, build flow start-to-end, runtime sequence diagrams, decision log for each architecture choice, reproducibility commands): https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/TECHNICAL_ARCHITECTURE.md
## What makes this submission strong
This is not a static prompt benchmark. It is a runnable OpenEnv environment with hidden ground truth, stateful episodes, objective rewards, real training, and public proof artifacts.
| Area | What is included |
|---|---|
| Environment depth | 9 tasks across detection, downstream impact tracing, and backward-compatible fix verification |
| Episode/data mix | Seeded synthetic enterprise API scenarios: OpenAPI specs, payloads, version diffs, consumer service graphs, and migration candidates |
| Reward richness | 14 independent reward signals covering correct findings, proximity, duplicates, false positives, missed consumers, malformed patches, broken consumers, and anti-spam |
| Training evidence | 300 GRPO steps on Qwen2.5-7B + LoRA, public WandB report, reward curve, training state JSON, full logs, and trained adapter on Hugging Face |
| Before/after evaluation | Three-way comparison: untrained Qwen2.5-72B, untrained Qwen2.5-7B, and trained Qwen2.5-7B + LoRA |
The environment uses generated, deterministic scenarios rather than a scraped external dataset. That is intentional: every episode has known ground truth, which makes the reward signal auditable and lets judges reproduce the same task with a fixed `seed`.
## The story in 30 seconds
It is Friday evening. A backend engineer makes what looks like a small API cleanup:
```diff
{
- "email": "user@example.com"
+ "email_address": "user@example.com"
}
```
The producer service deploys successfully because its own tests pass. By Monday morning four downstream teams are paged: Orders cannot attach customer emails to receipts, Billing cannot send invoices, Notifications goes silent, Analytics quietly drops a field. The bug was not "the API changed." The bug was that **nobody traced who depended on that field** and nobody proposed a migration the old consumers could survive.
Today's LLMs are great at spotting individual schema violations. They are not great at reasoning across a microservice graph and producing migration patches that keep every consumer running. There is no RL benchmark for this. So we built one.
## 1) Theme fit: World Modeling / Professional Tasks
This submission targets **Theme #3.1: World Modeling β Professional Tasks**.
The environment simulates a partially observable enterprise API ecosystem. The agent sees OpenAPI specs, example payloads, consumer dependencies, and step feedback. It does not directly see the ground-truth blast radius. It must infer which consumers depend on which fields, update its belief after every action, and choose fixes that pass validation against every consumer contract.
This is not a static benchmark or a prompt-only eval. The training loop calls the environment's real `reset`, `step`, and `state` interfaces. Rewards come from the environment's own grader.
## 2) Environment design
An OpenEnv environment with three phases that mirror what a senior platform engineer actually does:
1. **Detect** β find the contract violation
2. **Trace** β identify which downstream consumers break (the "blast radius")
3. **Fix & verify** β propose a backward-compatible migration and validate it against every consumer's spec
Each episode places the agent inside a simulated enterprise (3β5 microservices, each owning an OpenAPI spec, each declaring which fields it consumes from upstream):
```text
Enterprise Service Graph (one of two cascade scenarios)
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β UserService β ββββββΆ β OrdersService β ββββββΆ βBillingServiceβ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββ ββββββββββββββββββββ
βNotificationsSvc β β AnalyticsETL β
βββββββββββββββββββββ ββββββββββββββββββββ
```
When the producer ships a breaking change, the agent has to figure out who breaks β but the ground-truth answer is hidden. The agent must reason from the consumer declarations.
Then the agent has to propose a fix. Five backward-compat strategies are accepted: `field_alias`, `version_bump`, `deprecation_window`, `dual_write`, `consumer_patch`. The fix is validated against every consumer in the graph. If even one consumer would still break, the agent gets penalized.
### The 9 tasks at a glance
| Task | Phase | Tests |
|---|:-:|---|
| `find_type_mismatches` | 1 | Top-level type/missing/enum violations (4 violations, 12-pool seed variance, 495 combos) |
| `validate_nested_objects` | 1 | Deep nested-path traversal (7 violations, 2 scenario variants) |
| `detect_breaking_changes` | 1 | v1 β v2 spec diff: removed/renamed fields, narrowed enums, type changes (9 violations) |
| `validate_response_schema` | 1 | Subtle format/pattern/range/enum errors in responses (10 violations, 2 variants) |
| `validate_cross_field_constraints` | 1 | Arithmetic + date ordering + conditional rules across fields (7 violations) |
| `validate_auth_request` | 1 | OAuth2/API-key constraints, MFA patterns, IP format, rate limits (6 violations, 2 variants) |
| `trace_downstream_blast_radius` | 2 | Identify every consumer broken by a producer API change |
| `propose_backward_compat_fix` | 3 | Propose a migration patch that validates against all consumer specs |
| `multi_service_cascade_fix` | 2+3 | Full workflow: trace β fix β verify in one episode |
### Agent interface
The agent interacts through normal OpenEnv-style calls (`reset`, `step`, `state`, `close`). The action space is intentionally small and inspectable: report a violation (Phase 1), trace impacted consumers (Phase 2), or propose/validate a fix (Phase 3). Full action and observation schemas are in the [GitHub README](https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/README.md#action-space).
## 3) Reward signal β composable rubrics, 14 independent components
The reward is not a single pass-fail score. It is an OpenEnv Rubric composed of fourteen independent signals β correct violations, correct consumers, missed consumers, false flags, malformed patches, broken consumers, anti-spam, and more. Each is logged separately so we can see exactly which signal drives training.
```text
Phase 1 (detection): correct +1.0 | proximity +0.3 | duplicate -0.1 | false positive -0.3 | hint -0.5 | done bonus
Phase 2 (tracing): correct consumer +0.8 | missed -0.5 | false flag -0.4 | unknown service -0.2
Phase 3 (fix): fix passes ALL consumers +2.0 | breaks consumer -1.0 | malformed -0.5 | unacceptable strategy -0.3
Cross-cutting: malformed action -0.2 | spam (>3Γ violations) -1.0
```
14 signals, all independent, hard to game without actually solving the task.
## 4) Training setup β GRPO via TRL + Unsloth
We trained Qwen2.5-7B-Instruct (4-bit) with LoRA r=16 for 300 GRPO steps on a single Hugging Face Jobs L4 GPU.
The important detail: the reward function is the **environment's own grader**, called step by step. This is not supervised fine-tuning on a static dataset. The model samples actions, sends them to the OpenEnv environment, receives reward, and GRPO updates the LoRA adapter from that feedback.
[Public WandB report: `grpo-7b-l4-300steps-v3`](https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/reports/Enterprise-Contract-Guardian-GRPO-training-Qwen-7B-LoRA-300-steps---VmlldzoxNjY3MTAxMA?accessToken=3dhumexjta1umyk04rq6dx47iww4t25utt3j0x7063b7pvzzibp8jah29grhlwpb)
## 5) Results
We compared three configurations, all at the same inference temperature (0.7):
| Task | Qwen-72B | Qwen-7B | **Qwen-7B + LoRA** |
|---|---:|---:|---:|
| `find_type_mismatches` | 0.75 | 0.75 | 0.75 |
| `validate_nested_objects` | 0.99 | 0.57 | 0.57 |
| **`detect_breaking_changes`** | **0.01** | **0.01** | **0.67** |
| `validate_response_schema` | 0.99 | 0.70 | 0.30 |
| `validate_cross_field_constraints` | 0.99 | 0.43 | 0.29 |
| `validate_auth_request` | 0.99 | 0.83 | 0.33 |
| `trace_downstream_blast_radius` | 0.67 | 0.99 | 0.99 |
| `propose_backward_compat_fix` | 0.99 | 0.99 | 0.99 |
| `multi_service_cascade_fix` | 0.99 | 0.99 | 0.99 |
**The headline**: on `detect_breaking_changes`, both untrained models β including the **10Γ larger 72B** β score 0.01. They earn the +0.3 proximity reward repeatedly (they know *where* the breaking change is) but never predict `violation_type='breaking_change'` correctly. After 300 GRPO steps targeting our environment's reward, the trained 7B+LoRA scores **0.67**.
That is **+66 percentage points on a task where pure scale gave nothing.** This is RL training value, isolated from model size.
### Training curve and before/after plot
The training curve and three-way before/after comparison are committed in the GitHub repo so reviewers do not need access to a local notebook.


### Proof and artifacts
The training run is backed by public, reproducible artifacts:
| Artifact | Link |
|---|---|
| Public WandB report | https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/reports/Enterprise-Contract-Guardian-GRPO-training-Qwen-7B-LoRA-300-steps---VmlldzoxNjY3MTAxMA?accessToken=3dhumexjta1umyk04rq6dx47iww4t25utt3j0x7063b7pvzzibp8jah29grhlwpb |
| Training proof summary | https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/results/TRAINING_RUN_PROOF.md |
| Full training log | https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/results/training_full_log.txt |
| Training state JSON | https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/results/training_state.json |
| Trained scores | https://github.com/kumarpushpam17-personal/Hackathon/blob/main/trained_scores.json |
| 7B baseline scores | https://github.com/kumarpushpam17-personal/Hackathon/blob/main/baseline_7b_scores.json |
| 72B baseline scores | https://github.com/kumarpushpam17-personal/Hackathon/blob/main/baseline_72b_v2_scores.json |
| Trained LoRA adapter | https://huggingface.co/pushpam14/api-contract-validator-grpo-7b |
## 6) The honest trade-off
GRPO heavily reinforced the high-reward action patterns from training (Phase 2/3 episodes give +2.0 fix rewards vs Phase 1's +1.0 per violation). The trained model now over-applies these patterns to Phase 1 tasks where they don't fit, causing regressions on `validate_response_schema`, `validate_cross_field_constraints`, and `validate_auth_request`. With task-balanced training and a "don't repeat" reward signal, this would close. But the headroom-task win is real and reproducible.
## 7) Why this matters
API contract violations are the **#1 cause of production incidents in microservice architectures**. Every platform team deals with this weekly. Three groups benefit from an agent trained on this environment:
- **Platform / API gateway teams** β pre-merge contract gates that predict downstream impact
- **CI/CD pipelines** β automated impact analysis before deploy
- **API versioning toolchains** β backward-compat migration planning
There is no existing RL benchmark for multi-service contract reasoning. This is genuinely a publishable artifact β researchers training LLMs for enterprise workflows now have a benchmark to compete on.
## 8) Try it yourself
- **Live environment**: https://huggingface.co/spaces/pushpam14/api-contract-validator
- **Primary HF Space writeup**: https://huggingface.co/spaces/pushpam14/api-contract-validator/blob/main/BLOG.md
- **Trained adapter**: https://huggingface.co/pushpam14/api-contract-validator-grpo-7b
- **WandB report**: https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/reports/Enterprise-Contract-Guardian-GRPO-training-Qwen-7B-LoRA-300-steps---VmlldzoxNjY3MTAxMA?accessToken=3dhumexjta1umyk04rq6dx47iww4t25utt3j0x7063b7pvzzibp8jah29grhlwpb
- **GitHub**: https://github.com/kumarpushpam17-personal/Hackathon
- **GitHub README**: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/README.md
- **Story doc + technical guide**: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/ENTERPRISE_CONTRACT_GUARDIAN_STORY.md
- **Technical architecture (deep)**: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/TECHNICAL_ARCHITECTURE.md
```bash
# Try the live environment in 10 seconds
curl https://pushpam14-api-contract-validator.hf.space/health
# {"status":"healthy"}
curl -X POST https://pushpam14-api-contract-validator.hf.space/reset \
-H "Content-Type: application/json" \
-d '{"task_name":"trace_downstream_blast_radius","seed":1}'
```
## Final takeaway
The important result is not that one model became better at every task. It did not. The important result is narrower and more useful: an OpenEnv reward signal taught a 7B model a specific enterprise reasoning behavior that neither the untrained 7B nor the much larger 72B model could perform.
That is exactly why this environment matters. It creates a repeatable training loop for API blast-radius reasoning: detect the contract break, trace affected consumers, propose a migration, and verify the result.
## Acknowledgements
Built with [`openenv-core`](https://github.com/meta-pytorch/openenv), [`trl`](https://huggingface.co/docs/trl), [`unsloth`](https://github.com/unslothai/unsloth), Hugging Face Spaces, Hugging Face Jobs, Hugging Face Hub, and the OpenEnv composable rubric pattern.
Thanks to Meta PyTorch and Scaler School of Technology for the hackathon, Hugging Face for the hosting/training infrastructure, and the OpenEnv team for the framework.
|