Skip to content

Reference

The state machine runtime

src/lib/asmi/runtime/state-machine-runner.ts is the in-repo reference implementation of processMessage. The published npm package at @avatar-state-machine-interface/runtime is the same logic repackaged for host-site consumption — same function names, same behavior.

One turn through processMessage goes:

  1. Classify — intent + sentiment + confidence via llm_classify. Tracked in a ClassificationResult struct.
  2. Resolve awareness — visitor timezone → temporal/business-hours/cultural context injected into the enriched session context.
  3. Transition — evaluate the current state's outbound transitions; guards branch on the classification result.
  4. LLM generate — for llm_generate actions, invoke the host's LlmProvider with the compiled systemPrompt + responseRules + conversation history.
  5. Emit — expression changes + outbound app events (handoff, satisfaction_pulse, offered_contact, …) returned to the caller.

The public LlmProvider interface is dead-simple:

ts
interface LlmProvider {
  generate(params: {
    systemPrompt: string;
    userPrompt: string;
    history: Array<{ role: "user" | "model"; content: string }>;
    temperature: number;
    maxTokens: number;
  }): Promise<string>;
}

Implement that once against whatever LLM your app already uses — OpenAI, Anthropic, Gemini, a local model — and you are done on the runtime side.

A product by Broentech Sentinel.

Broentech Sentinel