EN 中文
Back to Overview

LiteRtLm_CreateConversation

Creates a basic conversation Session. Allocates a new KV Cache slot and context manager within the engine.

01. Session Allocation Logic

graph LR Engine[LiteRT-LM Engine] -->|Spawn| Conv[Conversation Object] subgraph KV_Pool [VRAM KV Pool] Slot1[Session 1 Cache] Slot2[Session 2 Cache] end Conv -->|Owner| Slot1

Each Conversation handle holds an independent context state machine. It is responsible for recording dialogue history and occupies VRAM space defined by max_num_tokens.

02. Parameter and Return Value

void* LiteRtLm_CreateConversation(void* engine_ptr);
Parameter / Return ValueDetailed Description
engine_ptr Valid engine pointer returned by CreateEngine.
Return Value (void*) Session handle.
Used for subsequent message appending and triggering Inference. Returns NULL if creation fails (e.g., insufficient VRAM to allocate a new slot).

03. Simple Initialization Example

// Create a new Session without any history
void* MyConversation = LiteRtLm_CreateConversation(EngineHandle);

if (MyConversation) {
    // Ready to start conversation...
}