Skip to Content
Back to Projects
HITL Guardrails · 8 Storefronts

Sentinel: B2B Vendor Order & Discrepancy Reconciliation Agent

An AI agent that executes B2B procurement workflows end-to-end — navigating vendor portals, validating every price and coupon against business rules, and pausing for human approval on anything high-stakes. It drafts the invoice but never places the order.

Technologies Used

Next.js 16LangGraph.jsPlaywrightGemini 2.5 FlashBullMQRedisPostgreSQLTypeScript

Scope & Context

Founding Engineer project targeting high concurrency, real-time sync, or custom system designs.

Codebase Link

See It In Action

Try the live agent at trysentinel-agent.vercel.app — write a goal like "build a cart with 5 units of Organic Almond Milk and 10 units of Oat Milk, apply SUMMER20, fill the shipping form" and watch it run. For a guided tour through the full flow, including an in-line human approval stop, see the Sentinel walkthrough.

The Problem

Procurement work is repetitive, cross-system, and error-prone. Buyers manually navigate portals, compare prices across stores, re-key orders, and reconcile invoices line by line. Pricing that drifts from a contracted target (e.g. $4.00/unit) goes unnoticed until the invoice arrives, and discount codes silently fail while fallback policies are applied inconsistently.

Naive automation is riskier: an agent that completes orders without guardrails can spend real money on a wrong price. Sentinel fixes this by combining action (it does the clicking and typing), reasoning (it checks each step against business rules), and guardrails (a human approves anything high-stakes before it happens).

The Solution & Architecture

Sentinel is split into two deployable services that communicate over HTTP and SSE. The frontend is stateless and declarative; all automation, LLM orchestration, and browser state live in a long-running worker:

  • LangGraph.js StateGraph orchestration: a plan → execute → extract → validate pipeline with conditional edges for HITL pauses, coupon recovery, and bounded replan retries — replacing a 600-line linear runner.
  • Playwright stealth automation for storefronts like eBay, Amazon, Flipkart, Target, and Best Buy, with HTTP/1.1 navigation to defeat HTTP/2 stream resets on bot-walled stores.
  • Gemini 2.5 Flash for intent classification, goal planning, DOM extraction, and pricing reasoning, with an OpenRouter/Groq/Ollama fallback chain.
  • BullMQ + Redis for job queuing, ephemeral run state, live event pub/sub, and the blocking HITL channel (BLPOP).
  • PostgreSQL for durable runs, approvals, reconciliation reports, and history.

Engineering Deep Dive

Three decisions mattered most for a real, acting AI agent:

  • Human-in-the-loop before high-stakes actions. Any threshold-crossing action (validate → HITL_PENDING) pauses execution and surfaces an ApprovalRequest. The human resolves with Approve & Continue, Override Target, or Abort. The agent never places or submits the final order — it stops at the review/draft screen. This is enforced in the graph, not just the UI.
  • Bot-wall resilience. Myntra and Ajio reset HTTP/2 connections on headless Chromium, crashing runs with net::ERR_HTTP2_PROTOCOL_ERROR. Launching with --disable-http2 forced HTTP/1.1 and eliminated stream resets, while unblocking image resources kept full, crisp product photos in live captures.
  • Site-agnostic direct search resolution. Storefront homepages are popup/captcha mines. Mapping goal text to direct search URLs (_nwk, q, k, st) skips homepages entirely and reduces navigation latency by ~60%.

Failures are recoverable, not silent: a failed coupon emits a RECOVERING state and falls back to the configured policy; a failed step replans (up to 2 retries); live steering applies the operator's instruction at the next step boundary. Every step is recorded as an event with evidence — a live run is a readable timeline, not a black box.

Related Reading: For more on the multi-agent orchestration patterns behind this system, see my post on how I built an AI content factory with RAG and LangGraph.

Quantifiable Metrics

1
Ships goal → cart → validation → invoice draft for 8+ storefronts (eBay, Amazon, Flipkart, Target, Best Buy, Walmart, Myntra, Ajio) from a single plain-English prompt.
2
Zero orders placed without approval — every price-variance, failed-coupon, or policy-override event pauses for a human decision.
3
Reduced navigation latency by ~60% via direct search URL resolution, skipping storefront homepages entirely.
4
Structured output end-to-end: normalized itemized invoices rendered as tables with one-click CSV export and direct product-page links.

Visual Showcase

Screenshots, dashboard metrics, and recorded event videos proving the system running in real-time.

Goal input — describe a procurement task in plain English and set price targets, variance thresholds, discount codes, and a fallback policy.

Goal input — describe a procurement task in plain English and set price targets, variance thresholds, discount codes, and a fallback policy.

Live run — the agent timeline logs every navigation, extraction, and validation step, with browser screenshots and a human-in-the-loop approval dialog.

Live run — the agent timeline logs every navigation, extraction, and validation step, with browser screenshots and a human-in-the-loop approval dialog.

Reconciliation report — flagged discrepancies, human-confirmed items, and a normalized invoice exportable as CSV.

Reconciliation report — flagged discrepancies, human-confirmed items, and a normalized invoice exportable as CSV.