Playbook: Build a Supply Chain Monitoring Agent

Every morning someone on your procurement team opens the ERP, checks inventory levels against upcoming demand, cross-references inbound shipments, and figures out if anything is going to run out. It takes an hour, it is tedious, and when that person is out sick the check does not happen. This playbook walks you through building an agent that does that check automatically and a sandcastle app that gives the team a live view of supply chain risk, all from inside Claude Desktop or ChatGPT.

What you will build

By the end of this playbook, you will have:

  • Custom tools that connect to your ERP and logistics provider APIs
  • A monitoring agent that runs every morning, checks stock levels against demand forecasts, and identifies items at risk of stockout
  • A sandcastle app that shows current inventory status, inbound shipments, risk alerts, and resolution tracking
  • Slack notifications when the agent finds items that need attention
  • Persistent state that tracks alerts, resolutions, and trends over time

What you need before you start

  • An Assist workspace with an MCP server set up. If you have not created one yet, follow Creating an MCP server.
  • Your AI client connected to the MCP server. See Connect your client.
  • Access credentials for your ERP system's API (inventory, demand forecasts, purchase orders).
  • Access credentials for your logistics provider's API (shipment tracking, estimated delivery dates). If you use multiple carriers, start with the primary one and add others later.
  • A Slack webhook URL or Slack tool configured in Assist for posting alerts.

Step 1: Understand your data

Start a conversation in your AI client and map out what data you have:

"I want to build a supply chain monitoring system. We have two main data sources:

  1. Our ERP at https://erp.internal.company.com/api -- it has inventory levels by SKU and warehouse, demand forecasts by week, and purchase orders with expected delivery dates.

  2. Our logistics provider API at https://api.logistics-provider.com -- it has shipment tracking with estimated arrival dates for inbound inventory.

The goal is to catch items that will run out before the next shipment arrives. Can you help me map out what tools I need?"

Let the AI ask questions. It will want to know things like: How far out do your demand forecasts go? Do you have safety stock thresholds? Are there multiple warehouses? What does a purchase order look like? Answer with as much detail as you have -- you can fill in gaps later.

Step 2: Build the data tools

Start with the tools that read data from your systems:

"Create a tool called 'get_inventory' that takes a SKU or product name and returns current stock quantity, warehouse location, and last replenishment date from our ERP."

"Create a tool called 'get_demand_forecast' that takes a SKU and returns weekly forecasted demand for the next 8 weeks from our ERP."

"Create a tool called 'get_inbound_shipments' that takes a SKU and returns all open purchase orders and inbound shipments with their expected delivery dates and quantities."

"Create a tool called 'track_shipment' that takes a shipment tracking number and returns current status, location, and estimated arrival from our logistics provider."

Test each tool as you go. Pull inventory for a SKU you know. Check the demand forecast. Look up a shipment. Make sure the data makes sense before building on top of it.

Then build the analytical tool that ties everything together:

"Create a tool called 'check_stockout_risk' that takes a SKU and does the following:

  1. Get current inventory level
  2. Get the demand forecast for the next 8 weeks
  3. Get all inbound shipments with ETAs
  4. Calculate week-by-week projected inventory: start with current stock, subtract each week's demand, add inbound quantities on their expected arrival week
  5. Return the SKU, current stock, weekly projections, the first week where stock hits zero (if any), and the nearest inbound shipment that could prevent the stockout
  6. Flag it as 'at risk' if projected stock goes below zero or below safety stock threshold before the next delivery"

This is the core logic your agent will use. Test it thoroughly:

"Run check_stockout_risk for SKU ABC-1234."

"Run it for a SKU you know is well-stocked to make sure it returns 'no risk.'"

"Run it for a SKU with a delayed shipment to make sure it correctly flags the risk."

Step 3: Build the batch check

The agent needs to check all SKUs, not just one:

"Create a tool called 'get_all_active_skus' that returns a list of all SKUs with active demand forecasts from our ERP."

"Create a tool called 'run_full_stockout_check' that calls get_all_active_skus, then runs check_stockout_risk for each one, and returns a summary: total SKUs checked, number at risk, and the list of at-risk items with their details sorted by urgency (earliest projected stockout first)."

Test the full check:

"Run the full stockout check. How many items are at risk?"

Review the results. If the check is too noisy (flagging items that are not really at risk), adjust the thresholds. If it is missing real risks, adjust the forecast horizon or safety stock levels.

Step 4: Build the monitoring agent

Now turn the check into an agent that runs automatically:

