BXUP Track progress & test yourself — free
Forward Deployed AI Engineer · Hands-on lab · ~1 min read
FORWARD DEPLOYED AI ENGINEER · HANDS-ON LAB

Lab 03 · Deterministic LangGraph Agent with Compensating Rollback Actions

Build a production-grade enterprise refund and cancellation agent using LangGraph that replaces fragile prompt loops with deterministic state transitions, idempotency locks, and compensating rollback handlers.

Time & Tier

~150 minutes hands-on · FDE Track, Advanced Engineering difficulty.

The Scenario

An e-commerce client has suffered duplicate payouts because an autonomous agent retried failed HTTP calls. You will construct a stateful LangGraph agent that guarantees: (1) actions over ₹2,000 pause for human approval, (2) all actions carry idempotency keys, and (3) partial failures trigger automated compensating rollback transactions.

Deliverables

  1. agent_graph.py: Compiled LangGraph state machine with conditional routing.
  2. tools.py: Pydantic-validated tool schemas with idempotency keys.
  3. saga_rollback.py: Compensating transaction stack restoring state upon failure.

Step-by-Step Instructions

  1. Install Dependencies:

    pip install langgraph==0.1.4 pydantic==2.8.2
    
  2. Define the Typed State Machine: Model nodes for IntentClassifier, HumanApprovalGate, ReserveInventory, ProcessPayment, and RollbackHandler.

  3. Wire Compensating Actions: In saga_rollback.py, register an undo closure whenever a state mutation succeeds. If any subsequent node throws an unhandled exception, pop and execute the undo closures in reverse order.

  4. Verify It Works: Simulate a network timeout during the payment step. Verify that the agent automatically invokes release_inventory() and leaves the database in a clean, consistent state.

This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in