Skip to content

KuralleThreadAgent

Generic production Durable Object: deploy one class and create one named instance per authenticated (tenantId, threadId) pair.

Type Parameter Default type

Env

unknown

State

unknown

new KuralleThreadAgent<Env, State>(ctx, env): KuralleThreadAgent<Env, State>;
Parameter Type

ctx

DurableObjectState

env

Env

KuralleThreadAgent<Env, State>

KuralleAgent.constructor

onChatMessage(onFinish, options?): Promise<Response>;

Called by CF when a chat message arrives.

CF has already:

  1. Received the WebSocket message from the client
  2. Parsed and validated it
  3. Persisted the user message to cf_ai_chat_agent_messages
  4. Populated this.messages with the full conversation history

We:

  1. Create a BridgeSessionStore (CF messages + orchestration state)
  2. Build and run Kuralle Runtime
  3. Return an SSE Response

CF then:

  1. Reads the SSE stream via _reply()
  2. Builds assistant message parts via applyChunkToParts()
  3. Persists the assistant message
  4. Broadcasts to all connected clients
  5. Handles stream resumability
Parameter Type

onFinish

GenerateTextOnFinishCallback<ToolSet>

options?

OnChatMessageOptions

Promise<Response>

KuralleAgent.onChatMessage


onRequest(request): Promise<Response>;

HTTP endpoint handler. Adds Kuralle-specific endpoints on top of CF’s defaults.

Parameter Type

request

Request

Promise<Response>

KuralleAgent.onRequest


runScheduledKuralleJob(job): Promise<void>;

DO-alarm callback for scheduled jobs. Wake jobs run an agent-initiated turn and persist + broadcast the assistant reply through CF’s machinery (same path as resumeWithSignal); other job kinds go to onScheduledJob for subclasses to handle.

Parameter Type

job

ScheduledJob

Promise<void>

KuralleAgent.runScheduledKuralleJob