This repository is a fintech risk-investigation demo. It shows how suspicious payment or dispute cases can move from a real-time screening layer into an AI-assisted investigation workspace backed by durable operational data.
The demo story is intentionally not "LLM in the millisecond authorization path." Rules, ML, graph features, and risk scoring create or hold suspicious cases first. Agents then investigate those cases, assemble evidence, explain the decision, and write back auditable outcomes.
There are two runnable surfaces in the project.
The refactored frontend is the main demo surface. It is a Next.js app with a polished CLAIMS-style case workspace. By default, its /api/* routes adapt the real TiDB-backed backend API on port 8787 into the frontend contract.
npx --yes pnpm@10.23.0 install --frozen-lockfile
npm run dev:api:tidb
npx --yes pnpm@10.23.0 --dir frontend dev --hostname 127.0.0.1 --port 3000Open:
http://127.0.0.1:3000/
The root route redirects to the first TiDB-backed generated case, for example RC00000697. Browser mocks remain available for offline visual work with NEXT_PUBLIC_USE_MSW=true.
The original Node API still supports local file mode and TiDB Zero mode. This is the current backend-storage implementation and is useful for the TiDB narrative.
npm install
npm run import:tidb
npm run dev:api:tidbThe API listens on:
http://127.0.0.1:8787
Confirm the active backend:
curl http://127.0.0.1:8787/api/healthExpected TiDB-backed response includes:
{ "repository": "tidb", "agentRuntime": "codex-cli" }On another machine, configure TiDB with environment variables instead of the local wrapper:
TIDB_DEMO_HOST
TIDB_DEMO_PORT
TIDB_DEMO_USER
TIDB_DEMO_PASSWORD
TIDB_DEMO_DATABASE
TIDB_DEMO_SSL_CA
Do not commit TiDB Cloud connection details.
To make the chat agents use the local Codex CLI as the real agent runtime, start the API with:
RISK_AGENT_PROVIDER=codex
RISK_CODEX_BIN=/opt/homebrew/bin/codex
Optional:
RISK_CODEX_MODEL=<codex model override>
RISK_AGENT_TIMEOUT_MS=25000
When configured, both the initial case investigation timeline and POST /api/cases/:id/chat send each agent task plus TiDB-backed tool observations to codex exec and return Codex's final agent response. If Codex CLI is unavailable or times out, each agent intentionally falls back to deterministic local skills so the demo still runs offline.
The repository has three data modes:
- The Next.js UI reads real case data through route handlers in
frontend/app/api/cases/*, which call the8787backend API. data/seed.jsonanddata/paysim-like/*.csvdrive the legacy local API mode.- TiDB Zero stores the same legacy case model in
riskops_ai_demofor backend-storage demos.
frontend/mocks/ is now an explicit fallback for offline demos and UI iteration, not the default runtime data source.
- Open the CLAIMS frontend case workspace.
- Select a suspicious dispute or payment case, for example
RC00000697. - Review customer profile, transaction context, dispute signals, graph/evidence context, and agent activity.
- Run or replay the investigation timeline.
- Inspect agent findings and final synthesis.
- Explain TiDB as the shared state layer for transactions, cases, evidence, relationships, memory, and agent writeback.
The visible workflow is:
Realtime screening -> Case queue -> Agent investigation -> Evidence-bound decision -> Durable writeback
The default guided data keeps the live demo stable.
For larger datasets, use the PaySim-style generator:
DEMO_TXN_COUNT=100000 npm run seed:paysimThis writes:
data/paysim-like/transactions.csv
data/paysim-like/risk_cases.csv
data/paysim-like/network_edges.csv
data/paysim-like/memory_events.csv
The generator borrows PaySim's domain shape, not its GPL-licensed Java source. It produces transactions plus demo-specific case, evidence, relationship, and memory tables.
TiDB is the backend state layer for:
- operational state:
transactions,customers,merchants,risk_cases - evidence and relationship state:
evidence_files,network_edges - agent memory and output:
memory_events,agent_findings,case_timeline_events,case_synthesis
The legacy TiDB repository already imports and reads the core tables. The new frontend needs additional workflow/timeline fields and endpoints. See docs/frontend-data-contract.md for the proposed schema and API alignment.
Useful commands:
npx --yes pnpm@10.23.0 --dir frontend build
curl http://127.0.0.1:8787/api/healthFor the current machine, the new frontend can also run as a persistent local service at:
http://127.0.0.1:3000/
Reusable agent-facing operational skills live under skills/:
skills/risk-demo-data-generation/SKILL.md: regenerate PaySim-style data, create more open cases, import into TiDB, and validate counts.skills/risk-demo-agent-configuration/SKILL.md: configure and verify real AI agent runtimes such as Codex CLI, plus the contract for future local CLI adapters.
- Seed the Sarah Chen /
CASE-2461story into TiDB if that exact guided scenario is needed in the real backend. - Persist richer execution writeback for
POST /api/cases/:id/executebeyond the current resolved-status update. - Persist real chat agent outputs from
POST /api/cases/:id/chatinto TiDB.