All work
MSFA Multi-Tenant AI Agent Platform
A production AI assistant for a multi-tenant enterprise SaaS, secure and cost-controlled on every run.

The problem
Tenants on an enterprise platform wanted an assistant that could answer questions and generate reports from their own data, without one tenant ever seeing another's data, and without runaway model costs.
The approach
- A LangChain/LangGraph ReAct agent behind a NestJS API and a Next.js UI.
- Layered gate checks before any run: platform switches, plan features, then user permissions.
- A middleware stack around every call: permission-based tool filtering, PII redaction, model retry with cross-provider fallback, call limits, human-in-the-loop approvals and per-tenant token budgets.
- Tools for report generation and read-only SQL. SQL is restricted to curated views by a parser allowlist and a locked-down database role, on top of PostgreSQL row-level security.
- Clarification and approval interrupts are checkpointed in Redis, so a run can pause for a human and resume exactly where it stopped.
- A provider-agnostic model layer (OpenRouter, OpenAI-compatible, local Ollama) with encrypted keys and task-based model profiles.
Architecture
How a request flows through the system, top to bottom.
- Client
- Next.js UI
- API
- NestJS
- Gate checks: platform → plan → permission
- Agent
- LangGraph ReAct
- Redis checkpoints
- Human-in-the-loop interrupts
- Middleware
- Tool filtering
- PII redaction
- Retry + fallback
- Token budgets
- Tools
- Report generation
- Read-only SQL (allowlist, curated views)
- Models & data
- OpenRouter / OpenAI-compatible / Ollama
- PostgreSQL + RLS
- LangSmith tracing
Results
- isolation enforced at gate, tool and database layers
- Multi-tenant
- token budgets and call limits keep cost predictable
- Per-tenant
- behind one model layer, with automatic fallback
- 3 providers
Stack
TypeScript · NestJS · Next.js · LangChain · LangGraph · PostgreSQL (RLS) · Redis · OpenRouter · Ollama · LangSmith · Docker