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:
- Classify — intent + sentiment + confidence via
llm_classify. Tracked in aClassificationResultstruct. - Resolve awareness — visitor timezone → temporal/business-hours/cultural context injected into the enriched session context.
- Transition — evaluate the current state's outbound transitions; guards branch on the classification result.
- LLM generate — for
llm_generateactions, invoke the host'sLlmProviderwith the compiled systemPrompt + responseRules + conversation history. - 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.