CFD Gateway Integration
This page explains how the Context Front Door (CFD) integrates technically with the smoltbot gateway. If you are new to CFD, start with the concept overview first.Request Pipeline
CFD runs as Phase 0.5 — after agent identification resolves the agent config and policy, but before quota enforcement or message forwarding. This placement is intentional: the gateway already knows which agent is handling the request (so CFD config can be loaded), but no downstream resources have been consumed yet.Phase-by-Phase Breakdown
Phase 0 — Agent Identification
The gateway resolves theAuthorization header to an agent record and loads the agent’s alignment card, CFD configuration, and policy bundle from KV. If CFD mode is disabled (the default), Phase 0.5 is skipped entirely with no performance cost.
Phase 0.5 — CFD Screening
Behavior depends on the configured mode:- enforce
- observe
- simulate
CFD runs synchronously. The gateway awaits the full L1→L2→L3 verdict before deciding whether to continue.
passorwarn: pipeline continues to Phase 1quarantine: request is stored in the quarantine queue with the full message payload; gateway returnsHTTP 400with body:block: request is dropped; gateway returnsHTTP 403with body:
X-CFD-Verdict header is present on all responses in this mode. For quarantine verdicts, X-CFD-Quarantine-Id contains the entry ID.Phase 1 — Quota Enforcement
Standard token and request quota checks run here. In enforce mode, this phase is only reached by messages that passed CFD screening, so quota is not consumed by quarantined or blocked attempts.Phase 2 — Policy Evaluation
The three-layer policy merge (org → agent → transaction) runs here. CFD operates independently of the policy engine — a message can pass CFD and fail policy, or vice versa.Phase 3 — Forward to AI Provider
The message is forwarded to the configured AI provider (Anthropic, OpenAI, Gemini, etc.). In enforce mode, only messages with a CFDpass or warn verdict reach this stage.
Phase 4 — AIP Conscience Analysis
The streaming response is teed through the AIP analysis pipeline. If CFD scored the inbound message with a non-zero threat score (even if the verdict waspass), that score and the specific threat categories detected are injected into the conscience prompt. This gives AIP additional signal to scrutinize the resulting reasoning.
The enrichment looks like:
KV Caching
CFD configuration and session state are cached in theBILLING_CACHE KV binding (the same binding used for quota state). Cache TTLs:
| Item | TTL |
|---|---|
| CFD agent config | 5 minutes |
| Session risk score | Duration of session (30-min idle expiry) |
| Canary patterns | 5 minutes |
| Quarantine metadata | 72 hours |
BILLING_CACHE binding must be present in wrangler.toml for CFD to operate. If the binding is absent and CFD_ENABLED=true, the gateway logs a warning and skips CFD analysis for all requests.
Pre-emptive Nudge Injection
When a message passes CFD screening but its L2 score is ≥ 0.6, CFD writes a record to theenforcement_nudges table. On the agent’s next request, the gateway’s standard nudge injection logic picks this up and prepends a notice to the system prompt:
Attestation
CFD scores are included in the attestationinputCommitment hash. When proof generation runs for a checkpoint, the hash commits to:
- The message content
- The CFD L1 score, L2 score, and verdict
- The session risk level at time of message
- Whether any canary patterns were matched
Sovereign Agent Template
For agents operating in high-trust, high-risk environments (financial automation, infrastructure management, regulated data handling), the sovereign agent template provides a hardened CFD configuration as a starting point:Environment Requirements
CFD requires the following to be present in the gateway environment:| Requirement | Purpose |
|---|---|
CFD_ENABLED=true | Activates CFD code path (feature flag) |
BILLING_CACHE KV binding | Session state and config caching |
Related
- Context Front Door concept — What CFD is and how the threat categories work
- CFD Quickstart — Enable and test CFD in 5 minutes
- Enforcement Modes — How smoltbot handles downstream violations
- Policy Engine — The parallel policy evaluation system