Spaces:
Sleeping
Sleeping
Commit
Β·
93e2b71
1
Parent(s):
cb88e8d
chore: clean up README files after repository cleanup
Browse files- README.md +30 -105
- backend/README.md +23 -33
README.md
CHANGED
|
@@ -70,11 +70,8 @@ python app.py
|
|
| 70 |
Then access:
|
| 71 |
- **Gradio UI**: `http://localhost:7860`
|
| 72 |
- **FastAPI Docs**: `http://localhost:8000/docs`
|
| 73 |
-
- **Next.js Frontend** (optional): `cd frontend && npm install && npm run dev` β `http://localhost:3000`
|
| 74 |
-
- Use the role selector in the header to switch between viewer, editor, admin, or owner roles
|
| 75 |
-
- UI automatically shows/hides features based on selected role
|
| 76 |
|
| 77 |
-
> **Security Note:** REST requests that hit protected endpoints must include both `x-tenant-id` and `x-user-role` headers. Roles (`viewer`, `editor`, `admin`, `owner`) determine which actionsβsuch as document ingestion, rule uploads, or analytics accessβthe caller may perform.
|
| 78 |
|
| 79 |
---
|
| 80 |
|
|
@@ -110,7 +107,7 @@ Then access:
|
|
| 110 |
- **Real-Time Visualizations**: Reasoning path visualizer, tool invocation timeline, and tenant activity heatmap
|
| 111 |
- π **Live Web Search** β Google Programmable Search (Custom Search API) with tenant-aware MCP tooling
|
| 112 |
- π’ **Multi-Tenant Isolation** β Complete tenant isolation with centralized tenant ID management; backend enforces strict isolation for chat, ingestion, and admin ops
|
| 113 |
-
- π **Fine-Grained Role-Based Access Control (RBAC)** β Four-tier role system (viewer, editor, admin, owner) with
|
| 114 |
- π **Intelligent Multi-Tool Orchestration** β MCP agent orchestrator autonomously selects optimal tool chains (RAG + Web + LLM, etc.) based on query intent, context, latency predictions, and previous tool outputs. Context-aware routing enables sophisticated tool skipping for efficiency
|
| 115 |
- β‘ **Robust Error Handling** β Structured error responses, retry mechanisms, and graceful fallbacks (e.g., if RAG fails β fallback to LLM-only)
|
| 116 |
- π‘ **Streaming Responses** β Chat responses stream character-by-character using Server-Sent Events (SSE) for real-time user experience
|
|
@@ -169,7 +166,7 @@ Subsequent tool calls with the same `session_id` will receive a `memory` field c
|
|
| 169 |
|
| 170 |
## Role-Based Access Control (RBAC)
|
| 171 |
|
| 172 |
-
IntegraChat implements fine-grained role-based access control (RBAC) for
|
| 173 |
|
| 174 |
### Roles
|
| 175 |
|
|
@@ -231,7 +228,7 @@ PERMISSIONS = {
|
|
| 231 |
|
| 232 |
**Role Propagation:**
|
| 233 |
The user role is automatically propagated through the entire request pipeline:
|
| 234 |
-
1.
|
| 235 |
2. Backend API route receives and validates role
|
| 236 |
3. Role is passed to service layer (`process_ingestion()`, etc.)
|
| 237 |
4. Service layer passes role to MCP clients
|
|
@@ -252,40 +249,11 @@ If the role lacks permission, the API returns `403 Forbidden` with a descriptive
|
|
| 252 |
- Which roles are allowed for the action
|
| 253 |
- Instructions to change role in the UI
|
| 254 |
|
| 255 |
-
### Frontend RBAC
|
| 256 |
-
|
| 257 |
-
The frontend UI dynamically shows/hides features based on the selected role:
|
| 258 |
-
|
| 259 |
-
**Role Selector:**
|
| 260 |
-
- Located in the header navigation
|
| 261 |
-
- Dropdown to switch between roles (viewer, editor, admin, owner)
|
| 262 |
-
- Role is persisted in localStorage
|
| 263 |
-
- Changes take effect immediately across all pages
|
| 264 |
-
|
| 265 |
-
**Conditional UI Visibility:**
|
| 266 |
-
- **Navigation Links**: Only relevant links shown (e.g., editor doesn't see "Analytics" or "Admin Rules")
|
| 267 |
-
- **Page Sections**: Entire sections hidden if user lacks permission
|
| 268 |
-
- **Action Buttons**: Delete buttons hidden for editor role
|
| 269 |
-
- **Access Denied Pages**: Friendly error messages when accessing restricted routes
|
| 270 |
-
|
| 271 |
-
**Protected Routes:**
|
| 272 |
-
- `/ingestion` - Editor, Admin, Owner only
|
| 273 |
-
- `/analytics` - All roles can view (viewer, editor, admin, owner)
|
| 274 |
-
- `/admin-rules` - Admin, Owner only
|
| 275 |
-
|
| 276 |
-
**Implementation:**
|
| 277 |
-
- Permission utilities in `frontend/lib/permissions.ts`
|
| 278 |
-
- Conditional rendering in components based on role
|
| 279 |
-
- Access denied pages with clear messaging
|
| 280 |
-
|
| 281 |
### Using RBAC
|
| 282 |
|
| 283 |
-
1. **
|
| 284 |
-
2. **Verify Permissions**:
|
| 285 |
-
3. **
|
| 286 |
-
4. **Error Handling**: Access denied pages guide users on required roles
|
| 287 |
-
|
| 288 |
-
**Note**: Role changes are immediate and affect both UI visibility and API permissions. The role persists across page refreshes via localStorage.
|
| 289 |
|
| 290 |
---
|
| 291 |
|
|
@@ -301,7 +269,6 @@ IntegraChat includes three powerful visualization components that provide real-t
|
|
| 301 |
- Detailed metrics per step (latency, hit counts, token estimates)
|
| 302 |
- Visual icons for each step type
|
| 303 |
- **Where to find it**:
|
| 304 |
-
- Next.js frontend: Chat panel (expand "Visualizations" section)
|
| 305 |
- Gradio app: Debug & Reasoning tab
|
| 306 |
- **Data source**: `reasoning_trace` from agent responses
|
| 307 |
|
|
@@ -313,7 +280,6 @@ IntegraChat includes three powerful visualization components that provide real-t
|
|
| 313 |
- Result count badges
|
| 314 |
- Summary statistics (total tools, total time, average latency)
|
| 315 |
- **Where to find it**:
|
| 316 |
-
- Next.js frontend: Chat panel (expand "Visualizations" section)
|
| 317 |
- Gradio app: Debug & Reasoning tab
|
| 318 |
- **Data source**: `tool_traces` from agent responses
|
| 319 |
|
|
@@ -325,7 +291,7 @@ IntegraChat includes three powerful visualization components that provide real-t
|
|
| 325 |
- Per-tool usage trends with bar charts
|
| 326 |
- Trend indicators (up/down/stable)
|
| 327 |
- **Where to find it**:
|
| 328 |
-
-
|
| 329 |
- Configurable time window (default: 7 days)
|
| 330 |
- **Data source**: `/analytics/activity` and `/analytics/tool-usage` endpoints
|
| 331 |
|
|
@@ -413,13 +379,6 @@ IntegraChat includes three powerful visualization components that provide real-t
|
|
| 413 |
```
|
| 414 |
Access at `http://localhost:7860`
|
| 415 |
|
| 416 |
-
**Next.js Frontend** (optional, modern UI):
|
| 417 |
-
```bash
|
| 418 |
-
cd frontend
|
| 419 |
-
npm install
|
| 420 |
-
npm run dev
|
| 421 |
-
```
|
| 422 |
-
Access at `http://localhost:3000`
|
| 423 |
|
| 424 |
## Usage
|
| 425 |
|
|
@@ -469,33 +428,6 @@ The Gradio UI provides a comprehensive interface with five main tabs:
|
|
| 469 |
|
| 470 |
> **π‘ Tip:** Every action requires a Tenant ID. The Tenant ID persists across page refreshes and is managed centrally.
|
| 471 |
|
| 472 |
-
### Next.js Frontend (`frontend/`)
|
| 473 |
-
|
| 474 |
-
The modern Next.js operator console provides dedicated pages for each workflow:
|
| 475 |
-
|
| 476 |
-
| Route | Description |
|
| 477 |
-
| --- | --- |
|
| 478 |
-
| `/` | Landing page with hero section and quick access panels |
|
| 479 |
-
| `/ingestion` | Data ingestion walkthrough (text/URL/files) with document management |
|
| 480 |
-
| `/chat` | Chat console with MCP agent integration |
|
| 481 |
-
| `/analytics` | Analytics overview with visualizations |
|
| 482 |
-
| `/admin-rules` | Admin rule management interface |
|
| 483 |
-
| `/knowledge-base` | Document library with search, filter, and delete functionality |
|
| 484 |
-
|
| 485 |
-
**Key Features:**
|
| 486 |
-
- **Centralized Tenant ID Management** β Global React Context with localStorage persistence
|
| 487 |
-
- **Document Management** β Full CRUD operations for knowledge base
|
| 488 |
-
- **Improved Error Handling** β Clear error messages with retry options
|
| 489 |
-
- **Real-time Updates** β Automatic refresh after operations
|
| 490 |
-
- **Modern UI** β Tailwind CSS with responsive design
|
| 491 |
-
|
| 492 |
-
**To run:**
|
| 493 |
-
```bash
|
| 494 |
-
cd frontend
|
| 495 |
-
npm install
|
| 496 |
-
npm run dev
|
| 497 |
-
```
|
| 498 |
-
Then open `http://localhost:3000`. The tenant ID selector is available in the navbar on all pages.
|
| 499 |
|
| 500 |
---
|
| 501 |
|
|
@@ -555,7 +487,7 @@ All endpoints are served by the FastAPI backend at `http://localhost:8000`. Most
|
|
| 555 |
IntegraChat includes three powerful visualization components that provide real-time insights into agent behavior and system activity:
|
| 556 |
|
| 557 |
#### 1. Real-Time Reasoning Visualizer
|
| 558 |
-
- **Location**:
|
| 559 |
- **Features**:
|
| 560 |
- Step-by-step visualization of agent reasoning path
|
| 561 |
- Animated progression through reasoning steps
|
|
@@ -566,7 +498,7 @@ IntegraChat includes three powerful visualization components that provide real-t
|
|
| 566 |
- **Usage**: Automatically appears in chat panel when agent responses include reasoning traces
|
| 567 |
|
| 568 |
#### 2. Tool Invocation Timeline
|
| 569 |
-
- **Location**:
|
| 570 |
- **Features**:
|
| 571 |
- Visual timeline showing tool execution order
|
| 572 |
- Color-coded bars indicating tool status (success/error)
|
|
@@ -595,7 +527,7 @@ Most endpoints require:
|
|
| 595 |
- `x-tenant-id`: Tenant identifier for multi-tenant isolation
|
| 596 |
- `x-user-role`: Caller role for RBAC enforcement (`viewer`, `editor`, `admin`, or `owner`)
|
| 597 |
- **Important**: Role must be passed through the entire pipeline (UI β API β RAG Client β MCP Server)
|
| 598 |
-
- Role is automatically propagated from the
|
| 599 |
- If ingestion fails with permission errors, verify the role is set correctly in the UI and check backend logs for role propagation debug messages
|
| 600 |
- `Content-Type: application/json`: For POST requests with JSON payloads
|
| 601 |
|
|
@@ -621,8 +553,8 @@ IntegraChat follows a modular architecture with clear separation of concerns:
|
|
| 621 |
|
| 622 |
```
|
| 623 |
βββββββββββββββββββ
|
| 624 |
-
β Frontend UI β (Gradio
|
| 625 |
-
β
|
| 626 |
ββββββββββ¬βββββββββ
|
| 627 |
β
|
| 628 |
βΌ
|
|
@@ -689,7 +621,7 @@ IntegraChat uses **dual-backend storage** with automatic fallback for production
|
|
| 689 |
- Perfect for local development
|
| 690 |
- Automatic fallback when Supabase not configured
|
| 691 |
|
| 692 |
-
**Migration:**
|
| 693 |
|
| 694 |
---
|
| 695 |
|
|
@@ -709,17 +641,7 @@ IntegraChat supports Supabase for production-ready storage of admin rules and an
|
|
| 709 |
SUPABASE_SERVICE_KEY=your_service_role_key_here
|
| 710 |
```
|
| 711 |
|
| 712 |
-
3. **
|
| 713 |
-
```bash
|
| 714 |
-
python migrate_sqlite_to_supabase.py
|
| 715 |
-
```
|
| 716 |
-
|
| 717 |
-
4. **Verify setup**:
|
| 718 |
-
```bash
|
| 719 |
-
python verify_supabase_setup.py
|
| 720 |
-
```
|
| 721 |
-
|
| 722 |
-
See `SUPABASE_SETUP.md` and `SUPABASE_MIGRATION_COMPLETE.md` for detailed instructions and troubleshooting.
|
| 723 |
|
| 724 |
---
|
| 725 |
|
|
@@ -757,7 +679,7 @@ See `SUPABASE_SETUP.md` and `SUPABASE_MIGRATION_COMPLETE.md` for detailed instru
|
|
| 757 |
- **Solution**:
|
| 758 |
- Verify `SUPABASE_URL` and `SUPABASE_SERVICE_KEY` in `.env` (no quotes, no spaces)
|
| 759 |
- Use **service_role** key (not anon key) from Supabase Dashboard
|
| 760 |
-
-
|
| 761 |
- Ensure tables exist: run SQL scripts in Supabase SQL Editor
|
| 762 |
- Check FastAPI startup logs for backend detection messages
|
| 763 |
|
|
@@ -809,26 +731,32 @@ See `SUPABASE_SETUP.md` and `SUPABASE_MIGRATION_COMPLETE.md` for detailed instru
|
|
| 809 |
#### Tenant Isolation Issues
|
| 810 |
- **Issue**: Documents or data leaking between tenants
|
| 811 |
- **Solution**:
|
| 812 |
-
- Run `python verify_tenant_isolation.py` to test isolation
|
| 813 |
- Check database queries include `WHERE tenant_id = ...` filters
|
| 814 |
- Verify tenant ID normalization is working correctly
|
| 815 |
-
- Review
|
| 816 |
|
| 817 |
### Getting Help
|
| 818 |
|
| 819 |
1. **Check Logs**: Review FastAPI and MCP server logs for detailed error messages
|
| 820 |
2. **Run Diagnostics**: Use helper scripts in the Testing & Diagnostics section
|
| 821 |
-
3. **Verify Configuration**:
|
| 822 |
4. **Review Documentation**: See `backend/README.md` for backend-specific issues
|
| 823 |
|
| 824 |
---
|
| 825 |
|
| 826 |
## Testing & Diagnostics
|
| 827 |
|
| 828 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
|
| 830 |
-
|
| 831 |
-
Runs a comprehensive suite that covers analytics logging, admin rule storage, API reachability, andβmost importantlyβmulti-tenant RAG isolation.
|
| 832 |
- β
**Prerequisites:** FastAPI backend plus all MCP servers (RAG/Web/Admin) running locally.
|
| 833 |
- β
**What it checks:**
|
| 834 |
1. Direct database writes via the analytics and rules stores
|
|
@@ -851,7 +779,7 @@ IntegraChat ships with several helper scripts to validate the full stack end-to-
|
|
| 851 |
- `python test_manual.py`
|
| 852 |
The existing manual test runner remains useful for smoke-testing analytics logging, admin rule CRUD, and API response codes. Run it whenever you adjust schemas or update MCP endpoints.
|
| 853 |
|
| 854 |
-
> **Tip:**
|
| 855 |
|
| 856 |
---
|
| 857 |
|
|
@@ -896,11 +824,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
| 896 |
|
| 897 |
### Frontend
|
| 898 |
- **Gradio UI**: Full-featured interface with Plotly visualizations (`app.py`)
|
| 899 |
-
- **Next.js Console**: Modern React-based operator console (`frontend/`)
|
| 900 |
- **UI Libraries**:
|
| 901 |
- Plotly for interactive charts and visualizations
|
| 902 |
-
- Tailwind CSS for modern styling (Next.js)
|
| 903 |
-
- React 19 with TypeScript
|
| 904 |
|
| 905 |
### Data Storage
|
| 906 |
- **RAG Vector Store**: PostgreSQL with pgvector extension (via Supabase or direct connection)
|
|
@@ -1027,7 +952,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
| 1027 |
- Longer conversation support
|
| 1028 |
- Better agent coherence across extended interactions
|
| 1029 |
- Improved performance through structured context
|
| 1030 |
-
- **Documentation**:
|
| 1031 |
|
| 1032 |
### UI Improvements
|
| 1033 |
- **Modern Drag-and-Drop**: Intuitive file upload with visual feedback
|
|
|
|
| 70 |
Then access:
|
| 71 |
- **Gradio UI**: `http://localhost:7860`
|
| 72 |
- **FastAPI Docs**: `http://localhost:8000/docs`
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
> **Security Note:** REST requests that hit protected endpoints must include both `x-tenant-id` and `x-user-role` headers. Roles (`viewer`, `editor`, `admin`, `owner`) determine which actionsβsuch as document ingestion, rule uploads, or analytics accessβthe caller may perform.
|
| 75 |
|
| 76 |
---
|
| 77 |
|
|
|
|
| 107 |
- **Real-Time Visualizations**: Reasoning path visualizer, tool invocation timeline, and tenant activity heatmap
|
| 108 |
- π **Live Web Search** β Google Programmable Search (Custom Search API) with tenant-aware MCP tooling
|
| 109 |
- π’ **Multi-Tenant Isolation** β Complete tenant isolation with centralized tenant ID management; backend enforces strict isolation for chat, ingestion, and admin ops
|
| 110 |
+
- π **Fine-Grained Role-Based Access Control (RBAC)** β Four-tier role system (viewer, editor, admin, owner) with backend permission enforcement
|
| 111 |
- π **Intelligent Multi-Tool Orchestration** β MCP agent orchestrator autonomously selects optimal tool chains (RAG + Web + LLM, etc.) based on query intent, context, latency predictions, and previous tool outputs. Context-aware routing enables sophisticated tool skipping for efficiency
|
| 112 |
- β‘ **Robust Error Handling** β Structured error responses, retry mechanisms, and graceful fallbacks (e.g., if RAG fails β fallback to LLM-only)
|
| 113 |
- π‘ **Streaming Responses** β Chat responses stream character-by-character using Server-Sent Events (SSE) for real-time user experience
|
|
|
|
| 166 |
|
| 167 |
## Role-Based Access Control (RBAC)
|
| 168 |
|
| 169 |
+
IntegraChat implements fine-grained role-based access control (RBAC) for backend API endpoints. This ensures that users can only access features appropriate for their role level.
|
| 170 |
|
| 171 |
### Roles
|
| 172 |
|
|
|
|
| 228 |
|
| 229 |
**Role Propagation:**
|
| 230 |
The user role is automatically propagated through the entire request pipeline:
|
| 231 |
+
1. Client sends `x-user-role` header
|
| 232 |
2. Backend API route receives and validates role
|
| 233 |
3. Role is passed to service layer (`process_ingestion()`, etc.)
|
| 234 |
4. Service layer passes role to MCP clients
|
|
|
|
| 249 |
- Which roles are allowed for the action
|
| 250 |
- Instructions to change role in the UI
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
### Using RBAC
|
| 253 |
|
| 254 |
+
1. **Set Role**: Include `x-user-role` header in API requests with one of: `viewer`, `editor`, `admin`, or `owner`
|
| 255 |
+
2. **Verify Permissions**: Backend enforces role-based access automatically
|
| 256 |
+
3. **Error Handling**: API returns `403 Forbidden` with clear error messages when role lacks required permissions
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
---
|
| 259 |
|
|
|
|
| 269 |
- Detailed metrics per step (latency, hit counts, token estimates)
|
| 270 |
- Visual icons for each step type
|
| 271 |
- **Where to find it**:
|
|
|
|
| 272 |
- Gradio app: Debug & Reasoning tab
|
| 273 |
- **Data source**: `reasoning_trace` from agent responses
|
| 274 |
|
|
|
|
| 280 |
- Result count badges
|
| 281 |
- Summary statistics (total tools, total time, average latency)
|
| 282 |
- **Where to find it**:
|
|
|
|
| 283 |
- Gradio app: Debug & Reasoning tab
|
| 284 |
- **Data source**: `tool_traces` from agent responses
|
| 285 |
|
|
|
|
| 291 |
- Per-tool usage trends with bar charts
|
| 292 |
- Trend indicators (up/down/stable)
|
| 293 |
- **Where to find it**:
|
| 294 |
+
- Gradio app: Admin Analytics tab
|
| 295 |
- Configurable time window (default: 7 days)
|
| 296 |
- **Data source**: `/analytics/activity` and `/analytics/tool-usage` endpoints
|
| 297 |
|
|
|
|
| 379 |
```
|
| 380 |
Access at `http://localhost:7860`
|
| 381 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
## Usage
|
| 384 |
|
|
|
|
| 428 |
|
| 429 |
> **π‘ Tip:** Every action requires a Tenant ID. The Tenant ID persists across page refreshes and is managed centrally.
|
| 430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
|
| 432 |
---
|
| 433 |
|
|
|
|
| 487 |
IntegraChat includes three powerful visualization components that provide real-time insights into agent behavior and system activity:
|
| 488 |
|
| 489 |
#### 1. Real-Time Reasoning Visualizer
|
| 490 |
+
- **Location**: Debug tab (Gradio app)
|
| 491 |
- **Features**:
|
| 492 |
- Step-by-step visualization of agent reasoning path
|
| 493 |
- Animated progression through reasoning steps
|
|
|
|
| 498 |
- **Usage**: Automatically appears in chat panel when agent responses include reasoning traces
|
| 499 |
|
| 500 |
#### 2. Tool Invocation Timeline
|
| 501 |
+
- **Location**: Debug tab (Gradio app)
|
| 502 |
- **Features**:
|
| 503 |
- Visual timeline showing tool execution order
|
| 504 |
- Color-coded bars indicating tool status (success/error)
|
|
|
|
| 527 |
- `x-tenant-id`: Tenant identifier for multi-tenant isolation
|
| 528 |
- `x-user-role`: Caller role for RBAC enforcement (`viewer`, `editor`, `admin`, or `owner`)
|
| 529 |
- **Important**: Role must be passed through the entire pipeline (UI β API β RAG Client β MCP Server)
|
| 530 |
+
- Role is automatically propagated from the API request to backend API, then to RAG client, and finally to MCP server for permission checks
|
| 531 |
- If ingestion fails with permission errors, verify the role is set correctly in the UI and check backend logs for role propagation debug messages
|
| 532 |
- `Content-Type: application/json`: For POST requests with JSON payloads
|
| 533 |
|
|
|
|
| 553 |
|
| 554 |
```
|
| 555 |
βββββββββββββββββββ
|
| 556 |
+
β Frontend UI β (Gradio)
|
| 557 |
+
β Port 7860 β
|
| 558 |
ββββββββββ¬βββββββββ
|
| 559 |
β
|
| 560 |
βΌ
|
|
|
|
| 621 |
- Perfect for local development
|
| 622 |
- Automatic fallback when Supabase not configured
|
| 623 |
|
| 624 |
+
**Migration:** To migrate existing SQLite data to Supabase, refer to Supabase documentation for data migration strategies.
|
| 625 |
|
| 626 |
---
|
| 627 |
|
|
|
|
| 641 |
SUPABASE_SERVICE_KEY=your_service_role_key_here
|
| 642 |
```
|
| 643 |
|
| 644 |
+
3. **Verify setup**: Check that your Supabase project is accessible and tables are created correctly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
|
| 646 |
---
|
| 647 |
|
|
|
|
| 679 |
- **Solution**:
|
| 680 |
- Verify `SUPABASE_URL` and `SUPABASE_SERVICE_KEY` in `.env` (no quotes, no spaces)
|
| 681 |
- Use **service_role** key (not anon key) from Supabase Dashboard
|
| 682 |
+
- Verify Supabase credentials in `.env` file
|
| 683 |
- Ensure tables exist: run SQL scripts in Supabase SQL Editor
|
| 684 |
- Check FastAPI startup logs for backend detection messages
|
| 685 |
|
|
|
|
| 731 |
#### Tenant Isolation Issues
|
| 732 |
- **Issue**: Documents or data leaking between tenants
|
| 733 |
- **Solution**:
|
|
|
|
| 734 |
- Check database queries include `WHERE tenant_id = ...` filters
|
| 735 |
- Verify tenant ID normalization is working correctly
|
| 736 |
+
- Review database logs for tenant isolation
|
| 737 |
|
| 738 |
### Getting Help
|
| 739 |
|
| 740 |
1. **Check Logs**: Review FastAPI and MCP server logs for detailed error messages
|
| 741 |
2. **Run Diagnostics**: Use helper scripts in the Testing & Diagnostics section
|
| 742 |
+
3. **Verify Configuration**: Check `.env` file and Supabase connection
|
| 743 |
4. **Review Documentation**: See `backend/README.md` for backend-specific issues
|
| 744 |
|
| 745 |
---
|
| 746 |
|
| 747 |
## Testing & Diagnostics
|
| 748 |
|
| 749 |
+
You can test the system by:
|
| 750 |
+
|
| 751 |
+
- **API Testing**: Use the FastAPI interactive docs at `http://localhost:8000/docs` to test endpoints
|
| 752 |
+
- **Database Inspection**: Connect directly to your PostgreSQL/Supabase instance to verify tenant isolation
|
| 753 |
+
- **Log Monitoring**: Check FastAPI and MCP server logs for detailed error messages and debugging information
|
| 754 |
+
|
| 755 |
+
> **Tip:** Ensure the Python virtual environment is active (`source venv/bin/activate` or `.\venv\Scripts\activate`) and that `.env` contains the MCP server URLs/LLM settings.
|
| 756 |
+
|
| 757 |
+
---
|
| 758 |
|
| 759 |
+
## Demo Video
|
|
|
|
| 760 |
- β
**Prerequisites:** FastAPI backend plus all MCP servers (RAG/Web/Admin) running locally.
|
| 761 |
- β
**What it checks:**
|
| 762 |
1. Direct database writes via the analytics and rules stores
|
|
|
|
| 779 |
- `python test_manual.py`
|
| 780 |
The existing manual test runner remains useful for smoke-testing analytics logging, admin rule CRUD, and API response codes. Run it whenever you adjust schemas or update MCP endpoints.
|
| 781 |
|
| 782 |
+
> **Tip:** Ensure the Python virtual environment is active (`source venv/bin/activate` or `.\venv\Scripts\activate`) and that `.env` contains the MCP server URLs/LLM settings.
|
| 783 |
|
| 784 |
---
|
| 785 |
|
|
|
|
| 824 |
|
| 825 |
### Frontend
|
| 826 |
- **Gradio UI**: Full-featured interface with Plotly visualizations (`app.py`)
|
|
|
|
| 827 |
- **UI Libraries**:
|
| 828 |
- Plotly for interactive charts and visualizations
|
|
|
|
|
|
|
| 829 |
|
| 830 |
### Data Storage
|
| 831 |
- **RAG Vector Store**: PostgreSQL with pgvector extension (via Supabase or direct connection)
|
|
|
|
| 952 |
- Longer conversation support
|
| 953 |
- Better agent coherence across extended interactions
|
| 954 |
- Improved performance through structured context
|
| 955 |
+
- **Documentation**: Context engineering features are integrated throughout the agent orchestrator and MCP server
|
| 956 |
|
| 957 |
### UI Improvements
|
| 958 |
- **Modern Drag-and-Drop**: Intuitive file upload with visual feedback
|
backend/README.md
CHANGED
|
@@ -64,7 +64,7 @@ cp env.example .env # update MCP URLs + LLM settings
|
|
| 64 |
celery -A backend.workers.analytics_worker worker --loglevel=info
|
| 65 |
```
|
| 66 |
|
| 67 |
-
The Gradio UI (`python app.py`)
|
| 68 |
|
| 69 |
## Key Endpoints
|
| 70 |
|
|
@@ -87,16 +87,13 @@ Refer to the root `README.md` for the complete endpoint tables.
|
|
| 87 |
|
| 88 |
## Diagnostics & Tenant Isolation
|
| 89 |
|
| 90 |
-
|
| 91 |
|
| 92 |
-
-
|
| 93 |
-
-
|
| 94 |
-
-
|
| 95 |
-
- `python check_supabase_rules.py` β Checks Supabase admin rules configuration and RLS policies.
|
| 96 |
-
- `python migrate_sqlite_to_supabase.py` β One-shot migration script to copy existing SQLite data to Supabase.
|
| 97 |
-
- `python test_manual.py` β Legacy manual smoke test harness (analytics store, admin rules, API surface).
|
| 98 |
|
| 99 |
-
> **Troubleshooting tip:** If
|
| 100 |
|
| 101 |
## Recent Improvements
|
| 102 |
|
|
@@ -135,7 +132,7 @@ Use the helper scripts in the repo root when validating backend changes:
|
|
| 135 |
- **Configuration**: Tune behavior via environment variables:
|
| 136 |
- `MCP_MEMORY_MAX_ITEMS`: Maximum number of tool outputs to keep per session (default: 10)
|
| 137 |
- `MCP_MEMORY_TTL_SECONDS`: Time-to-live for memory entries in seconds (default: 900)
|
| 138 |
-
- **Comprehensive Testing**:
|
| 139 |
|
| 140 |
### AI-Generated KB Metadata
|
| 141 |
|
|
@@ -199,7 +196,7 @@ Every tool now returns strict JSON schemas for consistency:
|
|
| 199 |
- **Improved Error Handling**:
|
| 200 |
- Permission errors (403) return clear messages with actionable guidance
|
| 201 |
- Error messages specify which roles are allowed for each action
|
| 202 |
-
-
|
| 203 |
- **Debug Logging**: Added debug logging in route handlers and services to trace role values:
|
| 204 |
- Logs role received in route handler
|
| 205 |
- Logs role passed to process_ingestion
|
|
@@ -255,15 +252,15 @@ The rule enhancement system includes intelligent fallback mechanisms:
|
|
| 255 |
|
| 256 |
This ensures users always receive useful rule explanations even when the LLM service is unavailable or slow.
|
| 257 |
|
| 258 |
-
### Real-Time Visualization Components (
|
| 259 |
|
| 260 |
-
The
|
| 261 |
|
| 262 |
-
- **Reasoning Path Visualizer**: Step-by-step visualization of agent reasoning with
|
| 263 |
-
- **Tool Invocation Timeline**: Visual timeline showing tool execution order, latency, and result counts.
|
| 264 |
-
- **
|
| 265 |
|
| 266 |
-
All visualizations
|
| 267 |
|
| 268 |
### Context Engineering (Latest)
|
| 269 |
|
|
@@ -298,7 +295,7 @@ The system implements comprehensive context engineering strategies based on Anth
|
|
| 298 |
- Better agent coherence across extended interactions
|
| 299 |
- Improved performance through structured context
|
| 300 |
|
| 301 |
-
|
| 302 |
|
| 303 |
## Environment Variables (excerpt)
|
| 304 |
|
|
@@ -313,7 +310,6 @@ Defined in `env.example`:
|
|
| 313 |
- `OLLAMA_URL`, `OLLAMA_MODEL` (or `GROQ_API_KEY` + `LLM_BACKEND=groq`)
|
| 314 |
- `SUPABASE_URL`, `SUPABASE_SERVICE_KEY` - **Required for Supabase backend** (admin rules + analytics)
|
| 315 |
- If not set, the system automatically falls back to SQLite in `data/` directory
|
| 316 |
-
- See `SUPABASE_SETUP.md` in the root directory for detailed setup instructions
|
| 317 |
- `GOOGLE_SEARCH_API_KEY`, `GOOGLE_SEARCH_CX_ID` - Credentials for Google Programmable Search used by `web.search`
|
| 318 |
- `MCP_MEMORY_MAX_ITEMS` - Maximum number of tool outputs to keep per session (default: 10)
|
| 319 |
- `MCP_MEMORY_TTL_SECONDS` - Time-to-live for memory entries in seconds (default: 900)
|
|
@@ -339,15 +335,9 @@ Both `RulesStore` and `AnalyticsStore` support dual-backend storage with automat
|
|
| 339 |
SUPABASE_SERVICE_KEY=your_service_role_key_here
|
| 340 |
```
|
| 341 |
|
| 342 |
-
3. **Verify configuration**:
|
| 343 |
-
```bash
|
| 344 |
-
python verify_supabase_setup.py
|
| 345 |
-
```
|
| 346 |
|
| 347 |
-
4. **Migrate existing data** (if you have SQLite data):
|
| 348 |
-
```bash
|
| 349 |
-
python migrate_sqlite_to_supabase.py
|
| 350 |
-
```
|
| 351 |
|
| 352 |
### How It Works
|
| 353 |
|
|
@@ -364,7 +354,7 @@ Both `RulesStore` and `AnalyticsStore` support dual-backend storage with automat
|
|
| 364 |
- **Admin Rules**: `admin_rules` table in Supabase
|
| 365 |
- **Analytics**: `tool_usage_events`, `redflag_violations`, `rag_search_events`, `agent_query_events`
|
| 366 |
|
| 367 |
-
|
| 368 |
|
| 369 |
## Unified MCP tool instructions
|
| 370 |
|
|
@@ -406,12 +396,12 @@ Agents that speak the Model Context Protocol should connect to the `integrachat`
|
|
| 406 |
|
| 407 |
### Document Ingestion Permission Errors
|
| 408 |
- **403 Forbidden**: If you see "Role 'viewer' is not permitted to perform 'ingest_documents'":
|
| 409 |
-
-
|
| 410 |
- Verify `x-user-role` header is being sent correctly (check backend logs for `π DEBUG:` messages)
|
| 411 |
- Check that role is being propagated through the pipeline: route handler β process_ingestion β RAG client β MCP server
|
| 412 |
- Review debug logs to see where role might be getting lost or defaulting to "viewer"
|
| 413 |
- **Role Propagation**: The role must flow through:
|
| 414 |
-
1.
|
| 415 |
2. Route handler receives it as `x_user_role` parameter
|
| 416 |
3. Route handler passes it to `process_ingestion(user_role=...)`
|
| 417 |
4. `process_ingestion` passes it to `rag_client.ingest_with_metadata(user_role=...)`
|
|
@@ -422,15 +412,15 @@ Agents that speak the Model Context Protocol should connect to the `integrachat`
|
|
| 422 |
- **404 Not Found**: Verify the document_id exists and belongs to the correct tenant
|
| 423 |
- **Tenant ID mismatch**: The system normalizes tenant IDs, but ensure you're using the same tenant_id format as when documents were ingested
|
| 424 |
- **Check logs**: Database deletion logs show detailed information about tenant ID matching and document existence
|
| 425 |
-
- **Role Propagation**: Ensure user role is being passed correctly - deletion requires `admin` or `owner` role. The role is now properly propagated from
|
| 426 |
|
| 427 |
### Rule Management Issues
|
| 428 |
- **Timeout Errors**: If rule enhancement times out:
|
| 429 |
-
- Disable LLM enhancement
|
| 430 |
- Add rules in smaller batches (1-3 rules at a time)
|
| 431 |
- Enhancement timeout increased to 180s per chunk (5 rules)
|
| 432 |
- **Rule Deletion 404**: Can now delete by rule number or full text. If using number, ensure it's a valid index (1-based)
|
| 433 |
-
- **Permission Errors**: Rule management requires `admin` or `owner` role. Check that role is set correctly in the
|
| 434 |
|
| 435 |
### Supabase Configuration Issues
|
| 436 |
- **Data still going to SQLite**: Check that `SUPABASE_URL` and `SUPABASE_SERVICE_KEY` are set correctly in `.env` (no quotes, no spaces)
|
|
|
|
| 64 |
celery -A backend.workers.analytics_worker worker --loglevel=info
|
| 65 |
```
|
| 66 |
|
| 67 |
+
The Gradio UI (`python app.py`) talks to the FastAPI layer at `http://localhost:8000`.
|
| 68 |
|
| 69 |
## Key Endpoints
|
| 70 |
|
|
|
|
| 87 |
|
| 88 |
## Diagnostics & Tenant Isolation
|
| 89 |
|
| 90 |
+
When validating backend changes:
|
| 91 |
|
| 92 |
+
- **API Testing**: Use the FastAPI interactive docs at `http://localhost:8000/docs` to test endpoints
|
| 93 |
+
- **Database Inspection**: Connect directly to your PostgreSQL/Supabase instance to verify tenant isolation and check that documents are tagged with the correct `tenant_id`
|
| 94 |
+
- **Log Monitoring**: Check FastAPI and MCP server logs for detailed error messages and debugging information
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
> **Troubleshooting tip:** If you suspect tenant isolation issues, check database queries to confirm they include `WHERE tenant_id = ...` filters, then restart the unified MCP server so it reloads the updated SQL filtering logic.
|
| 97 |
|
| 98 |
## Recent Improvements
|
| 99 |
|
|
|
|
| 132 |
- **Configuration**: Tune behavior via environment variables:
|
| 133 |
- `MCP_MEMORY_MAX_ITEMS`: Maximum number of tool outputs to keep per session (default: 10)
|
| 134 |
- `MCP_MEMORY_TTL_SECONDS`: Time-to-live for memory entries in seconds (default: 900)
|
| 135 |
+
- **Comprehensive Testing**: Conversation memory system tested through integration with agent orchestrator
|
| 136 |
|
| 137 |
### AI-Generated KB Metadata
|
| 138 |
|
|
|
|
| 196 |
- **Improved Error Handling**:
|
| 197 |
- Permission errors (403) return clear messages with actionable guidance
|
| 198 |
- Error messages specify which roles are allowed for each action
|
| 199 |
+
- Error messages specify which roles are allowed for each action
|
| 200 |
- **Debug Logging**: Added debug logging in route handlers and services to trace role values:
|
| 201 |
- Logs role received in route handler
|
| 202 |
- Logs role passed to process_ingestion
|
|
|
|
| 252 |
|
| 253 |
This ensures users always receive useful rule explanations even when the LLM service is unavailable or slow.
|
| 254 |
|
| 255 |
+
### Real-Time Visualization Components (Gradio UI)
|
| 256 |
|
| 257 |
+
The Gradio UI includes powerful visualization components:
|
| 258 |
|
| 259 |
+
- **Reasoning Path Visualizer**: Step-by-step visualization of agent reasoning with status indicators and detailed metrics. Available in Debug & Reasoning tab.
|
| 260 |
+
- **Tool Invocation Timeline**: Visual timeline showing tool execution order, latency, and result counts. Available in Debug & Reasoning tab.
|
| 261 |
+
- **Analytics Dashboard**: Query activity and per-tool usage trends. Available in Admin Analytics tab.
|
| 262 |
|
| 263 |
+
All visualizations automatically populate when agent responses include `reasoning_trace` and `tool_traces` data.
|
| 264 |
|
| 265 |
### Context Engineering (Latest)
|
| 266 |
|
|
|
|
| 295 |
- Better agent coherence across extended interactions
|
| 296 |
- Improved performance through structured context
|
| 297 |
|
| 298 |
+
Context engineering features are integrated throughout the agent orchestrator and MCP server.
|
| 299 |
|
| 300 |
## Environment Variables (excerpt)
|
| 301 |
|
|
|
|
| 310 |
- `OLLAMA_URL`, `OLLAMA_MODEL` (or `GROQ_API_KEY` + `LLM_BACKEND=groq`)
|
| 311 |
- `SUPABASE_URL`, `SUPABASE_SERVICE_KEY` - **Required for Supabase backend** (admin rules + analytics)
|
| 312 |
- If not set, the system automatically falls back to SQLite in `data/` directory
|
|
|
|
| 313 |
- `GOOGLE_SEARCH_API_KEY`, `GOOGLE_SEARCH_CX_ID` - Credentials for Google Programmable Search used by `web.search`
|
| 314 |
- `MCP_MEMORY_MAX_ITEMS` - Maximum number of tool outputs to keep per session (default: 10)
|
| 315 |
- `MCP_MEMORY_TTL_SECONDS` - Time-to-live for memory entries in seconds (default: 900)
|
|
|
|
| 335 |
SUPABASE_SERVICE_KEY=your_service_role_key_here
|
| 336 |
```
|
| 337 |
|
| 338 |
+
3. **Verify configuration**: Check that your Supabase project is accessible and tables are created correctly.
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
+
4. **Migrate existing data** (if you have SQLite data): Use Supabase migration tools or database export/import methods.
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
### How It Works
|
| 343 |
|
|
|
|
| 354 |
- **Admin Rules**: `admin_rules` table in Supabase
|
| 355 |
- **Analytics**: `tool_usage_events`, `redflag_violations`, `rag_search_events`, `agent_query_events`
|
| 356 |
|
| 357 |
+
For detailed Supabase setup instructions, refer to the Supabase documentation and ensure tables are created correctly.
|
| 358 |
|
| 359 |
## Unified MCP tool instructions
|
| 360 |
|
|
|
|
| 396 |
|
| 397 |
### Document Ingestion Permission Errors
|
| 398 |
- **403 Forbidden**: If you see "Role 'viewer' is not permitted to perform 'ingest_documents'":
|
| 399 |
+
- Ensure the `x-user-role` header is set to "editor", "admin", or "owner"
|
| 400 |
- Verify `x-user-role` header is being sent correctly (check backend logs for `π DEBUG:` messages)
|
| 401 |
- Check that role is being propagated through the pipeline: route handler β process_ingestion β RAG client β MCP server
|
| 402 |
- Review debug logs to see where role might be getting lost or defaulting to "viewer"
|
| 403 |
- **Role Propagation**: The role must flow through:
|
| 404 |
+
1. Client sends `x-user-role` header
|
| 405 |
2. Route handler receives it as `x_user_role` parameter
|
| 406 |
3. Route handler passes it to `process_ingestion(user_role=...)`
|
| 407 |
4. `process_ingestion` passes it to `rag_client.ingest_with_metadata(user_role=...)`
|
|
|
|
| 412 |
- **404 Not Found**: Verify the document_id exists and belongs to the correct tenant
|
| 413 |
- **Tenant ID mismatch**: The system normalizes tenant IDs, but ensure you're using the same tenant_id format as when documents were ingested
|
| 414 |
- **Check logs**: Database deletion logs show detailed information about tenant ID matching and document existence
|
| 415 |
+
- **Role Propagation**: Ensure user role is being passed correctly - deletion requires `admin` or `owner` role. The role is now properly propagated from API request β API β RAG Client β MCP Server
|
| 416 |
|
| 417 |
### Rule Management Issues
|
| 418 |
- **Timeout Errors**: If rule enhancement times out:
|
| 419 |
+
- Disable LLM enhancement by not setting `enhance=true` in the request
|
| 420 |
- Add rules in smaller batches (1-3 rules at a time)
|
| 421 |
- Enhancement timeout increased to 180s per chunk (5 rules)
|
| 422 |
- **Rule Deletion 404**: Can now delete by rule number or full text. If using number, ensure it's a valid index (1-based)
|
| 423 |
+
- **Permission Errors**: Rule management requires `admin` or `owner` role. Check that role is set correctly in the `x-user-role` header
|
| 424 |
|
| 425 |
### Supabase Configuration Issues
|
| 426 |
- **Data still going to SQLite**: Check that `SUPABASE_URL` and `SUPABASE_SERVICE_KEY` are set correctly in `.env` (no quotes, no spaces)
|