Skip to content
Konstera
Docs · Reference
Konstera documentation.

Getting started, SDK quickstart, manifest reference, kernel MCP services, deploy guide and FAQ — everything you need to build and run agents on Konstera.

Multi-tenancy

Konstera is multi-tenant by default. Every piece of tenant data — invocations, state, vectors, credentials, approvals, cost events — is scoped so an agent instance can only read/write its own tenant's rows.

You don't configure this. The kernel enforces it. This page covers how it enforces it so agent authors know what invariants they can rely on.

The invariant#

Every tenant-scoped DB write and read sets the app.tenant_id PostgreSQL session GUC via SET LOCAL. Row-Level Security policies enforce tenant_id = current_setting('app.tenant_id')::uuid.

Translation:

  • The agent's SDK calls the kernel via MCP
  • The kernel resolves tenant_id from the caller's instance_id (via tenant_agent_instances table)
  • Before any DB query, the kernel sets app.tenant_id on the connection
  • PostgreSQL's RLS layer filters every row by that GUC
  • The application DB role is konstera_app with NOBYPASSRLS — so even a buggy query cannot leak across tenants

A buggy agent that accidentally sends another tenant's UUID in a request would just get a "not found" response — the row exists, but RLS hides it.

The ambient tenant scope#

Server-side, every request handler enters an AmbientTenantScope block that pins the tenant for the duration of the request. Nested calls (including Temporal activities) inherit it:

C#
// Konstera kernel — simplified
using var scope = AmbientTenantScope.Enter(resolvedTenantId);
await _dbContext.Database.ExecuteSqlRawAsync(
    "SET LOCAL app.tenant_id = {0}", scope.TenantId
);
// ... any DB query here is tenant-scoped

The SET LOCAL is transaction-scoped. If a Temporal activity opens its own transaction, the kernel re-enters the scope + re-sets the GUC.

X-Konstera-Tenant header#

For HTTP requests that cross tenant boundaries (admin UIs, inbound webhooks not tied to an agent instance), the request carries an X-Konstera-Tenant: <uuid> header. The kernel validates the header against the authenticated user's grants + sets the ambient scope.

Agents don't send this header — the agent's identity (the instance ID) already tells the kernel which tenant.

SoD (Segregation of Duties)#

Beyond tenant isolation, M8 added role-level SoD inside a tenant:

  • kernel_admin can set the ambient tenant on any request
  • tenant_user can only operate on their own tenant
  • agent_runtime can only operate on invocations their granted agents initiated
  • A submitter of an approval cannot be the approver — enforced at the DB level, not just the application layer

See the human-in-the-loop recipe for how SoD shows up in agent code (via submitter_role on ctx.human.request).

What's tenant-scoped#

ResourceTableAgent surface
Agent instancestenant_agent_instancesctx.agent_id, ctx.instance_id
Stateinstance_statectx.state.*
Vectorsinstance_vectorsctx.vector.*
Credentialscredentialsctx.credentials.get()
Invocationsinvocations + invocation_logsautomatic
Approvalsapprovalsctx.human.*
Cost eventsusage_eventsautomatic + ctx.cost.record()
Rulesrulesctx.rule.*
Contexttenant_context_term/entity/skillctx.semantic.*

What's NOT tenant-scoped#

Shared across all tenants (same bytes for everyone):

  • Agent package images — one konstera/customer-service-agent:0.9.2 image across tenants; instance config varies per tenant
  • Capability catalogue — the canonical capability names + schemas
  • Standard Context Pack — the 24+24+2 pack ships to every tenant (tenant can author overrides, those are scoped)

These live in BYPASSRLS tables accessed via the konstera_admin role.

What the agent sees#

From the agent's perspective, multi-tenancy is invisible. The code:

Python
async def handle(self, req, ctx):
    cursor = await ctx.state.get("last_processed_id")  # scoped to this tenant
    orders = await ctx.capability.call("orders.lookup_by_email", email=req.input)
    # these orders belong to this tenant's Shopify connection
    await ctx.vector.upsert(
        namespace="shared:policies",  # 'shared:' = all this tenant's agents
        content="...",
    )

...runs on tenant A and tenant B with identical semantics. The agent reads/writes its tenant's data; no code change needed.

Cross-tenant admin ops (operator surface)#

When an operator needs to run cross-tenant queries (platform health, cost rollups), the kernel uses a separate connection with konstera_admin (BYPASSRLS). These ops are:

  • Admin-only HTTP endpoints under /api/admin/*
  • Behind IAM checks + a separate audit log (admin_actions)
  • Not reachable from agent code

Agent authors can safely treat multi-tenancy as a black box.

Debugging multi-tenancy#

If an agent gets unexpected "no results" and you suspect tenant scoping, check the invocation trace in the portal — the trace shows:

  • The resolved tenant_id for this invocation
  • The app.tenant_id GUC set on each DB call
  • The RLS policy that filtered each query

Mismatches here are a kernel-side bug; file an issue.

See also#