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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Enterprise Contract Guardian β training LLMs to reason about API blast radius
|
| 2 |
+
|
| 3 |
+
> This is the public mini-blog/writeup for our OpenEnv Hackathon submission.
|
| 4 |
+
|
| 5 |
+
*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.*
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## TL;DR
|
| 10 |
+
|
| 11 |
+
We built **Enterprise Contract Guardian**, an OpenEnv environment that trains LLM agents to reason about API contract blast radius across microservices.
|
| 12 |
+
|
| 13 |
+
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.
|
| 14 |
+
|
| 15 |
+
The agent learns to:
|
| 16 |
+
|
| 17 |
+
- detect API contract violations,
|
| 18 |
+
- trace which downstream services break,
|
| 19 |
+
- propose backward-compatible fixes,
|
| 20 |
+
- and verify that the fix does not cascade into another outage.
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## Who this is for
|
| 25 |
+
|
| 26 |
+
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.
|
| 27 |
+
|
| 28 |
+
By the end, you should understand:
|
| 29 |
+
|
| 30 |
+
- what the environment simulates,
|
| 31 |
+
- what actions the agent can take,
|
| 32 |
+
- how the reward signal teaches the behavior,
|
| 33 |
+
- what we trained with GRPO,
|
| 34 |
+
- and where the trained model improved.
|
| 35 |
+
|
| 36 |
+
## What we built
|
| 37 |
+
|
| 38 |
+
We built a hosted OpenEnv environment called **Enterprise Contract Guardian**.
|
| 39 |
+
|
| 40 |
+
Live environment: https://huggingface.co/spaces/pushpam14/api-contract-validator
|
| 41 |
+
Trained adapter: https://huggingface.co/pushpam14/api-contract-validator-grpo-7b
|
| 42 |
+
Training run: https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/runs/gch0eg3k
|
| 43 |
+
Source code: https://github.com/kumarpushpam17-personal/Hackathon
|
| 44 |
+
GitHub README: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/README.md
|
| 45 |
+
|
| 46 |
+
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.
|
| 47 |
+
|
| 48 |
+
## The story in 30 seconds
|
| 49 |
+
|
| 50 |
+
It is Friday evening. A backend engineer makes what looks like a small API cleanup:
|
| 51 |
+
|
| 52 |
+
```diff
|
| 53 |
+
{
|
| 54 |
+
- "email": "user@example.com"
|
| 55 |
+
+ "email_address": "user@example.com"
|
| 56 |
+
}
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
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.
|
| 60 |
+
|
| 61 |
+
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.
|
| 62 |
+
|
| 63 |
+
## 1) Theme fit: World Modeling / Professional Tasks
|
| 64 |
+
|
| 65 |
+
This submission targets **Theme #3.1: World Modeling β Professional Tasks**.
|
| 66 |
+
|
| 67 |
+
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.
|
| 68 |
+
|
| 69 |
+
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.
|
| 70 |
+
|
| 71 |
+
## 2) Environment design
|
| 72 |
+
|
| 73 |
+
An OpenEnv environment with three phases that mirror what a senior platform engineer actually does:
|
| 74 |
+
|
| 75 |
+
1. **Detect** β find the contract violation
|
| 76 |
+
2. **Trace** β identify which downstream consumers break (the "blast radius")
|
| 77 |
+
3. **Fix & verify** β propose a backward-compatible migration and validate it against every consumer's spec
|
| 78 |
+
|
| 79 |
+
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). 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.
|
| 80 |
+
|
| 81 |
+
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.
|
| 82 |
+
|
| 83 |
+
### Agent interface
|
| 84 |
+
|
| 85 |
+
The agent interacts through normal OpenEnv-style calls:
|
| 86 |
+
|
| 87 |
+
- `reset(task_name, seed)` starts a task episode,
|
| 88 |
+
- `state()` returns the current observation,
|
| 89 |
+
- `step(action)` submits an action and receives reward,
|
| 90 |
+
- `close()` ends the session.
|
| 91 |
+
|
| 92 |
+
The action space is intentionally small and inspectable: report a violation, trace an impacted consumer, propose a fix, or mark the task done. This keeps the environment easy to run while still requiring non-trivial reasoning.
|
| 93 |
+
|
| 94 |
+
## 3) Reward signal β composable rubrics, 14 independent components
|
| 95 |
+
|
| 96 |
+
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.
|
| 97 |
+
|
| 98 |
+
```text
|
| 99 |
+
Phase 1 (detection): correct +1.0 | proximity +0.3 | duplicate -0.1 | false positive -0.3 | hint -0.5 | done bonus
|
| 100 |
+
Phase 2 (tracing): correct consumer +0.8 | missed -0.5 | false flag -0.4 | unknown service -0.2
|
| 101 |
+
Phase 3 (fix): fix passes ALL consumers +2.0 | breaks consumer -1.0 | malformed -0.5 | unacceptable strategy -0.3
|
| 102 |
+
Cross-cutting: malformed action -0.2 | spam (>3Γ violations) -1.0
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
14 signals, all independent, hard to game without actually solving the task.
|
| 106 |
+
|
| 107 |
+
## 4) Training setup β GRPO via TRL + Unsloth
|
| 108 |
+
|
| 109 |
+
We trained Qwen2.5-7B-Instruct (4-bit) with LoRA r=16 for 300 GRPO steps on a single Hugging Face Jobs L4 GPU.
|
| 110 |
+
|
| 111 |
+
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.
|
| 112 |
+
|
| 113 |
+
[Public WandB run: `grpo-7b-l4-300steps-v3`](https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/runs/gch0eg3k)
|
| 114 |
+
|
| 115 |
+
## 5) Results
|
| 116 |
+
|
| 117 |
+
We compared three configurations, all at the same inference temperature (0.7):
|
| 118 |
+
|
| 119 |
+
| Task | Qwen-72B | Qwen-7B | **Qwen-7B + LoRA** |
|
| 120 |
+
|---|---:|---:|---:|
|
| 121 |
+
| `find_type_mismatches` | 0.75 | 0.75 | 0.75 |
|
| 122 |
+
| `validate_nested_objects` | 0.99 | 0.57 | 0.57 |
|
| 123 |
+
| **`detect_breaking_changes`** | **0.01** | **0.01** | **0.67** |
|
| 124 |
+
| `validate_response_schema` | 0.99 | 0.70 | 0.30 |
|
| 125 |
+
| `validate_cross_field_constraints` | 0.99 | 0.43 | 0.29 |
|
| 126 |
+
| `validate_auth_request` | 0.99 | 0.83 | 0.33 |
|
| 127 |
+
| `trace_downstream_blast_radius` | 0.67 | 0.99 | 0.99 |
|
| 128 |
+
| `propose_backward_compat_fix` | 0.99 | 0.99 | 0.99 |
|
| 129 |
+
| `multi_service_cascade_fix` | 0.99 | 0.99 | 0.99 |
|
| 130 |
+
|
| 131 |
+
**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**.
|
| 132 |
+
|
| 133 |
+
That is **+66 percentage points on a task where pure scale gave nothing.** This is RL training value, isolated from model size.
|
| 134 |
+
|
| 135 |
+
### Training curve and before/after plot
|
| 136 |
+
|
| 137 |
+
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.
|
| 138 |
+
|
| 139 |
+