"Create a subagent that runs every weekday morning at 7:00 AM. It should:

  1. Run the full stockout check
  2. Compare today's at-risk items to yesterday's (use persistent state to track this)
  3. Identify new risks (items that were not flagged yesterday), resolved risks (items that were flagged but are no longer at risk), and ongoing risks
  4. Post a summary to our #supply-chain Slack channel with:
    • Count of new, ongoing, and resolved risks
    • Details for each new risk: SKU, product name, current stock, projected stockout date, nearest inbound shipment
    • A note for resolved items explaining what changed (new shipment arrived, demand forecast updated, etc.)
  5. Store today's full results in persistent state for tomorrow's comparison"

The agent stores its results in persistent state collections, which means it tracks trends over time. Tomorrow's check compares against today's results. Over weeks, you build a history of supply chain risk that you can analyze.

Test the agent manually first:

"Run the supply chain monitoring agent now so I can see what the output looks like."

Review the Slack message. Adjust the formatting, the thresholds, or the level of detail until the team finds it useful.

Step 5: Build the supply chain dashboard app

The Slack alerts tell the team what needs attention right now. The sandcastle app gives them the full picture and a place to manage responses.

"Build me a sandcastle app for supply chain monitoring. It should have these views:

  1. Risk dashboard: Show all currently at-risk items in a table with SKU, product name, current stock, weekly burn rate, projected stockout date, nearest inbound shipment, and days until stockout. Color-code rows: red for stockout within 7 days, yellow for 7-14 days, green for 14+ days. Show summary counts at the top.

  2. SKU detail: Click a SKU to see a chart of projected inventory over the next 8 weeks (line chart with a red zone below safety stock). Show inbound shipments as markers on the timeline. Show demand forecast as a stacked area.

  3. Alert history: A log of all alerts the agent has generated, with date, SKU, risk level, and resolution status. Team members can mark alerts as 'acknowledged', 'ordered', 'resolved', or 'accepted risk' with notes.

  4. Trends: Charts showing number of at-risk items over time, average days-to-stockout trend, and most frequently flagged SKUs."

Iterate on the app:

"Add a filter bar to the risk dashboard so the team can filter by warehouse, product category, or risk level."

"On the SKU detail page, add a section showing all purchase orders for that SKU with their status and expected delivery dates."

"Add an 'action taken' dropdown to the alert history: reorder placed, expedited shipment, substitute sourced, demand reduced, no action needed. This should update the collection record."

Step 6: Connect the agent to the app

The monitoring agent and the dashboard app should share the same data:

"Make the monitoring agent write its daily results to the same collections the supply chain dashboard reads from. The risk dashboard should show the latest agent run data. The alert history should show every alert the agent has generated."

Now when the agent runs at 7 AM, the dashboard updates automatically. When a team member marks an alert as resolved in the app, the agent's next run will see the resolution and exclude it from the "ongoing" count.

Step 7: Add escalation logic

Not all risks are equal. A potential stockout on your best-selling product is more urgent than one on a slow-moving item:

"Update the monitoring agent to classify risks by severity:

  • Critical: stockout projected within 3 days, or the item accounts for more than 5% of revenue
  • High: stockout projected within 7 days
  • Medium: stockout projected within 14 days
  • Low: stockout projected beyond 14 days

For critical risks, also send a direct message to the procurement lead in Slack, not just the channel post."

"In the dashboard app, add a severity column and let users sort by severity. Show critical items at the top with a banner."

Step 8: Share and iterate

Share the dashboard URL with the procurement and operations teams. The agent runs every morning whether anyone is logged in or not. The Slack alerts reach the team immediately. The dashboard gives them a place to dig deeper and track their responses.

As the system matures, extend it:

"Add a tool that pulls carrier delay reports from our logistics provider. If a carrier has systemic delays, flag all inbound shipments from that carrier as potentially late and recalculate stockout risks."

"Add a weekly summary that the agent posts every Friday: total risks identified this week, average resolution time, top 5 most problematic SKUs, and any trends in lead time changes."

"Create a tool that generates a purchase order recommendation: for each at-risk SKU, calculate the reorder quantity needed to cover demand through the next expected shipment plus safety stock. Format it as a table the procurement team can act on."

What you built

You now have an automated supply chain monitoring system:

  • Tools that connect to your ERP and logistics provider, running securely in Assist
  • A monitoring agent that checks every SKU every morning and alerts the team to stockout risks before they happen
  • A dashboard app where the team tracks risks, logs actions, and monitors trends
  • Persistent state that gives the agent memory -- it knows what changed since yesterday and tracks patterns over weeks
  • Escalation logic that routes critical issues to the right people

The morning inventory check went from one person spending an hour in the ERP to an agent that runs in three minutes and tells the team exactly what needs attention. When that person is out sick, the check still happens. When a new risk emerges at 7:01 AM, the team knows about it by 7:02.

Related guides