Repository navigation
Add supply chain alert dashboard demo - #17
moonandlife merged 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new end-to-end SAGE demo application (“Supply Chain Alert Dashboard”) that showcases stateful workflow orchestration, a queryable service layer (FastAPI), a multi-role browser dashboard UI, and optional gateway-backed natural-language explanations.
Changes:
- Introduce
sage.apps.supply_chain_alertapp module: models, state store, operators, workflow runner, service facade, optional gateway explainer, and embedded dashboard UI. - Add CLI + FastAPI entry scripts and update example/root READMEs to document how to run the demo.
- Add a dedicated test suite covering workflow/service/detection/API paths and gateway explanation logic.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/run_supply_chain_alert_api.py | Adds a runnable entrypoint for launching the FastAPI service via uvicorn. |
| examples/run_supply_chain_alert.py | Adds a CLI runner for the demo, with optional JSON output and optional explanation generation. |
| examples/README.md | Registers the new CLI/API example scripts in the examples index. |
| docs/supply-chain-alert-board-plan.md | Adds an implementation plan/design doc for the supply chain alert dashboard demo. |
| docs/sage-demo-app-ideas.md | Adds the supply chain alert dashboard idea and links to the plan doc. |
| apps/tests/supply_chain_alert/init.py | Initializes the new supply-chain-alert test package. |
| apps/tests/supply_chain_alert/test_workflow.py | Tests demo workflow outputs and expected dashboard metrics. |
| apps/tests/supply_chain_alert/test_service.py | Tests state persistence, demo resets, and service explanation integration. |
| apps/tests/supply_chain_alert/test_llm.py | Tests gateway settings/env parsing and explainer behavior across gateway probe/generation scenarios. |
| apps/tests/supply_chain_alert/test_detection.py | Tests specific anomaly detection behaviors and supplier recommendation ordering/filtering. |
| apps/tests/supply_chain_alert/test_api.py | Tests FastAPI routes, UI HTML response, ingest/demo/query routes, and explanations route. |
| apps/src/sage/apps/supply_chain_alert/workflow.py | Implements the LocalEnvironment pipeline runner and BaseService-backed state service. |
| apps/src/sage/apps/supply_chain_alert/ui.py | Adds a multi-role, browser-rendered dashboard UI served from /dashboard/ui. |
| apps/src/sage/apps/supply_chain_alert/state_store.py | Adds an in-memory state store with optional JSON persistence and dashboard metric derivation. |
| apps/src/sage/apps/supply_chain_alert/service.py | Adds the application service facade and FastAPI app factory for querying/ingesting/demoing. |
| apps/src/sage/apps/supply_chain_alert/operators.py | Adds SAGE operators for normalization, state updates, anomaly detection, impact assessment, and mitigation. |
| apps/src/sage/apps/supply_chain_alert/models.py | Adds the structured dataclass models for events, alerts, snapshots, and explanation results. |
| apps/src/sage/apps/supply_chain_alert/llm.py | Adds optional sage.serving gateway integration to generate natural-language explanations. |
| apps/src/sage/apps/supply_chain_alert/demo_data.py | Adds deterministic demo event generation + summary metrics for CLI/UI. |
| apps/src/sage/apps/supply_chain_alert/init.py | Exposes the new app’s public API surface via re-exports. |
| apps/src/sage/apps/supply_chain_alert/README.md | Documents how to run the CLI/API/UI and configure optional gateway explanations. |
| apps/pyproject.toml | Adds FastAPI + uvicorn as app dependencies to support the new HTTP demo. |
| README.md | Adds the new demo entries to the repository’s top-level “Complete applications” list. |
| class RecommendMitigationStep(MapFunction): | ||
| def execute(self, data: dict[str, Any]) -> dict[str, Any]: | ||
| alerts: list[OpenAlert] = [] | ||
| for signal, assessment in zip(data["signals"], data["assessments"], strict=False): |
| def parse_timestamp(value: str) -> datetime: | ||
| normalized = value.replace("Z", "+00:00") | ||
| return datetime.fromisoformat(normalized) | ||
|
|
| def _infer_latest_timestamp(self) -> str: | ||
| timestamps: list[str] = [] | ||
| timestamps.extend(item.updated_at for item in self.inventories.values()) | ||
| timestamps.extend(item.observed_at for item in self.orders.values()) | ||
| timestamps.extend(item.recorded_at for item in self.shipments.values()) | ||
| timestamps.extend(item.observed_at for item in self.suppliers.values()) | ||
| timestamps.extend(item.triggered_at for item in self.alerts.values()) | ||
| if not timestamps: | ||
| return datetime.utcnow().replace(microsecond=0).isoformat() | ||
| return max(timestamps) |
| def _resolve_last_timestamp(events: list[SupplyEvent]) -> str | None: | ||
| if not events: | ||
| return None | ||
| timestamps = [] | ||
| for event in events: | ||
| if hasattr(event, "observed_at"): | ||
| timestamps.append(getattr(event, "observed_at")) | ||
| elif hasattr(event, "updated_at"): | ||
| timestamps.append(getattr(event, "updated_at")) | ||
| elif hasattr(event, "recorded_at"): | ||
| timestamps.append(getattr(event, "recorded_at")) | ||
| return max(timestamps) if timestamps else None |
| @app.post("/events/ingest") | ||
| def ingest_events(payload: list[dict[str, Any]]) -> dict[str, Any]: | ||
| result = runtime_service.ingest_events(payload) | ||
| return _to_payload(result) |
|
PR 标题 / PR Title 中文: English: PR 描述 / PR Description 中文: 变更概述本 PR 新增了一个基于 SAGE 工作流的客服工单分诊 Demo,用于演示工单从输入、意图识别、紧急度评分、相似案例召回、路由决策到回复草稿生成的完整处理链路。 除了工作流主链路外,这次还补充了可直接运行的 CLI 入口、FastAPI 服务入口、中文 Dashboard 界面,以及配套的最小测试与文档说明,方便本地演示和后续扩展。 主要改动
设计说明
验证情况已完成 ticket_triage 相关定向测试,结果通过:
本地也已完成基础运行验证,包括:
适用场景这个 Demo 适合用于演示以下能力:
English: SummaryThis PR adds a customer support ticket triage demo built on top of a SAGE workflow. It demonstrates the full processing path from ticket ingestion, intent classification, urgency scoring, and similar-case recall to routing decisions and reply draft generation. In addition to the workflow itself, this PR includes a runnable CLI entry point, a FastAPI service, a Chinese dashboard UI, and the minimum supporting tests and documentation needed for local demos and future extension. Main Changes
Design Notes
ValidationThe ticket_triage-focused test suite has been executed successfully:
Basic local runtime validation was also completed:
Use CasesThis demo is intended to showcase:
|
Summary
This PR change:
Why
Main Changes
Testing
conda run -n sage pytest apps/tests/supply_chain_alert -qNotes
摘要
本 PR 包含的改动:
为什么要改
主要改动
测试
conda run -n sage pytest apps/tests/supply_chain_alert -q说明