Adam BlansettSenior Full-Stack & AI Engineer
AI Engineering
11 min read
Adam Blansett

Engineering an AI Freight Control Tower: X12 EDI 214 Tracking, Multi-Constraint Routing, and 409-Gated Carrier Comms

How ai-logistics-coordinator ingests HMAC carrier webhooks and X12 EDI 214 payloads, scores multi-objective carrier lanes, enforces HTTP 409 HITL carrier comms, and reconciles ASN/BOL warehouse shrinkage.

Supply ChainX12 EDI 214Route OptimizationpgvectorCeleryFastAPIAudit Chains

Freight dispatchers and supply chain coordinators work against tight SLA windows where late detention alerts, customs holds, temperature excursions, or warehouse receiving shortages quickly compound into demurrage fees and lost inventory. Worse, allowing an automated agent to email carriers with unverified detention claims or trigger unauthorized re-routes breaks carrier relationships.

In AI Logistics Coordinator Platform (GitHub repository), a Phase 2 FastAPI + async SQLAlchemy 2 control tower and React 18 TypeScript UI unify X12 EDI 214 telemetry, multi-constraint lane optimization, `409 Conflict`-gated carrier communications, and ASN/BOL warehouse reconciliation.

X12 EDI 214 Parsing & HMAC-Verified Carrier Webhooks#

The `tracking/` module ingests both JSON carrier webhooks (verified via `X-Webhook-Signature` HMAC-SHA256 digests) and raw X12 EDI 214 shipment status messages (`B10`, `AT7`, `MS1`, `G62`, `L11`). Standardized status codes feed an exception detector covering `ETA_SLIP`, `DETENTION`, `CUSTOMS_HOLD`, `WEATHER_DISRUPTION`, `PORT_CONGESTION`, and `TEMPERATURE_EXCURSION`, while Celery + Redis periodic workers run SLA breach sweeps and bulk EDI ingestion.

Multi-Constraint Carrier Route Optimization & Operational Memory#

When a lane degrades, `routing/` evaluates active carrier options across five selectable optimization objectives—`BALANCED`, `LOWEST_COST`, `FASTEST_TRANSIT`, `HIGHEST_RELIABILITY`, and `LOWEST_CARBON`—subject to hard reefer, weight, budget, and transit bounds plus live corridor disruption penalties. Resolved exceptions automatically index into L2-normalized operational memory (`memory/`, `pgvector`-ready) so past corridor workarounds inform both lane scoring and dispatcher notes.

409-Enforced Carrier Outbox & ASN/BOL Warehouse Reconciliation#

Every outbound carrier draft in `comms/` cites live BOL/PRO telemetry, open alerts, and operational memory—and enforces a strict `409 Conflict` API guard until dispatcher sign-off:

carrier_outbox_guard.py
if draft.approval_status != "approved":
    raise HTTPException(
        status_code=409,
        detail="Carrier communication requires dispatcher approval before dispatch",
    )
receipt = await delivery_adapter.dispatch(draft)  # simulated | smtp | hmac_webhook
  • Warehouse Shrinkage Reconciliation (`inventory/`): Compares expected ASN/BOL line counts against receiving and damage tallies, computing financial exposure and shrinkage percentages across `SHORTAGE`, `OVERAGE`, `DAMAGED`, and `UNEXPECTED_SKU` alerts.
  • Scoped Machine & Human Auth (`core/`): Enforces HS256 JWT + `X-API-Key` RBAC across `VIEWER`, `WAREHOUSE`, `DISPATCHER`, `WEBHOOK_INGESTOR`, and `ADMIN` with verified actor attribution.
  • Production Hardening: Includes container startup migrations (`backend/entrypoint.sh`), `RateLimitMiddleware`, pure ASGI security headers, optional OpenTelemetry instrumentation, outbound cloud PII scrubbing, and SHA-256 hash-chained `audit_logs` verified at `/api/v1/audit/verify`.
One-Click Workspace Demo: Calling `POST /api/v1/demo/seed` populates 5 shipments, EDI 214 exceptions, 6 carrier lanes, active disruptions, pending outbox drafts, and warehouse alerts so teams can test the entire Control Tower immediately.

Architecting logistics visibility, EDI pipelines, or guarded operational tooling? Review my AI Engineering and Software Architecture services or book a consultation.

Applied Architecture

Production Case Studies & Capabilities

Explore how these engineering patterns are deployed in production systems and available through client engagements.

Case Study

AI Logistics Coordinator Platform

An open-source Python 3.12 (FastAPI), async SQLAlchemy 2 + PostgreSQL/pgvector, and React 18 Control Tower ingesting HMAC carrier webhooks and X12 EDI 214 payloads, optimizing lanes across cost/transit/carbon objectives, gating carrier dispatches behind 409 Conflict approvals, and reconciling ASN/BOL warehouse counts.

Read Case Study
Related Engineering Service

AI Engineering & LLM Integration

Many AI initiatives fail in production due to prompt fragility, high token latency, hallucination risks, and lack of structured evaluation. I bridge the gap between experimental LLM prompts and deterministic software engineering.

Related Engineering Service

Software Architecture & System Design

Fast-moving teams frequently accrue hidden architectural liabilities: tangled domain logic, unmaintainable monoliths, or over-engineered microservices that paralyze development.

Frequently Asked Questions

Which X12 EDI 214 segments does ai-logistics-coordinator parse?
The tracking module parses X12 EDI 214 B10, AT7, MS1, G62, and L11 segments alongside HMAC-SHA256 verified JSON carrier webhooks, normalizing status codes and flagging SLA ETA slips and operational exceptions.
How does the carrier outbox enforce human-in-the-loop review?
Generated carrier escalation drafts grounded in live BOL/PRO telemetry return HTTP 409 Conflict from dispatch endpoints until an authorized dispatcher approves the message, after which it delivers via simulated, SMTP, or HMAC-signed webhook adapters.
How does resolved exception memory improve future routing and comms?
When freight exceptions resolve, the tracking pipeline automatically indexes the resolution into L2-normalized pgvector-ready operational memory, making historical corridor workarounds searchable during future route scoring and draft generation.
Share this technical guide

Need Help Solving This in Your Application?

I partner with founders, executives, and engineering leaders to design architectures, resolve production bottlenecks, and deliver resilient software.

Related Technical Articles