nothingworry commited on
Commit
31f3625
Β·
1 Parent(s): a477044

update the readme files

Browse files
Files changed (3) hide show
  1. LICENSE +1 -1
  2. README.md +49 -4
  3. RULES_EXAMPLES.md +39 -13
LICENSE CHANGED
@@ -13,7 +13,7 @@ The above copyright notice and this permission notice shall be included in all
13
  copies or substantial portions of the Software.
14
 
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
13
  copies or substantial portions of the Software.
14
 
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,got
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
README.md CHANGED
@@ -22,7 +22,15 @@ This platform showcases how MCP can power intelligent, governed, multi-tenant AI
22
  - πŸ“š **Enhanced Knowledge Base Management** – Upload raw text, URLs, or documents (PDF/DOCX/TXT/MD) with rich metadata (source URL, timestamp, document type) and optimized chunking (400-600 tokens)
23
  - πŸ” **Optimized RAG Search** – Semantic search with configurable similarity threshold (default 0.3) for better recall, with fallback to return top results even if below threshold
24
  - πŸ—‘οΈ **Document Management** – Delete individual documents or bulk delete all documents for a tenant with confirmation dialogs
25
- - πŸ›‘οΈ **Enterprise Admin Governance** – Regex-based red-flag pattern matching with severity levels (low/medium/high/critical) and automatic admin alerts
 
 
 
 
 
 
 
 
26
  - πŸ“Š **Comprehensive Analytics & Observability** – Full tenant-level analytics logging with SQLite backend:
27
  - Tool usage breakdown (RAG, Web, Admin, LLM) with latency and token tracking
28
  - RAG recall/precision indicators (average hits, scores, top scores)
@@ -33,14 +41,20 @@ This platform showcases how MCP can power intelligent, governed, multi-tenant AI
33
  - 🏒 **Multi-Tenant Isolation** – Complete tenant isolation with centralized tenant ID management; backend enforces strict isolation for chat, ingestion, and admin ops
34
  - πŸ”„ **Intelligent Multi-Tool Orchestration** – MCP agent orchestrator autonomously selects optimal tool chains (RAG + Web + LLM, etc.) based on query intent and context
35
  - ⚑ **Robust Error Handling** – Structured error responses, retry mechanisms, and graceful fallbacks (e.g., if RAG fails β†’ fallback to LLM-only)
 
 
36
 
37
  ### Enterprise Features
38
 
39
  - πŸ” **Regex-Based Red-Flag Detection** – Support for complex regex patterns with keyword fallback and semantic scoring
 
 
 
40
  - πŸ“ˆ **Real-Time Analytics Dashboard** – Per-tenant analytics with configurable time windows (7, 30, 90 days)
41
  - πŸ› οΈ **Admin API Endpoints** – `/admin/violations`, `/admin/tools/logs`, `/admin/tenants` for comprehensive governance
42
  - 🧠 **Agent Debug & Planning** – `/agent/debug` and `/agent/plan` endpoints for observability and tool selection inspection
43
  - πŸ’Ύ **Persistent Analytics Storage** – SQLite-based analytics store with indexes for fast queries
 
44
 
45
  ---
46
 
@@ -97,7 +111,14 @@ The Gradio UI exposes four tabs once you launch `app.py`:
97
  - **Formatted Summary**: Key metrics displayed in an easy-to-read format
98
  - Click "πŸ”„ Fetch Analytics Snapshot" to load the latest data
99
 
100
- 5. **Admin Rules & Compliance** – upload/delete governance rules that are stored via the backend `/admin/rules` API.
 
 
 
 
 
 
 
101
 
102
  **Tip:** Every action requires a tenant ID. The tenant ID is now managed centrally and persists across page refreshes. The Knowledge Base Library and Admin Analytics tabs feature beautiful, modern UI with dark theme styling and interactive Plotly visualizations.
103
 
@@ -137,6 +158,7 @@ Then open `http://localhost:3000`. The navbar links on the landing page route to
137
  | Purpose | Method & Path | Description |
138
  | --- | --- | --- |
139
  | Chat with agent | `POST /agent/message` | Main chat endpoint with `tenant_id`, `message`, optional history |
 
140
  | Agent debug | `POST /agent/debug` | Returns detailed debugging info: reasoning trace, tool selection, intent classification |
141
  | Agent plan | `POST /agent/plan` | Returns tool selection plan without execution (intent, tool scores, planned steps) |
142
 
@@ -155,11 +177,14 @@ Then open `http://localhost:3000`. The navbar links on the landing page route to
155
  | Purpose | Method & Path | Description |
