๐Ÿ” 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.

License: MIT Python 3.10+ PyPI

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

SourceKey RequiredFree TierDataGet Key
Yahoo FinanceโŒUnlimitedDaily commodity futures (copper, aluminum, soybean, cotton, coffee)โ€”
World BankโŒUnlimitedEconomic indicatorsโ€”
FREDFRED_API_KEY120 req/minCPI, PPI, commodity prices็”ณ่ซ‹
Commodities-APICOMMODITIES_API_KEY100 req/monthReal-time commodity prices็”ณ่ซ‹
UN ComtradeCOMTRADE_API_KEY500 req/dayTrade volumes็”ณ่ซ‹
NewsData.ioNEWSDATA_API_KEY200 req/dayNews + sentiment็”ณ่ซ‹
Gemini AIGEMINI_API_KEY15 RPMAI analysis็”ณ่ซ‹
Freightos FBXFBX_API_KEYPaidFreight rates็”ณ่ซ‹

๐Ÿ’ก Zero-key start: Yahoo Finance and World Bank work without any API key. Add GEMINI_API_KEY for AI-powered analysis.

๐Ÿ“ฆ Supported Item Categories (20 items)

CategoryExamples
ๅปบๆ (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)
LevelScoreAction
๐ŸŸข Low0โ€“39Stable โ€” no action needed
๐ŸŸก Medium40โ€“59Monitor โ€” review before large orders
๐ŸŸ  High60โ€“79Act โ€” consider alternative sourcing
๐Ÿ”ด Critical80โ€“100Escalate โ€” 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.