Multi-Tenant Setup
End-to-end walkthrough for setting up a multi-tenant Inconvo agent with data isolation.
This example walks through setting up an Inconvo agent for a multi-tenant SaaS application where each organisation should only see their own data.
Scenario
Section titled “Scenario”You have an ecommerce analytics database shared by multiple organisations. Each organisation has their own users, orders, and products. Every table has an organisation_id column.
-
Connect your database
Follow the Connect a Database guide to add your database connection.
-
Define user context fields
In the Inconvo dashboard, go to Configure and define a user context field:
- Field name:
organisationId - Type:
integer
- Field name:
-
Set context filters on every queryable table
For each table that should be scoped to a tenant, add a context filter:
-- users tableWHERE users.organisation_id = userContext.organisationId;-- orders tableWHERE orders.organisation_id = userContext.organisationId;-- products tableWHERE products.organisation_id = userContext.organisationId; -
Add table prompts for business context
Add prompts to help the agent understand your data:
users table: Users are also referred to as accounts. A user is considered a customer if the
last_order_atis not null. -
Create conversations with userContext
When creating a conversation from your backend, pass the tenant’s
organisationId:import Inconvo from "@inconvoai/node";const inconvo = new Inconvo({apiKey: process.env.INCONVO_API_KEY,});// Get the organisationId from your authenticated user's sessionconst organisationId = req.user.organisationId;const conversation = await inconvo.agents.conversations.create(process.env.INCONVO_AGENT_ID,{userIdentifier: req.user.id,userContext: {organisationId,},},); -
Verify data isolation
Create conversations with different
organisationIdvalues and confirm each returns only that organisation’s data.
What happens at query time
Section titled “What happens at query time”When a user in organisation 1 asks “How many orders did we have last month?”, Inconvo will:
- Identify the
orderstable as relevant - Apply the context filter:
WHERE orders.organisation_id = 1 - Add the time filter for “last month”
- Return only organisation 1’s order count
The user never sees data from other organisations.