156
  | --- | --- | --- |
157
  | List rules | `GET /admin/rules?detailed=true` | Get all rules (use `detailed=true` for regex/severity metadata) |
158
- | Add rule | `POST /admin/rules` | Add rule with optional `pattern` (regex), `severity` (low/medium/high/critical), `description` |
 
 
159
  | Delete rule | `DELETE /admin/rules/{rule}` | Delete a specific rule |
160
  | List violations | `GET /admin/violations?days=30&limit=50` | Get red-flag violations with timestamps and confidence scores |
161
  | Tool logs | `GET /admin/tools/logs?tool_name=rag&days=7` | Get detailed tool usage logs with latency and token counts |
162
  | Manage tenants | `GET/POST/DELETE /admin/tenants` | Tenant management endpoints (placeholder implementation) |
 
163
 
164
  ### Analytics Endpoints
165
 
@@ -255,11 +280,31 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
255
  - **Backend**: FastAPI with async/await for high-performance MCP orchestration
256
  - **Frontend**: Gradio interface with Plotly visualizations + Next.js operator console
257
  - **UI Libraries**: Plotly for interactive charts, Gradio for web interface
258
- - **LLM Integration**: Ollama (local) or Groq (cloud) via configurable backend
259
  - **Vector Store**: pgvector (via Supabase) or SQLite embeddings
260
  - **Analytics**: SQLite with indexed queries for fast analytics
 
261
  - **MCP Server**: Unified MCP server (port 8900) exposing all tools via namespaces
262
  - **Database**: PostgreSQL with pgvector extension for RAG embeddings, SQLite for analytics
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
  ## Key Technical Features
265
 
 
22
  - πŸ“š **Enhanced Knowledge Base Management** – Upload raw text, URLs, or documents (PDF/DOCX/TXT/MD) with rich metadata (source URL, timestamp, document type) and optimized chunking (400-600 tokens)
23
  - πŸ” **Optimized RAG Search** – Semantic search with configurable similarity threshold (default 0.3) for better recall, with fallback to return top results even if below threshold
24
  - πŸ—‘οΈ **Document Management** – Delete individual documents or bulk delete all documents for a tenant with confirmation dialogs
