Questa pagina non è ancora tradotta in italiano: qui la trovi in inglese.
Serve several tenants
Serve several companies from one instance: tell MentorAgent the tenant of each request, and keep memory, limits, conversations, metrics and documents apart.
On this page
Use this page when one instance of your application serves more than one company, for example in a software-as-a-service product. Each company is a tenant. MentorAgent keeps each user apart, but two users of two companies could share the memory of anonymous users, a document search or the dashboard. Tell MentorAgent the tenant of each request, and it keeps each company apart. Your data stays with your application: MentorAgent passes the tenant on, and your services filter on it.
When to choose it
Section titled “When to choose it”- Choose it when one instance serves several companies, and a company must never see another's memory, conversations, figures or documents.
- Leave it out when each company has its own instance, or its own database behind its own deployment. Without a resolver there is one tenant, as before.
Name the tenant of each request
Section titled “Name the tenant of each request”Write an IMentorTenantResolver that names the tenant from the request, and register it once. Your actions read the tenant from IMentorTenant:
// The tenant is a claim of the signed-in user
public class ClaimTenantResolver : IMentorTenantResolver
{
// null: the request is refused
public ValueTask<string?> ResolveAsync(
MentorTenantRequest request, CancellationToken cancellationToken)
=> ValueTask.FromResult(
request.User?.FindFirst("tenant_id")?.Value);
}
// An action reads the tenant of the request
public class OrderActions(IMentorTenant tenant, IOrderStore store)
{
[MentorAction(Description = "Counts the open orders",
ReadOnly = true)]
public Task<int> CountOpenOrders() =>
store.CountOpenAsync(tenant.Id!);
}builder.Services.AddMentorAgent(options => { /* … */ });
builder.Services.AddMentorTenantResolver<ClaimTenantResolver>();- You choose where the tenant comes from. The resolver receives the signed-in user, the channel and the request's services. You can read the tenant from a claim of the user, as in the example, from a host name, or from a header that your gateway sets.
- One per application. MentorAgent asks the resolver once for every unit of work, before it does anything else for it. A unit of work is a turn that starts in a Blazor circuit, on the hub, on
/mentor/chator in an Agent-to-Agent (A2A) task, and everytools/listandtools/callof the Model Context Protocol (MCP) server. IMentorTenant.Idis the tenant of the current turn, or of the current call to the MCP server. Before the first turn,GetIdAsync()asks the resolver first. ReadingIdwhere no tenant was resolved throws.
Never without a tenant
Section titled “Never without a tenant”MentorAgent refuses the request when the resolver throws, or answers null, an empty text or white space. The turn then ends before the model is called, a tools/call gets an error, a tools/list lists nothing, and an A2A task fails. MentorAgent does not use a shared tenant instead, because that would put the request among the data that every tenant shares. The user reads, in the language of the widget, that the organization could not be identified.
A conversation stays with its tenant. In a circuit or a hub connection, MentorAgent refuses a turn whose tenant differs from the tenant that the conversation began with, and it tells the user to reload the page.
What stays apart
Section titled “What stays apart”| What | With a resolver |
|---|---|
| Memory and the rate limit | The key of the user's memory and of RateLimitPerUser starts with the tenant. The same user in two tenants has two memories and two allowances, and the anonymous bucket is one per tenant. The MCP server's allowance per caller is per tenant too. |
| Saved conversations | A session snapshot names its tenant, and is restored for that tenant only. A snapshot of another tenant, or with no tenant where a resolver is registered, is refused with 400 on /mentor/session. |
| Metrics and the dashboard | Every counter and the mentor.turn span carry the mentoragent.tenant tag. The dashboard and GET /mentor/admin/metrics show the reader's tenant only, and answer 403 to a reader without a tenant. |
| Document search | A source receives the tenant in MentorRagRequest.TenantId: see Search your documents. |
| Logs | Every log line of a turn, your code's included, is written in a log scope with mentoragent.tenant. A provider that includes scopes shows it. |
What stays with your application
Section titled “What stays with your application”- Your data. An action reads
IMentorTenant.Idand asks your services for that tenant's data. MentorAgent does not filter what your methods return. - The documents of each tenant. MentorAgent filters no document. A source that holds several tenants' documents returns those of
TenantId. With the vector store source, setFilter. A source that implements only the olderSearchAsync(query, maxResults)never sees the tenant, and a warning says so at its first search with one. - The conversation history that you store. The history that MentorAgent keeps is already separate for each conversation. Your
ChatHistoryProviderFactoryruns after the tenant is known, so readIMentorTenantthere and store the history by tenant. A singleChatHistoryProviderinstance serves every tenant, and a warning at startup says so. - A metrics store. The figures of a tenant are kept in memory since the process started. An
IMentorMetricsStoresaves the instance's totals; to serve a tenant's figures from your backend, it implementsQueryAsync(tenant, …). - Budgets. A limit that stops a tenant when it has spent its budget belongs to the service in front of your application.
Roles, policies and the governor
Section titled “Roles, policies and the governor”The tenant is not a role. RequiredRoles still reads the user's roles. A rule per tenant, such as an action that only some companies have, belongs to an action policy or to the governor, which can read IMentorTenant from the request's services.
Common errors
Section titled “Common errors”Every request is refused: the organization could not be identified
Section titled “Every request is refused: the organization could not be identified”The resolver answered nothing. Check that the claim, the header or the host name that it reads is there on every channel: the hub, /mentor/chat, the MCP server and A2A read the user of the request, after ASP.NET Core authentication.
A conversation is refused: it belongs to another organization
Section titled “A conversation is refused: it belongs to another organization”The tenant of the turn is not the one that the conversation began with, for example after the user switched company in the same page. Reload the page to start a new conversation.
Restoring a conversation answers 400
Section titled “Restoring a conversation answers 400”The snapshot belongs to another tenant, or it was saved without a resolver. A snapshot is restored only for the tenant that saved it.
Vedi anche
Sezione “Vedi anche”- Search your documents — Let the agent answer from your own documents: a source of your own or any vector store, the relevance threshold, citations, failures, and what it costs.
- Roles from your sign-in — Make the roles of your sign-in reach RequiredRoles: JWT bearer tokens, Microsoft Entra ID app roles and groups, Windows groups, and roles from your database.
- Production checklist — Settings to review before production: governance, safety check, rate limits, cost and routing, history, several instances, observability and outgoing data.
- Ruoli, conferma e governance — Ruoli e approvazione human-in-the-loop per i tool di un agente AI in .NET: controlli nel codice, non nel prompt, su ogni canale, e cosa resta a te.
