Skip to content

OrchestrationStore

Lightweight store for Kuralle orchestration state, keyed by session id.

This is NOT a SessionStore. CF owns message persistence via its cf_ai_chat_agent_messages table. This store only tracks the state Kuralle needs for multi-agent orchestration within a specific call / logical session:

  • currentAgent: which agent is active
  • workingMemory: key-value context injected into prompts
  • agentStates: per-agent state (flow node, extraction data, etc.)
  • handoffHistory: agent-to-agent transfer log

Keyed by sessionId, so multiple calls into the same DO get isolated orchestration state (fresh flow node per call, independent handoff history). DO-scoped state that should survive across calls (Gemini resumption handle, long-term memory facts) belongs in this.state, not here.

Earlier versions used a hardcoded 'default' sentinel, collapsing every call in a DO into the same row. That was fine for single-call demos but caused cross-call state leaks (flow stuck at confirm on the 2nd call).

new OrchestrationStore(sql): OrchestrationStore;
Parameter Type

sql

SqlExecutor

OrchestrationStore

cleanup(maxAgeMs): Promise<number>;

Garbage-collect rows older than maxAgeMs. Call from an alarm or on DO wake to keep the table bounded when users don’t explicitly end calls.

Parameter Type

maxAgeMs

number

Promise<number>


clear(id): Promise<void>;
Parameter Type

id

string

Promise<void>


get(id): Promise<
| OrchestrationState
| null>;
Parameter Type

id

string

Promise< | OrchestrationState | null>


save(id, state): Promise<void>;
Parameter Type

id

string

state

OrchestrationState

Promise<void>