Add Dynamic Context / State Initialization to ChatKit Sessions (for Multi-Tenant and Context-Aware Applications)

Please add support for dynamic frontend-to-agent context passing in ChatKit session initialization.
This would allow developers to embed ChatKit in complex multi-tenant or multi-context web apps where runtime state (like tenant IDs, organization settings, or user scopes) must be injected automatically when a chat session starts.


Current Limitation
When creating a ChatKit session using the Hosted Agent Builder, the session.create() API only accepts:

{
  "workflow": "workflow-id",
  "version": "v1",
  "user": "user-id"
}

There’s currently no supported field for:

  • context (runtime variables)

  • inputs or metadata

  • Updating context mid-session

As a result, developers cannot programmatically pass critical application state (e.g., tenant scope, active project, feature flags, etc.) from the frontend to the hosted agent.


Why This Matters
For enterprise SaaS products, context-aware AI is essential. In multi-tenant apps:

  • Each message must be scoped to a specific tenant or workspace

  • Context may need to switch dynamically (e.g. user switches organizations mid-chat)

  • Context should never appear in chat text or be user-visible

Without dynamic context injection, the only workarounds are:

  • Polluting the chat history with system messages like “My organization is Tenant-123”

  • Encoding state into the user field (hacky and brittle)

  • Self-hosting the Agents SDK (adds cost, ops complexity, and defeats the “hosted” model advantage)


Proposed API Enhancement

Allow context or inputs during session initialization and updates:

POST /v1/chatkit/sessions
{
  "workflow": "workflow-id",
  "user": "user-id",
  "context": {
    "tenant_id": "tenant-123",
    "plan": "enterprise",
    "locale": "en-AU"
  }
}

And optionally an endpoint to update context mid-session:

PATCH /v1/chatkit/sessions/{id}/context


Benefits

  • Enables secure, automatic tenant scoping

  • Improves UX (no system prompts visible to end users)

  • Makes ChatKit viable for multi-tenant SaaS and enterprise integrations

  • Keeps developers within the Hosted Agent Builder ecosystem (no need to self-host)

5 Likes

Facing the same issue. At the moment, I find the only way to pass through initial state variables, which are not possible to update. Only starting a new thread will update the state variables.