๐ upstream-alert
Monitor global supply chain risks in real-time with AI-powered analysis.
๐ upstream-alert
Give your AI agent eyes on the global supply chain.
upstream-alert is an AI agent skill that monitors supply chain risks in real-time. It aggregates data from 7 global sources, scores risk (0โ100), and generates AI-powered analysis โ all callable as a single tool by your agent.
User โ "Is it safe to order coffee beans from Brazil right now?"
Agent โ [calls upstream-alert]
โ ๐ก Coffee Beans (BR) โ Score: 52/100 [MEDIUM]
๐ CPI pressure moderate at 4.2% YoY.
โ Coffee spot price $5.62/lb (+3.3% MoM).
๐ข Freight rates down 3.1% โ favorable for importers.
๐ฐ 2 disruption signals detected in NewsData feed.
๐ก Recommendation: Proceed with caution, consider hedging.
๐ค Why Agents Need This
Traditional supply chain monitoring requires humans to check dashboards, read news, and cross-reference data. upstream-alert packages all of this into a single function call that any AI agent can invoke.
graph LR
A[๐ค AI Agent] -->|"check_risk('coffee', 'BR')"| B[upstream-alert]
B --> B1[Yahoo Finance]
B --> C[FRED API]
B --> D[Commodities-API]
B --> E[UN Comtrade]
B --> F[World Bank]
B --> G[Freightos FBX]
B --> H[NewsData.io]
B1 & C & D & E & F & G & H --> I[Risk Engine]
I -->|Score + Analysis| J[Gemini AI]
J -->|Structured Response| A
What your agent gets back:
- ๐ Risk score (0โ100) with severity level
- ๐ Market pulse โ CPI, freight rates, trade volumes
- ๐ฐ News signals โ disruption events from global feeds
- ๐ก AI analysis โ context-aware summary & recommendations
- ๐ก Source attribution โ which data sources contributed
โก Quick Start
As an AI Agent Skill (Recommended)
<details> <summary><b>OpenClaw</b> โ one command install</summary>claw skill install upstream-alert
Then just ask your agent:
"What's the supply chain risk for semiconductors in Taiwan?"
</details>
<details>
<summary><b>Claude Code</b></summary>
pip install upstream-alert
cp -r skills/claude-code ~/.claude/skills/upstream-alert
export GEMINI_API_KEY="your_key"
</details>
<details>
<summary><b>Gemini CLI</b></summary>
pip install upstream-alert
cp -r skills/gemini ~/.gemini/antigravity/skills/upstream-alert
export GEMINI_API_KEY="your_key"
</details>
As a Python Library
from upstream_alert import check_risk
result = check_risk("coffee", country="BR")
print(result.score) # 52
print(result.level) # RiskLevel.MEDIUM
print(result.ai_summary) # "CPI pressure moderate at 4.2%..."
print(result.sources_used) # ['fred', 'commodities_api', 'newsdata']
As a CLI Tool
pip install upstream-alert
export GEMINI_API_KEY="your_key"
upstream-alert check "semiconductor" --country TW
upstream-alert check "rice" --country JP -j # JSON output
upstream-alert pulse --country US # Market overview
upstream-alert sources # Show configured sources
๐ Agent Integration Patterns
Function Calling / Tool Use
# Define as a tool for any LLM framework
tool_definition = {
"name": "check_supply_chain_risk",
"description": "Check supply chain risk for a commodity in a specific country",
"parameters": {
"item": {"type": "string", "description": "Commodity name (e.g., 'coffee', 'ๅๅฐ้ซ')"},
"country": {"type": "string", "description": "ISO country code (e.g., 'US', 'TW', 'BR')"}
}
}
# Implementation
from upstream_alert import check_risk
def check_supply_chain_risk(item: str, country: str) -> dict:
result = check_risk(item, country=country)
return {
"score": result.score,
"level": result.level.value,
"summary": result.ai_summary,
"market_pulse": result.market_pulse.model_dump() if result.market_pulse else None,
"sources": result.sources_used,
}
๐ง MCP Server โ native MCP tool server integration is on the roadmap.
Multi-Agent Workflow
from upstream_alert import RiskEngine
# Shared engine for a team of agents
engine = RiskEngine(
fred_key="...",
gemini_key="...",
)
# Procurement agent checks before ordering
risk = engine.check("steel", country="CN")
if risk.score > 60:
# Escalate to human or trigger alternative sourcing
notify_procurement_team(risk) # your custom function
๐ก Data Sources
| Source | Key Required | Free Tier | Data | Get Key |
|---|---|---|---|---|
| Yahoo Finance | โ | Unlimited | Daily commodity futures (copper, aluminum, soybean, cotton, coffee) | โ |
| World Bank | โ | Unlimited | Economic indicators | โ |
| FRED | FRED_API_KEY | 120 req/min | CPI, PPI, commodity prices | ็ณ่ซ |
| Commodities-API | COMMODITIES_API_KEY | 100 req/month | Real-time commodity prices | ็ณ่ซ |
| UN Comtrade | COMTRADE_API_KEY | 500 req/day | Trade volumes | ็ณ่ซ |
| NewsData.io | NEWSDATA_API_KEY | 200 req/day | News + sentiment | ็ณ่ซ |
| Gemini AI | GEMINI_API_KEY | 15 RPM | AI analysis | ็ณ่ซ |
| Freightos FBX | FBX_API_KEY | Paid | Freight rates | ็ณ่ซ |
๐ก Zero-key start: Yahoo Finance and World Bank work without any API key. Add
GEMINI_API_KEYfor AI-powered analysis.
๐ฆ Supported Item Categories (20 items)
| Category | Examples |
|---|---|
| ๅปบๆ (Construction) | ้ผ็ญ, ๅๆฟ, ๆฐดๆณฅ |
| ๆฉ้ป (Electrical) | ้ป็ท้ป็บ |
| ่ฝๆบ (Energy) | ๆดๆฒน, ๆฑฝๆฒน, ๅคฉ็ถๆฐฃ |
| ้ฃๅๅๆ (Food) | ้ป่ฑ, ้บต็ฒ, ๆฃๆซๆฒน, ็ ็ณ, ๅๅก่ฑ |
| ้ปๅญ้ถไปถ (Electronics) | ๆถ็ MCU, ่ขซๅๅ ไปถ |
| ๅ ๆ (Packaging) | ็ฆๆฅ็ด็ฎฑ, PE ่ |
| ๅๅทฅ (Chemicals) | ๅก่ ็ฒ, ๅทฅๆฅญ้ ็ฒพ |
| ็ดก็น (Textiles) | ๆฃ็ด, ๆป็ถธ็บ็ถญ |
๐ Risk Scoring
The engine calculates a composite score (0โ100) from four weighted signals:
Risk Score = (CPI ร 0.30) + (News ร 0.30) + (Freight ร 0.20) + (Trade ร 0.20)
| Level | Score | Action |
|---|---|---|
| ๐ข Low | 0โ39 | Stable โ no action needed |
| ๐ก Medium | 40โ59 | Monitor โ review before large orders |
| ๐ High | 60โ79 | Act โ consider alternative sourcing |
| ๐ด Critical | 80โ100 | Escalate โ immediate attention required |
๐ Architecture
upstream-alert/
โโโ src/upstream_alert/
โ โโโ engine.py โ Orchestration + scoring
โ โโโ analyzer.py โ Gemini AI analysis
โ โโโ models.py โ Pydantic response models
โ โโโ cli.py โ Click CLI interface
โ โโโ sources/ โ Pluggable data adapters
โ โโโ fred.py โ CPI/PPI/Commodity prices (FRED)
โ โโโ commodity.py โ Real-time prices (Commodities-API)
โ โโโ comtrade.py โ Trade data (UN)
โ โโโ worldbank.py โ Economic indicators
โ โโโ newsdata.py โ News sentiment
โ โโโ fbx.py โ Freight rates (Freightos)
โโโ skills/ โ Pre-built AI agent skills
โ โโโ openclaw/ โ OpenClaw skill package
โ โโโ claude-code/ โ Claude Code skill
โ โโโ gemini/ โ Gemini CLI skill
โโโ tests/ โ 155+ test cases
Design Principles:
- ๐ค Agent-first โ designed as a tool for AI agents, not just humans
- ๐ BYOK โ bring your own API keys, no vendor lock-in
- ๐ซ No infrastructure โ no database, no cloud services required
- ๐ฆ Zero dependencies on system packages โ pure Python + HTTP
- ๐ฏ Stateless โ every call is independent, perfect for serverless
๐ค Contributing
git clone https://github.com/ImL1s/upstream-alert
cd upstream-alert
pip install -e ".[dev]"
pytest # 155+ tests
๐ License
MIT โ use freely in personal and commercial projects.