25
+ - πŸ›‘οΈ **Enterprise Admin Governance** – Advanced rule management system with:
26
+ - Regex-based red-flag pattern matching with severity levels (low/medium/high/critical)
27
+ - Automatic admin alerts for violations
28
+ - **LLM-Enhanced Rules**: Rules are automatically analyzed and enhanced to identify edge cases, improve regex patterns, and suggest appropriate severity levels
29
+ - **File Upload Support**: Upload rules from TXT, PDF, DOC, or DOCX files with drag-and-drop interface
30
+ - **Chunk Processing**: Large rule sets processed in manageable chunks (5 rules at a time) to prevent timeouts
31
+ - **Rule-Based Behavior Control**: Rules checked FIRST - brief response rules return quick answers, blocking rules prevent requests
32
+ - **Comment Filtering**: Comment lines (starting with #) automatically ignored when uploading rules
33
+ - **Supabase Integration**: Rules stored in Supabase for production scalability (with SQLite fallback)
34
  - πŸ“Š **Comprehensive Analytics & Observability** – Full tenant-level analytics logging with SQLite backend:
35
  - Tool usage breakdown (RAG, Web, Admin, LLM) with latency and token tracking
36
  - RAG recall/precision indicators (average hits, scores, top scores)
 
41
  - 🏒 **Multi-Tenant Isolation** – Complete tenant isolation with centralized tenant ID management; backend enforces strict isolation for chat, ingestion, and admin ops
42
  - πŸ”„ **Intelligent Multi-Tool Orchestration** – MCP agent orchestrator autonomously selects optimal tool chains (RAG + Web + LLM, etc.) based on query intent and context
43
  - ⚑ **Robust Error Handling** – Structured error responses, retry mechanisms, and graceful fallbacks (e.g., if RAG fails β†’ fallback to LLM-only)
44
+ - πŸ“‘ **Streaming Responses** – Chat responses stream word-by-word using Server-Sent Events (SSE) for real-time user experience
45
+ - 🎯 **Rule-First Processing** – Admin rules checked before intent classification - rules can trigger brief responses or block requests entirely
46
 
47
  ### Enterprise Features
48
 
49
  - πŸ” **Regex-Based Red-Flag Detection** – Support for complex regex patterns with keyword fallback and semantic scoring
50
+ - πŸ€– **LLM-Enhanced Rule Management** – Rules automatically enhanced by LLM to identify edge cases, improve patterns, and suggest severity levels
51
+ - πŸ“„ **File Upload & Drag-and-Drop** – Upload rules from files (TXT, PDF, DOC, DOCX) with intuitive drag-and-drop interface
52
+ - ⚑ **Chunk-Wise Processing** – Large rule sets processed in chunks to prevent timeouts and ensure reliable processing
53
  - πŸ“ˆ **Real-Time Analytics Dashboard** – Per-tenant analytics with configurable time windows (7, 30, 90 days)
54
  - πŸ› οΈ **Admin API Endpoints** – `/admin/violations`, `/admin/tools/logs`, `/admin/tenants` for comprehensive governance
55
  - 🧠 **Agent Debug & Planning** – `/agent/debug` and `/agent/plan` endpoints for observability and tool selection inspection
56
  - πŸ’Ύ **Persistent Analytics Storage** – SQLite-based analytics store with indexes for fast queries
57
+ - πŸ—„οΈ **Supabase Integration** – Production-ready Supabase support for admin rules with automatic table creation
58
 
59
  ---
60
 
 
111
  - **Formatted Summary**: Key metrics displayed in an easy-to-read format
112
  - Click "πŸ”„ Fetch Analytics Snapshot" to load the latest data
113
 
114
+ 5. **Admin Rules & Compliance** – comprehensive rule management with:
115
+ - **Text Input**: Paste rules one per line (comment lines starting with # are automatically ignored)
116
+ - **File Upload**: Upload rules from TXT, PDF, DOC, or DOCX files with drag-and-drop support
117
+ - **LLM Enhancement**: Rules are automatically enhanced by LLM to identify edge cases, improve patterns, and suggest severity levels
118
+ - **Chunk Processing**: Large rule sets processed in chunks (5 rules at a time) to avoid timeouts
119
+ - **Rule-Based Behavior**: Rules are checked FIRST before normal processing - brief response rules (low severity) return quick responses, blocking rules (high severity) block requests
120
+ - **Streaming Responses**: Chat responses stream word-by-word for better user experience
121
+ - **Refresh Button**: Refresh rules directly from the Rule Set table
122
 
123
  **Tip:** Every action requires a tenant ID. The tenant ID is now managed centrally and persists across page refreshes. The Knowledge Base Library and Admin Analytics tabs feature beautiful, modern UI with dark theme styling and interactive Plotly visualizations.
124
 
 
158
  | Purpose | Method & Path | Description |
159
  | --- | --- | --- |
160
  | Chat with agent | `POST /agent/message` | Main chat endpoint with `tenant_id`, `message`, optional history |
161
+ | Chat with agent (streaming) | `POST /agent/message/stream` | Streams response word-by-word using Server-Sent Events (SSE). Returns status messages and tokens as they're generated |
162
  | Agent debug | `POST /agent/debug` | Returns detailed debugging info: reasoning trace, tool selection, intent classification |
163
  | Agent plan | `POST /agent/plan` | Returns tool selection plan without execution (intent, tool scores, planned steps) |
164
 
 
177
  | Purpose | Method & Path | Description |
178
  | --- | --- | --- |
179
  | List rules | `GET /admin/rules?detailed=true` | Get all rules (use `detailed=true` for regex/severity metadata) |
180
+ | Add rule | `POST /admin/rules?enhance=true` | Add single rule with optional `pattern` (regex), `severity` (low/medium/high/critical), `description`. Set `enhance=true` for LLM enhancement |
181
+ | Add rules bulk | `POST /admin/rules/bulk?enhance=true` | Add multiple rules at once. Processed in chunks of 5 to avoid timeouts. LLM enhancement applied automatically |
182
+ | Upload rules file | `POST /admin/rules/upload-file?enhance=true` | Upload rules from file (TXT, PDF, DOC, DOCX). Text extracted server-side, rules processed with LLM enhancement |
183
  | Delete rule | `DELETE /admin/rules/{rule}` | Delete a specific rule |
184
  | List violations | `GET /admin/violations?days=30&limit=50` | Get red-flag violations with timestamps and confidence scores |
185
  | Tool logs | `GET /admin/tools/logs?tool_name=rag&days=7` | Get detailed tool usage logs with latency and token counts |
186
  | Manage tenants | `GET/POST/DELETE /admin/tenants` | Tenant management endpoints (placeholder implementation) |
187
+ | Setup Supabase table | `POST /admin/setup/table` | Create admin_rules table in Supabase if it doesn't exist |
188
 
189
  ### Analytics Endpoints
190
 
 
280
  - **Backend**: FastAPI with async/await for high-performance MCP orchestration
281
  - **Frontend**: Gradio interface with Plotly visualizations + Next.js operator console
282
  - **UI Libraries**: Plotly for interactive charts, Gradio for web interface
283
+ - **LLM Integration**: Ollama (local) or Groq (cloud) via configurable backend with streaming support
284
  - **Vector Store**: pgvector (via Supabase) or SQLite embeddings
285
  - **Analytics**: SQLite with indexed queries for fast analytics
286
+ - **Rules Storage**: Supabase (production) or SQLite (development) with automatic table creation
287
  - **MCP Server**: Unified MCP server (port 8900) exposing all tools via namespaces
288
  - **Database**: PostgreSQL with pgvector extension for RAG embeddings, SQLite for analytics
289
+ - **File Processing**: Support for TXT, PDF, DOC, DOCX with server-side text extraction (PyPDF2, python-docx)
290
+ - **Streaming**: Server-Sent Events (SSE) for real-time word-by-word response streaming
291
+
292
+ ## Recent Enhancements
293
+
294
+ ### Admin Rules System (Latest)
295
+ - **File Upload Support**: Upload rules from TXT, PDF, DOC, DOCX files with drag-and-drop interface
296
+ - **LLM Enhancement**: Automatic rule enhancement identifies edge cases, improves regex patterns, and suggests severity levels
297
+ - **Chunk Processing**: Large rule sets processed in chunks of 5 to prevent timeouts (handles 100+ rules efficiently)
298
+ - **Comment Filtering**: Comment lines (starting with #) automatically ignored when uploading rules
299
+ - **Rule-First Processing**: Admin rules checked before intent classification - enables behavior control (brief responses vs blocking)
300
+ - **Supabase Integration**: Production-ready Supabase support with automatic table creation
301
+ - **Streaming Responses**: Word-by-word streaming for chat responses using Server-Sent Events (SSE)
302
+
303
+ ### UI Improvements
304
+ - **Modern Drag-and-Drop**: Intuitive file upload with visual feedback
305
+ - **Enhanced Status Messages**: Clear success/error messages with icons
306
+ - **Refresh Button in Table**: Quick refresh directly from the Rule Set section
307
+ - **Better Visual Hierarchy**: Improved spacing, colors, and layout
308
 
309
  ## Key Technical Features
310
 
RULES_EXAMPLES.md CHANGED
@@ -4,9 +4,10 @@ This document provides examples of rules you can use with the IntegraChat admin
4
 
5
  ## Quick Start
6
 
7
- 1. **Simple Rules** - Copy from `example_rules.txt` and paste into Gradio UI
8
- 2. **Detailed Rules** - Use `example_rules_detailed.json` for rules with patterns and severity
9
- 3. **API** - Use the `/admin/rules` or `/admin/rules/bulk` endpoints
 
10
 
11
  ## Rule Categories
12
 
@@ -101,10 +102,20 @@ For more precise matching, you can specify regex patterns:
101
  1. Open the IntegraChat Gradio interface
102
  2. Go to "Admin Rules & Compliance" tab
103
  3. Enter your tenant ID
104
- 4. Paste rules from `example_rules.txt` (one per line)
105
- 5. Click "Upload / Append Rules"
 
 
106
 
107
- ### Method 2: Via API (Programmatic)
 
 
 
 
 
 
 
 
108
 
109
  **Single Rule:**
110
  ```bash
@@ -121,7 +132,7 @@ curl -X POST http://localhost:8000/admin/rules \
121
 
122
  **Bulk Rules:**
123
  ```bash
124
- curl -X POST http://localhost:8000/admin/rules/bulk \
125
  -H "Content-Type: application/json" \
126
  -H "x-tenant-id: your_tenant_id" \
127
  -d '{
@@ -133,7 +144,14 @@ curl -X POST http://localhost:8000/admin/rules/bulk \
133
  }'
134
  ```
135
 
136
- ### Method 3: Using Python
 
 
 
 
 
 
 
137
 
138
  ```python
139
  import requests
@@ -172,6 +190,10 @@ When you add rules, the LLM will automatically:
172
  - βœ… Improve regex patterns for better matching
173
  - βœ… Suggest appropriate severity levels
174
  - βœ… Write clear descriptions
 
 
 
 
175
 
176
  **Example:**
177
  - **Input:** `Block password queries`
@@ -197,11 +219,15 @@ After adding rules, test them by asking questions that should be blocked:
197
  ## Best Practices
198
 
199
  1. **Start Simple** - Begin with basic rules, then add patterns
200
- 2. **Test Thoroughly** - Test rules with various phrasings
201
- 3. **Review Edge Cases** - Check if rules block legitimate queries
202
- 4. **Use Appropriate Severity** - Match severity to risk level
203
- 5. **Regular Updates** - Review and update rules periodically
204
- 6. **Document Patterns** - Add descriptions explaining what each rule blocks
 
 
 
 
205
 
206
  ## Common Patterns
207
 
 
4
 
5
  ## Quick Start
6
 
7
+ 1. **Simple Rules** - Copy from `example_rules.txt` and paste into Gradio UI or Next.js frontend
8
+ 2. **File Upload** - Drag and drop or upload TXT, PDF, DOC, or DOCX files directly
9
+ 3. **Detailed Rules** - Use `example_rules_detailed.json` for rules with patterns and severity
10
+ 4. **API** - Use the `/admin/rules`, `/admin/rules/bulk`, or `/admin/rules/upload-file` endpoints
11
 
12
  ## Rule Categories
13
 
 
102
  1. Open the IntegraChat Gradio interface
103
  2. Go to "Admin Rules & Compliance" tab
104
  3. Enter your tenant ID
105
+ 4. **Option A - Text Input**: Paste rules from `example_rules.txt` (one per line) and click "Upload / Append Rules"
106
+ 5. **Option B - File Upload**: Drag and drop or click to upload a TXT, PDF, DOC, or DOCX file containing rules
107
+ 6. Rules are automatically enhanced by LLM (identifies edge cases, improves patterns)
108
+ 7. Comment lines (starting with #) are automatically ignored
109
 
110
+ ### Method 2: Via Next.js Frontend
111
+
112
+ 1. Navigate to `/admin-rules` page
113
+ 2. Enter your tenant ID in the navbar
114
+ 3. **Text Input**: Paste rules in the text area and click "Upload / Append Rules"
115
+ 4. **File Upload**: Drag and drop files or click the drop zone to upload
116
+ 5. Click "Refresh Rules" to see your uploaded rules
117
+
118
+ ### Method 3: Via API (Programmatic)
119
 
120
  **Single Rule:**
121
  ```bash
 
132
 
133
  **Bulk Rules:**
134
  ```bash
135
+ curl -X POST "http://localhost:8000/admin/rules/bulk?enhance=true" \
136
  -H "Content-Type: application/json" \
137
  -H "x-tenant-id: your_tenant_id" \
138
  -d '{
 
144
  }'
145
  ```
146
 
147
+ **File Upload:**
148
+ ```bash
149
+ curl -X POST "http://localhost:8000/admin/rules/upload-file?enhance=true" \
150
+ -H "x-tenant-id: your_tenant_id" \
151
+ -F "file=@example_rules.txt"
152
+ ```
153
+
154
+ ### Method 4: Using Python
155
 
156
  ```python
157
  import requests
 
190
  - βœ… Improve regex patterns for better matching
191
  - βœ… Suggest appropriate severity levels
192
  - βœ… Write clear descriptions
193
+ - βœ… Process rules in chunks (5 at a time) to avoid timeouts
194
+ - βœ… Handle large rule sets efficiently
195
+
196
+ **Note**: Enhancement can be disabled by setting `enhance=false` in the API query parameter, but it's enabled by default for better rule quality.
197
 
198
  **Example:**
199
  - **Input:** `Block password queries`
 
219
  ## Best Practices
220
 
221
  1. **Start Simple** - Begin with basic rules, then add patterns
222
+ 2. **Use File Upload** - For large rule sets, upload from files instead of typing manually
223
+ 3. **Leverage LLM Enhancement** - Let the system enhance your rules automatically
224
+ 4. **Test Thoroughly** - Test rules with various phrasings
225
+ 5. **Review Edge Cases** - Check if rules block legitimate queries
226
+ 6. **Use Appropriate Severity** - Match severity to risk level (low for brief responses, high for blocking)
227
+ 7. **Comment Lines** - Use `#` for comments in rule files - they're automatically ignored
228
+ 8. **Regular Updates** - Review and update rules periodically
229
+ 9. **Document Patterns** - Add descriptions explaining what each rule blocks
230
+ 10. **Chunk Processing** - Large uploads are automatically chunked - be patient for 20+ rules
231
 
232
  ## Common Patterns
233