AI-native operational assistant for claims, families, and tickets. Not a chatbot – each run is a structured operational analysis with tool-backed recommendations.
-
Frontend:
frontend/- Next.js (App Router), React, TypeScript, Tailwind CSS.
- Components:
ChatWindow– manages runs, streaming UX, auto-scroll, typing indicator.DynamicRenderer– renders UI based onui_type(summary | table | suggestion | confirmation).DataTable,ConfirmationCard,MessageBubble– UI primitives for structured responses.
lib/api.ts– typed client and simulated streaming from the backend.types/ai.ts– shared UI response contract.
-
Backend:
backend/- FastAPI service exposing
/aiand/health. ai/system_prompt.py– single source of truth for LLM instructions and UI contract.ai/schemas.py– Pydantic models forAIRequest,AIResponse,SuggestedAction, andUIType.ai/tools.py– modular tools:list_rejected_claimsfix_invalid_claim_dates(dry-run-only by default)list_large_families
ai/orchestrator.py– orchestration layer that decides which tools to call and shapes a UI response.
- FastAPI service exposing
This separation keeps AI orchestration and business logic decoupled, and the frontend consumes a clean, typed UI protocol instead of free-form text.
- Tool-first, not chat-first:
- User queries are routed to tools (claims, families, anomaly checks).
- Tools return structured, domain-specific results.
- Orchestrator converts those results into a UI-oriented JSON shape.
- UI contract:
- Every AI response respects:
ui_type: "summary" | "table" | "suggestion" | "confirmation"title: stringmessage: stringdata: Record<string, unknown>[]suggested_actions: { label, description, payload }[]
- The React frontend renders components dynamically from this contract, so new behaviors can be added on the backend without rewriting the UI.
- Every AI response respects:
- Proactive behavior:
- On load, the frontend triggers a proactive anomaly overview rather than waiting for a chat message.
- The orchestrator aggregates tool outputs into a snapshot of anomalies (rejections, invalid dates, large families).
- Tools are defined in
backend/ai/tools.pywith:- Pure functions operating on an in-memory context (
ToolContext). - A
TOOLS_REGISTRYdescribing tool parameters and purpose (suitable for LLM function calling in a real setup). - A
call_tool(name, args)dispatcher.
- Pure functions operating on an in-memory context (
- Safety constraints:
fix_invalid_claim_datesruns as a dry-run by default and never mutates data.- Any real mutation would require:
- A
confirmation-typed response from the orchestrator, and - An explicit user action handled via
SuggestedAction.
- A
- The orchestrator (
ai/orchestrator.py) currently uses deterministic rules to:- Map natural language queries to tools.
- Combine multiple tool outputs into overviews.
- Emit suggested actions that encode next-best operations in
payload.
In production, you would swap the rule engine with an LLM using BASE_SYSTEM_PROMPT and TOOLS_REGISTRY for function calling.
SmartOps AI is designed so retrieval can be plugged in without disturbing the UI:
- Where to plug RAG:
- Add a
retrievers/ordata/module underbackend/that:- Connects to your vector store (claims notes, tickets, policies).
- Exposes retrieval functions like
retrieve_related_tickets(claim_id)orretrieve_policy_context(family_id).
- Call these from
ai/orchestrator.pybefore or after tools to enrich context.
- Add a
- How it fits:
- Retrieved context becomes additional
datarows or explanatory fields inAIResponse. - No frontend change is needed as long as you honor the same
AIResponseshape.
- Retrieved context becomes additional
- There is no generic chat history UI; instead:
- Each interaction is framed as an operational run with clearly defined tools.
- The UI emphasizes tables, summaries, and confirmations — not long-form text.
- The assistant:
- Calls tools to inspect operational data (claims, families).
- Returns structured, typed JSON consumed by a dynamic renderer.
- Surfaces proactive suggestions for follow-up analyses and safe write operations.
The result is an AI control panel, not a conversational toy.
cd backend
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 8000The backend exposes:
GET /health– basic health check.POST /ai– main AI orchestration endpoint.
cd frontend
pnpm install # or: npm install / yarn install
export NEXT_PUBLIC_BACKEND_URL="http://localhost:8000"
pnpm dev # or: npm run dev / yarn devThen open http://localhost:3000 in your browser.
- Proactive anomalies (also runs automatically on load):
- “Run proactive anomaly overview”
- “Show me an anomaly snapshot for claims and families”
- Rejected claims:
- “Show me rejected claims with details”
- “List all rejected claims and their amounts”
- Invalid claim dates:
- “Simulate fixing invalid claim dates”
- “Find claims with future service dates and propose corrections”
- Large families:
- “Show large families driving claim volume”
- “List all families with more than 5 members”
Use the suggestion buttons in the UI to chain analyses and explore how SmartOps AI orchestrates tools and returns structured responses.
flowchart LR
U[User] <--> FE[SmartOps Frontend]
FE <--> BE[SmartOps Backend / Core Engine]
BE <--> LLM[LLM: Generate payload / analyze]
%% Domain Adapters
BE <--> OA[OpenIMIS Backend]
OA <--> DB[PostgreSQL]
BE <--> EC[eCommerce Backend]
EC <--> ECDB[eCommerce DB]
BE <--> ERP[ERP Backend]
ERP <--> ERPDB[ERP DB]
sequenceDiagram
participant U as User
participant FE as SmartOps Frontend
participant BE as SmartOps Backend
participant LLM as LLM
participant OA as openIMIS API
participant DB as PostgreSQL
U->>FE: Prompt "List rejected claims 01-01 to 31-01"
FE->>BE: POST /ai
BE->>LLM: Request GraphQL payload
LLM-->>BE: Returns GraphQL query payload
BE->>OA: POST /api/graphql with query
OA->>DB: Query claims
DB-->>OA: Results JSON
OA-->>BE: JSON response
BE->>LLM: Send results for analysis
LLM-->>BE: Detects anomalies/fraudes, builds fix payload
BE-->>FE: AIResponse (confirmation required)
U->>FE: Confirm fixes
FE->>BE: POST /ai/confirm
BE->>OA: POST /api/graphql with LLM-generated mutation(s)
OA->>DB: Apply fixes
DB-->>OA: Success / Errors
OA-->>BE: Updated status
BE-->>FE: Summary response
FE-->>U: Structured UI rendering
SmartOps operates as an AI orchestration layer on top of openIMIS.
- No direct database access
- All business logic enforced by openIMIS
- JWT token forwarding for RBAC
- Tool-first AI design
- Structured UI protocol (AIResponse contract)