Skip to content

Add supply chain alert dashboard demo - #17

Merged
moonandlife merged 5 commits into
RIDE-Lab:mainfrom
kms12425-ctrl:feature/supply-chain-alert-dashboard-demo
Apr 22, 2026
Merged

moonandlife merged 5 commits into
RIDE-Lab:mainfrom
kms12425-ctrl:feature/supply-chain-alert-dashboard-demo

Conversation

@kms12425-ctrl

Copy link
Copy Markdown
Contributor

Summary

This PR change:

  1. Adds a SAGE-based supply chain alert dashboard demo with rule-based anomaly detection, stateful workflow orchestration, a FastAPI service, a multi-role web dashboard, and optional gateway-backed natural language risk explanations.

Why

  • The repository was missing a more complete business-style demo that shows SAGE state services, workflow orchestration, service endpoints, and optional gateway enhancement in one flow.

Main Changes

  • Add the new supply chain alert app, including event models, state store, detection operators, workflow, and application service.
  • Add CLI and FastAPI entry points for querying dashboard, alerts, supplier risk, and explanations.
  • Add a browser-based multi-role dashboard for command, procurement, logistics, and supplier management views.
  • Add test coverage for the supply chain alert app, including workflow, service, detection, API, and LLM explanation paths.
  • Update README content, example documentation, and implementation planning docs.

Testing

  • conda run -n sage pytest apps/tests/supply_chain_alert -q

Notes

  • The core alerting pipeline is rule-based and does not depend on LLM availability; natural language explanation is optional enhancement.

摘要

本 PR 包含的改动:

  1. 新增一个基于 SAGE 的供应链异常预警看板 Demo,提供规则驱动的异常检测、状态化工作流、FastAPI 服务、多角色 Web dashboard,以及可选的网关自然语言风险解释。

为什么要改

  • 仓库缺少一个能够更完整展示 SAGE 状态服务、工作流编排、服务化接口和可选网关增强能力的业务型 Demo。

主要改动

  • 新增 supply chain alert 应用,包含事件模型、状态仓、检测算子、工作流和应用服务。
  • 增加 CLI 与 FastAPI 入口,支持 dashboard、alerts、supplier risk 和 explanations 查询。
  • 增加浏览器端多角色 dashboard,用于运营总控、采购协调、仓配调度和供应商管理视角展示。
  • 增加 supply chain alert 测试覆盖,包括 workflow、service、detection、API 和 LLM explain 分支。
  • 更新 README、example 说明和实现规划文档。

测试

  • conda run -n sage pytest apps/tests/supply_chain_alert -q

说明

  • 规则预警主链路不依赖 LLM;自然语言解释是可选增强。

Copilot AI review requested due to automatic review settings April 20, 2026 08:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_alert app 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):
Comment on lines +20 to +23
def parse_timestamp(value: str) -> datetime:
normalized = value.replace("Z", "+00:00")
return datetime.fromisoformat(normalized)

Comment on lines +220 to +229
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)
Comment on lines +41 to +52
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
Comment on lines +148 to +151
@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)
@kms12425-ctrl

Copy link
Copy Markdown
Contributor Author

PR 标题 / PR Title

中文:
新增客服工单分诊 Demo 应用、API 与中文可视化界面

English:
Add customer support ticket triage demo app, API, and Chinese dashboard UI

PR 描述 / PR Description

中文:

变更概述

本 PR 新增了一个基于 SAGE 工作流的客服工单分诊 Demo,用于演示工单从输入、意图识别、紧急度评分、相似案例召回、路由决策到回复草稿生成的完整处理链路。

除了工作流主链路外,这次还补充了可直接运行的 CLI 入口、FastAPI 服务入口、中文 Dashboard 界面,以及配套的最小测试与文档说明,方便本地演示和后续扩展。

主要改动

  • 新增 ticket_triage 应用模块
  • 基于 SAGE workflow 实现工单分诊主流程
  • 新增 demo 数据、状态存储和服务层封装
  • 新增 FastAPI 接口与中文 Dashboard UI
  • 新增命令行运行入口和 API 启动入口
  • 新增 workflow、service、routing、API 相关测试
  • 更新仓库 README、examples README 和相关规划文档

设计说明

  • 核心分诊链路显式运行在 SAGE 接口和工作流之上,而不是普通脚本拼接
  • 当前版本采用规则分诊作为 MVP 主方案,不依赖 sagellm
  • 如果后续需要引入 sagellm,更适合作为解释增强、回复润色或总结层,而不是核心判定链路

验证情况

已完成 ticket_triage 相关定向测试,结果通过:

  • test_workflow
  • test_service
  • test_routing_rules
  • test_api

本地也已完成基础运行验证,包括:

  • CLI demo 可正常运行
  • API 服务可正常启动
  • Dashboard 页面可访问

适用场景

这个 Demo 适合用于演示以下能力:

  • 客服工单自动分诊
  • 优先级识别与队列分配
  • FAQ 和历史案例辅助处理
  • 面向中文演示场景的可视化工单看板

English:

Summary

This 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

  • Add a new ticket_triage application module
  • Implement the ticket triage pipeline on top of a SAGE workflow
  • Add demo data, state storage, and an application service layer
  • Add FastAPI endpoints and a Chinese dashboard UI
  • Add CLI and API startup entry points
  • Add tests for workflow, service, routing rules, and API behavior
  • Update repository documentation and related planning docs

Design Notes

  • The core triage flow runs explicitly through SAGE interfaces and workflow operators rather than a plain Python script
  • The current MVP uses deterministic rule-based triage and does not depend on sagellm
  • If sagellm is introduced later, it should be used as an explanation, summarization, or response-enhancement layer instead of the core decision path

Validation

The ticket_triage-focused test suite has been executed successfully:

  • test_workflow
  • test_service
  • test_routing_rules
  • test_api

Basic local runtime validation was also completed:

  • CLI demo runs successfully
  • API service starts successfully
  • Dashboard page is accessible

Use Cases

This demo is intended to showcase:

  • Automated customer support ticket triage
  • Priority identification and queue assignment
  • FAQ and historical-case assisted handling
  • A Chinese-first dashboard experience for demos

@moonandlife
moonandlife merged commit df43f28 into RIDE-Lab:main Apr 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants