|
| 1 | +--- |
| 2 | +permalink: /18-integration-guide.html |
| 3 | +title: Integration Guide |
| 4 | +--- |
| 5 | + |
| 6 | +# 18. Integration Guide (Brownfield) |
| 7 | +**Reading Time:** 10-12 minutes | **Difficulty:** Intermediate |
| 8 | +**Compiler Version:** 0.1.2 | **Spec Version:** 2.1.3 |
| 9 | + |
| 10 | +This guide focuses on integrating FACET into existing systems without a full rewrite. |
| 11 | + |
| 12 | +## 1. Minimal Insertion Points |
| 13 | + |
| 14 | +### Pattern A: Sidecar Compiler (lowest risk) |
| 15 | + |
| 16 | +- Keep current application flow. |
| 17 | +- Replace prompt assembly function with `fct run` call. |
| 18 | +- Continue using your existing provider client and response validator. |
| 19 | + |
| 20 | +### Pattern B: CI Contract Gate |
| 21 | + |
| 22 | +- Keep runtime unchanged initially. |
| 23 | +- Add `fct build` in CI for all `.facet` contracts. |
| 24 | +- Block merges on contract/type/policy failures. |
| 25 | + |
| 26 | +### Pattern C: Runtime Guard Rollout |
| 27 | + |
| 28 | +- Start in `core` profile for static validation. |
| 29 | +- Move selected flows to `hypervisor` with policy/guard events. |
| 30 | +- Enable strict fail-closed behavior for high-risk operations. |
| 31 | + |
| 32 | +## 2. Migration Plan (Incremental) |
| 33 | + |
| 34 | +1. Inventory 3 high-value prompt flows. |
| 35 | +2. Port them to `.facet` contracts. |
| 36 | +3. Add CI gate: `fct build --input <file>`. |
| 37 | +4. Add runtime call path: `fct run` -> provider. |
| 38 | +5. Enforce schema validation on provider response. |
| 39 | +6. Add bounded retry/fallback policy. |
| 40 | + |
| 41 | +## 3. Cost of Adoption |
| 42 | + |
| 43 | +### Engineering Cost |
| 44 | + |
| 45 | +- Initial contract modeling effort. |
| 46 | +- Host-side response validation and retry policy wiring. |
| 47 | +- Policy/guard setup for Hypervisor flows. |
| 48 | + |
| 49 | +### Runtime Cost |
| 50 | + |
| 51 | +- Additional per-request compile/run overhead. |
| 52 | +- Artifact/telemetry storage if guard provenance is enabled. |
| 53 | + |
| 54 | +### Risk Reduction Value |
| 55 | + |
| 56 | +- Contract errors move left (compile-time). |
| 57 | +- Runtime failures become explicit and classifiable. |
| 58 | +- Guarded operations become auditable. |
| 59 | + |
| 60 | +## 4. Compatibility Strategy |
| 61 | + |
| 62 | +- Keep provider SDKs unchanged. |
| 63 | +- Keep business logic unchanged. |
| 64 | +- Replace only request construction and policy gating layer first. |
| 65 | + |
| 66 | +## 5. Anti-Patterns |
| 67 | + |
| 68 | +- Treating FACET as response truth validator by itself. |
| 69 | +- Skipping host response schema checks. |
| 70 | +- Enabling retries without strict bounds. |
| 71 | +- Using nondeterministic host defaults for policy decisions. |
| 72 | + |
| 73 | +## 6. Recommended “First Week” Checklist |
| 74 | + |
| 75 | +- [ ] Add `fct build` in CI on changed contracts. |
| 76 | +- [ ] Add one production flow via sidecar integration. |
| 77 | +- [ ] Log `document_hash` and `policy_hash` per request. |
| 78 | +- [ ] Add deterministic retry/fallback policy. |
| 79 | +- [ ] Validate post-model response schema in host code. |
| 80 | + |
| 81 | +## 7. Related |
| 82 | + |
| 83 | +- [Execution Model](15-execution-model.html) |
| 84 | +- [Production Scenario](16-production-scenario.html) |
| 85 | +- [Mini Benchmark Report](17-benchmark-report.html) |
0 commit comments