|
| 140 |
+
|
| 141 |
+

|
| 142 |
+
|
| 143 |
+
## 6) The honest trade-off
|
| 144 |
+
|
| 145 |
+
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.
|
| 146 |
+
|
| 147 |
+
## 7) Why this matters
|
| 148 |
+
|
| 149 |
+
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:
|
| 150 |
+
|
| 151 |
+
- **Platform / API gateway teams** β pre-merge contract gates that predict downstream impact
|
| 152 |
+
- **CI/CD pipelines** β automated impact analysis before deploy
|
| 153 |
+
- **API versioning toolchains** β backward-compat migration planning
|
| 154 |
+
|
| 155 |
+
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.
|
| 156 |
+
|
| 157 |
+
## 8) Try it yourself
|
| 158 |
+
|
| 159 |
+
- **Live environment**: https://huggingface.co/spaces/pushpam14/api-contract-validator
|
| 160 |
+
- **Trained adapter**: https://huggingface.co/pushpam14/api-contract-validator-grpo-7b
|
| 161 |
+
- **WandB run**: https://wandb.ai/pushpamsubscriptions-inn/openenv-contract-guardian/runs/gch0eg3k
|
| 162 |
+
- **GitHub**: https://github.com/kumarpushpam17-personal/Hackathon
|
| 163 |
+
- **GitHub README**: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/README.md
|
| 164 |
+
- **Story doc + technical guide**: https://github.com/kumarpushpam17-personal/Hackathon/blob/main/api_contract_validator/ENTERPRISE_CONTRACT_GUARDIAN_STORY.md
|
| 165 |
+
|
| 166 |
+
```bash
|
| 167 |
+
# Try the live environment in 10 seconds
|
| 168 |
+
curl https://pushpam14-api-contract-validator.hf.space/health
|
| 169 |
+
# {"status":"healthy"}
|
| 170 |
+
|
| 171 |
+
curl -X POST https://pushpam14-api-contract-validator.hf.space/reset \
|
| 172 |
+
-H "Content-Type: application/json" \
|
| 173 |
+
-d '{"task_name":"trace_downstream_blast_radius","seed":1}'
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## Final takeaway
|
| 177 |
+
|
| 178 |
+
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.
|
| 179 |
+
|
| 180 |
+
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.
|
| 181 |
+
|
| 182 |
+
## Acknowledgements
|
| 183 |
+
|
| 184 |
+
Built with [`openenv-core`](https://github.com/meta-pytorch/openenv), [`trl`](https://huggingface.co/docs/trl), [`unsloth`](https://github.com/unslothai/unsloth), and the OpenEnv composable rubric pattern. Thanks to Meta PyTorch and Scaler School of Technology for the hackathon, and to the OpenEnv team for the framework.
|