How swordboom/supplai works
1. Overall shape
- SupplAI is a Streamlit-based decision support app centered on a single inference pipeline in app.py.
- It combines rule-based parsing, graph simulation, ML scoring, explainability, anomaly detection, and LLM-generated briefs/agent actions into one dashboard.
2. Primary runtime boundary
- app.py is the main orchestration layer and UI entry point.
- The README’s core flow is: parse disruption → run cascade → score nodes → find alternates → compute SHAP → generate brief → score anomalies → run agent.
- This means the app is not just a viewer; it is the orchestration boundary for all analytical subsystems.
3. Supply network and cascade analytics
- src/graph_builder.py, src/cascade_model.py, and src/material_flow.py appear to form the network-simulation core.
- These modules likely build the supply-chain graph, propagate disruption effects downstream, and model material movement/exposure across nodes and routes.
- This subsystem is the main “system dynamics” layer feeding risk and rerouting.
4. Risk scoring and delay prediction
- src/risk_scoring.py and src/delay_model.py provide node-level risk estimation.
- The README says the delay model is a major component of composite risk, so risk scoring is a blend of graph-derived signals + ML delay probability.
- Trained model artifacts live in models/ and are loaded by the inference app rather than retrained at runtime.
5. Rerouting and exposure validation
- src/reroute.py is the decision-support layer for alternate path finding.
- It likely consumes the graph/cascade outputs and checks whether a candidate route reduces exposure to the active disruption.
- This is a distinct operational boundary from risk scoring: risk identifies impacted nodes; rerouting proposes mitigation.
6. Disruption ingestion and normalization
- src/disruption_input.py is the entry point for turning heterogeneous events into a common disruption format.
- Supporting feeds are split across src/news_fetcher.py, src/weather_monitor.py, and src/ofac_fetcher.py.
- The README also mentions earthquakes from USGS and news extraction from RSS, so this subsystem normalizes manual input, live feeds, and keyword fallbacks into one event schema.
7. External data services
- The app integrates with several external sources when configured:
- Gemini and Groq for LLM-driven parsing, briefs, and agent reasoning.
- OpenWeather/Open-Meteo for weather disruption signals.
- USGS for earthquakes.
- RSS/news sources for live disruption headlines.
- GCS / Vertex AI via src/gcs_utils.py and cloud-related env vars for managed artifact loading/deployment.
- These are optional by design; the README notes deterministic fallbacks when API keys are absent.
8. Explainability and anomaly detection
- src/shap_explain.py provides model explainability for the delay/risk model using SHAP.
- src/anomaly_detector.py and the persisted models/anomaly_model.pkl support shipment anomaly scoring, likely at a city or shipment-feature level.
- In the dashboard, these are separate user-facing analyses: one explains why risk is high, the other flags unusual shipment behavior.
9. LLM-generated summaries and agent behavior
- src/llm_brief.py generates executive summaries/ops briefs.
- src/supply_chain_agent.py implements an autonomous or semi-autonomous action planner, likely using tool-calling and the outputs of the other subsystems.
- src/historical_rag.py suggests retrieval over prior incidents or internal knowledge to ground LLM outputs in historical context.
10. Data and artifact layout
- The repository separates training data, reference data, and serialized artifacts:
- datasets/ contains source datasets used for training and evaluation.
- data/ contains supporting reference files like sanctions, tariffs, and supply-chain data.
- models/ stores persisted pickle models used by the app.
- This separation makes the runtime app mostly read-only and artifact-driven.
11. Training and optimization pipeline
- train_models.py is the main model-building workflow and writes sanity/evaluation outputs.
- optimize_models.py experiments with optimized model variants.
- generate_dataset.py and generate_tariffs.py are data-prep utilities for synthetic/global inputs.
- This training boundary is separate from the dashboard runtime and is designed to refresh artifacts consumed by app.py.
12. Deployment and operational packaging
- Dockerfile packages the app for containerized Streamlit execution.
- cloudbuild.yaml wires the repo for Google Cloud Build, Artifact Registry, and Cloud Run deployment.
- The presence of .devcontainer and .env.example shows the repo is built for reproducible local development and cloud deployment with optional secret injection.
13. How to draw the architecture
- A clean diagram would show:
- User/UI layer: Streamlit dashboard in app.py
- Analytical services: graph/cascade, risk scoring, rerouting, SHAP, anomaly detection, LLM brief/agent
- Ingestion layer: manual disruption input plus news/weather/earthquake/OFAC feeds
- Artifact/data layer: datasets/, data/, models/
- External services: Gemini, Groq, OpenWeather, USGS, RSS, GCS/Vertex
- The key directional flow is from event ingestion → normalization → graph impact simulation → risk/mitigation/explanation outputs, with LLMs and anomaly detection as parallel enrichments.
Main entry points: risk_scoring.py Risk · app.py App · models Models · graph_builder.py Graph
Components 26
UI Runtime
Streamlit app entrypoint and orchestration boundary
- App · Main dashboard and orchestration layer for the end-to-end inference flow
app.py
Ingestion
Disruption normalization and external signal feeds
- Normalize · Converts manual and live disruption inputs into a common event format
src/disruption_input.py - News · Fetches disruption signals from news and RSS-style sources
src/news_fetcher.py - Weather · Pulls weather-based disruption indicators from weather services
src/weather_monitor.py - Sanctions · Loads OFAC and sanctions-related disruption data
src/ofac_fetcher.py
Analytics
Graph simulation, scoring, explanations, and mitigation
- Graph · Builds the supply network used by downstream simulation and scoring
src/graph_builder.py - Cascade · Propagates disruption effects through the supply network
src/cascade_model.py - Flow · Models material movement and exposure across nodes and routes
src/material_flow.py - Risk · Combines graph signals and model outputs into node-level risk
src/risk_scoring.py - Delay ML · Predicts shipment delay probability used by composite risk
src/delay_model.py - Reroute · Finds alternate paths and checks exposure reduction for candidate routes
src/reroute.py - Explain · Produces SHAP-based explanations for model and risk outcomes
src/shap_explain.py - Anomaly · Flags unusual shipment behavior using persisted anomaly models
src/anomaly_detector.py - Brief · Generates executive and operations summaries from analysis outputs
src/llm_brief.py - Agent · Uses tool-like reasoning to recommend operational actions
src/supply_chain_agent.py - RAG · Retrieves prior incidents and context to ground LLM outputs
src/historical_rag.py - Cloud IO · Handles cloud storage and managed artifact access
src/gcs_utils.py
Data & Artifacts
Training data, reference data, and serialized models
- Models · Persisted delay and anomaly models loaded at runtime
models - Training Data · Source datasets used to train and evaluate models
datasets - Reference Data · Supply-chain, sanctions, and tariff reference files
data
Training & Deploy
Model refresh, containerization, and cloud packaging
- Train · Primary workflow for building and evaluating models
train_models.py - Optimize · Builds optimized model variants for deployment
optimize_models.py - Gen Data · Creates synthetic or derived datasets for training and analysis
generate_dataset.py - Tariffs · Generates tariff reference inputs for the dataset layer
generate_tariffs.py - Docker · Containerizes the Streamlit application for runtime deployment
Dockerfile - Cloud Build · Defines cloud build and deployment packaging for the repo
cloudbuild.yaml
Connections 28
- App → Normalize: parse event · Normalizes disruption input before analysis
- App → News: ingest news · Pulls external news signals into the app flow
- App → Weather: ingest weather · Adds weather disruption signals
- App → Sanctions: ingest sanctions · Adds sanctions-related disruption context
- Normalize → Graph: build graph · Creates the network representation used downstream
- Graph → Cascade: simulate impact · Feeds the disruption cascade model
- Graph → Flow: route flow · Provides topology for movement and exposure modeling
- Cascade → Risk: impact features · Supplies propagated disruption signals for scoring
- Flow → Risk: exposure features · Contributes route and node exposure inputs
- Delay ML → Risk: delay score · Provides ML delay probability as a risk component
- Risk → Reroute: mitigate · Uses scored risk to evaluate alternate paths
- Risk → Explain: explain · Explains why the risk score is high
- Risk → Anomaly: analyze anomaly · Pairs risk analysis with shipment anomaly scoring
- Risk → Brief: summarize · Feeds summary generation for executive briefing
- RAG → Brief: ground brief · Adds historical context to generated briefs
- Brief → Agent: inform action · Provides narrative context for agent recommendations
- Risk → Agent: decision inputs · Supplies operational state for action planning
- Cloud IO → Models: load artifacts · Reads persisted models from managed storage when configured
- Models → Delay ML: serve model · Runtime inference artifact for delay prediction
- Models → Anomaly: serve model · Runtime inference artifact for anomaly scoring
- Training Data → Train: train on · Primary training inputs
- Reference Data → Train: enrich training · Adds domain reference context during model building
- Train → Models: write artifacts · Persists trained models for inference
- Optimize → Models: write optimized · Stores tuned model variants
- Gen Data → Training Data: produce data · Generates training and evaluation datasets
- Tariffs → Reference Data: produce tariffs · Creates tariff reference inputs
- Docker → App: package app · Builds the runtime container around the dashboard
- Cloud Build → Docker: build image · Cloud build pipeline packages the container