22[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( LICENSE )
33[ ![ Python 3.11] ( https://img.shields.io/badge/python-3.11+-blue.svg )] ( https://www.python.org/ )
44
5- # AI-Driven Trade Surveillance Orchestrator
5+ # AI-Driven Trade Surveillance Orchestrator 🚦
66
7- A small demo is designed to illustrate ** AI orchestration** and ** governance patterns ** in ** trade surveillance** .
7+ ** TL;DR: ** A compact example demonstrating AI orchestration, governance, and anomaly detection for trade surveillance. Use the CLI or the Streamlit UI to run workflows that parse trades, detect anomalies (rule-based or ML), produce compliance-style summaries, and capture an audit trail .
88
9- This project simulates a ** trade surveillance workflow ** :
9+ Keywords: ** trade surveillance ** , ** anomaly detection ** , ** AI orchestration ** , ** governance ** , ** IsolationForest ** , ** Streamlit **
1010
11- 1 . Parse a set of trades
12- 2 . Run simple anomaly detection rules
13- 3 . Generate a compliance-style summary
14- 4 . Capture an audit trail with risk levels
11+ ** Docs:** Additional documentation is available in the ` docs/ ` folder — see [ AI governance] ( docs/ai_governance.md ) , [ Model card (ML detector)] ( docs/model_card_ml_anomaly_detector.md ) , [ Roadmap] ( docs/roadmap.md ) , and screenshots in [ docs/images] ( docs/images/ ) .
1512
16- The code is intentionally compact but structured like a real enterprise component.
13+ <table >
14+ <tr >
15+ <td align="center" valign="top">
16+ <img src="docs/images/ui_ml.gif" alt="ML workflow demo" width="420" />
17+ <br>
18+ <strong>ML workflow</strong>
19+ </td>
20+ <td align="center" valign="top">
21+ <img src="docs/images/ui_rule_based.gif" alt="Rule-based workflow demo" width="420" />
22+ <br>
23+ <strong>Rule-based workflow</strong>
24+ </td>
25+ </tr >
26+ </table >
27+
28+ > ** Note:** Individual screenshots (PNG) are available in ` docs/images/ ` for full-resolution stills and reference.
29+
30+ ---
31+
32+ ## Table of contents 📚
1733
18- ## Features
34+ - [ Why this project] ( #why-this-project-%EF%B8%8F )
35+ - [ Features] ( #features )
36+ - [ Quick start] ( #quick-start-rocket )
37+ - [ Install] ( #install )
38+ - [ Run example (CLI)] ( #run-example-cli )
39+ - [ Run UI (Streamlit)] ( #run-ui-streamlit )
40+ - [ Quick demo — expected output] ( #quick-demo--expected-output )
41+ - [ Files of interest] ( #files-of-interest )
42+ - [ Testing & CI] ( #testing--ci )
43+ - [ Contributing & Support] ( #contributing--support )
44+ - [ License] ( #license )
1945
20- - ** Workflow as config**
21- - Define surveillance workflows in YAML (` workflows/trade_surveillance.yml ` ).
46+ ---
2247
23- - ** Tool registry**
24- - Pluggable tools in ` orchestrator/tools.py ` :
25- - ` parse_trades ` : parses JSON list of trades
26- - ` anomaly_detector ` : rule-based checks (large trades, rapid flips, wash-like patterns)
27- - ` ml_anomaly_detector ` : ML-based detector (IsolationForest) — optional
28- - ` summarizer ` : produces a compliance-style narrative
48+ ## Why this project ⚖️
2949
30- - ** Task routing & orchestration**
31- - ` orchestrator/workflow_runner.py ` runs configured steps and tracks an audit log.
50+ This repository is a focused demo for engineers and researchers who want to explore how AI components can be orchestrated and governed in a trade surveillance setting. It balances realistic structure (tool registry, workflow config, audit logs) with lightweight code that’s easy to extend.
3251
33- - ** Governance & audit**
34- - ` AuditLog ` and ` AuditEntry ` in ` orchestrator/governance.py ` capture step inputs/outputs and risk levels.
52+ ---
3553
36- - ** UI**
37- - Streamlit app (` ui/app.py ` ) to paste/edit trade JSON, choose detection method (rule-based or ML), run the workflow, and inspect results.
54+ ## Features ✨
3855
39- ## Getting started
56+ - Workflow-as-config: define surveillance flows in YAML (` workflows/trade_surveillance.yml ` ).
57+ - Tool registry: modular tools in ` orchestrator/tools.py ` :
58+ - ` parse_trades ` — parse JSON trade lists
59+ - ` anomaly_detector ` — rule-based heuristics (large trades, flips, wash-like patterns)
60+ - ` ml_anomaly_detector ` — optional IsolationForest-based detector
61+ - ` summarizer ` — compliance-style narrative
62+ - Orchestration: ` orchestrator/workflow_runner.py ` executes steps and builds an audit log.
63+ - Governance & audit: ` AuditLog ` and ` AuditEntry ` capture inputs/outputs and risk levels (` orchestrator/governance.py ` ).
64+ - UI: Streamlit app (` ui/app.py ` ) for interactive exploration and parameter tuning.
4065
41- ### 1. Setup environment
66+ ---
67+
68+ ## Quick start 🚀
69+
70+ ### Install
4271
4372``` bash
4473python -m venv .venv
@@ -50,114 +79,78 @@ source .venv/bin/activate
5079pip install -r requirements.txt
5180```
5281
53- ### 2. Run CLI example
82+ Tip: use ` python -m pip install -e . ` if you add packaging later and want editable installs.
83+
84+ ### Run example (CLI)
5485
5586``` bash
5687python -m examples.run_workflow
5788```
5889
59- Expected output:
60- - A final textual summary
61- - A list of detected anomalies
62- - Compact audit log lines
63-
64- ### 3. Run Streamlit UI
90+ ### Run UI (Streamlit)
6591
6692``` bash
6793python -m streamlit run ui/app.py
6894```
6995
70- Then open the URL printed in the terminal (usually http://localhost:8501 ). In the UI you can:
71- - Inspect and modify ` examples/sample_trades.json `
72- - Choose detection method (` Rule-based ` or ` ML (IsolationForest) ` ) and tune parameters (` threshold ` or ` contamination ` )
73- - Set summary max length and view the audit log
96+ Open the URL printed in the terminal (usually http://localhost:8501 ).
7497
75- Screenshots of the UI (real captures):
98+ ---
7699
77- <table >
78- <thead >
79- <tr>
80- <th align="center" valign="top"><strong>ML</strong></th>
81- <th align="center" valign="top"><strong>Rule-based</strong></th>
82- </tr>
83- </thead >
84- <tbody >
85- <tr>
86- <td align="center" valign="top">
87- <em>Initial</em>
88- <br>
89- <img src="docs/images/ui_ml_1_initial.png" alt="ML initial" width="420"/>
90- </td>
91- <td align="center" valign="top">
92- <em>Initial</em>
93- <br>
94- <img src="docs/images/ui_rule_based_1_initial.png" alt="Rule-based initial" width="420"/>
95- </td>
96- </tr>
97- <tr>
98- <td align="center" valign="top">
99- <em>Summary</em>
100- <br>
101- <img src="docs/images/ui_ml_2_summary.png" alt="ML summary" width="420"/>
102- </td>
103- <td align="center" valign="top">
104- <em>Summary</em>
105- <br>
106- <img src="docs/images/ui_rule_based_2_summary.png" alt="Rule-based summary" width="420"/>
107- </td>
108- </tr>
109- <tr>
110- <td align="center" valign="top">
111- <em>Anomaly (expanded)</em>
112- <br>
113- <img src="docs/images/ui_ml_3_anomaly_expanded.png" alt="ML anomaly expanded" width="420"/>
114- </td>
115- <td align="center" valign="top">
116- <em>Anomaly (expanded)</em>
117- <br>
118- <img src="docs/images/ui_rule_based_3_anomaly_expanded.png" alt="Rule-based anomaly expanded" width="420">
119- </td>
120- </tr>
121- <tr>
122- <td align="center" valign="top">
123- <em>Audit</em>
124- <br>
125- <img src="docs/images/ui_ml_4_audit.png" alt="ML audit" width="420"/>
126- </td>
127- <td align="center" valign="top">
128- <em>Audit</em>
129- <br>
130- <img src="docs/images/ui_rule_based_4_audit.png" alt="Rule-based audit" width="420"/>
131- </td>
132- </tr>
133- </tbody >
134- </table >
100+ ## Quick demo — expected output 🧾
101+
102+ CLI output shows a short summary, detected anomalies, and a compact audit log. Example snippet:
103+
104+ ``` text
105+ Summary: 2 potential anomalies detected, highest risk: high
106+ Anomalies:
107+ - trade_id: 12345 — large size (>$1m)
108+ - trade_id: 12348 — rapid flip pattern
109+ AuditLog:
110+ [01:23:45] parse_trades -> 100 trades
111+ [01:23:45] anomaly_detector -> 2 anomalies (risk=high)
112+ [01:23:46] summarizer -> 1 summary
113+ ```
114+
115+ Use ` examples/sample_trades.json ` as a starting dataset.
135116
136- ## Files of interest
117+ ---
137118
138- - ` orchestrator/tools.py ` — parsing, rule-based anomaly detection, ML detector, summarizer, tool registry
139- - ` orchestrator/workflow_runner.py ` — runs steps and builds the audit log
140- - ` orchestrator/governance.py ` — audit models and risk classification
141- - ` workflows/trade_surveillance.yml ` — example workflow configuration
142- - ` ui/app.py ` — Streamlit UI
119+ ## Files of interest 📂
120+
121+ - ` orchestrator/tools.py ` — parsing, rule-based and ML detectors, summarizer
122+ - ` orchestrator/workflow_runner.py ` — workflow execution and audit log
123+ - ` orchestrator/governance.py ` — audit models, risk classification
124+ - ` workflows/trade_surveillance.yml ` — an example workflow configuration
125+ - ` ui/app.py ` — Streamlit UI for interactive runs
143126- ` docs/model_card_ml_anomaly_detector.md ` — model card for the ML detector
144- - ` examples/evaluate_ml_detector.py ` — quick runner for the ML detector
127+ - ` examples/ ` — quick scripts ( ` run_workflow ` , ` evaluate_ml_detector ` )
145128- ` tests/ ` — unit and integration tests
146129
147- ## Testing & CI
130+ ---
131+
132+ ## Testing & CI ✅
148133
149- Run tests locally with :
134+ Run tests locally:
150135
151136``` bash
152137python -m pytest -q
153138```
154139
155- A CI workflow is included at ` .github/workflows/ci.yml ` to run tests on push/PR.
140+ CI runs automatically at ` .github/workflows/ci.yml ` on push and PRs.
141+
142+ ---
143+
144+ ## Contributing & Support 🤝
145+
146+ - See ` CONTRIBUTING.md ` for contribution guidelines and how to run tests.
147+ - File issues or feature requests at the repo Issues page.
148+ - For quick questions, open an issue and tag maintainers.
156149
157- ## Contributing
150+ ---
158151
159- See ` CONTRIBUTING.md ` for guidelines on contributing, testing, and submitting PRs.
152+ ## License 📜
160153
161- ## License
154+ MIT — see ` LICENSE ` for details.
162155
163- This project is licensed under the MIT License — see ` LICENSE ` for details.
156+ ---
0 commit comments