Back to Coordinator
Workflow 03 / Orchestration

Orchestration: Allocation

VRAM LRU Eviction, Session Addressing, and Incremental Sync Counting

Sequence / Session Orchestration Internals
            sequenceDiagram
                participant NPC as Actor (Level 3)
                participant SUB as Subsystem (Level 2)
                participant K as Kernel (Level 1)
                
                NPC->>SUB: 1. GetOrCreateSession(ptr)
                SUB->>SUB: 2. Lookup (SessionMap)
                alt Miss & Slot Available
                    SUB->>K: 3. Request New VRAM Slot
                else Miss & Full
                    SUB->>SUB: 4. Execute LRU Eviction (Oldest)
                    SUB->>K: 5. Free Slot & Overwrite
                end
                K-->>SUB: 6. Return Physical Handle
                SUB->>SUB: 7. Init LastSentCount=0
                SUB-->>NPC: 8. Handover SessionKey (void*)
            
01 / Concept: Complex Resource Arbitration

The subsystem acts as the global "Memory Butler." It coordinates dialogue requests for hundreds of NPCs within a finite KV Cache pool.

LRU Eviction (Least Recently Used)

When VRAM slots are exhausted, the subsystem automatically sacrifices the NPC "who hasn't spoken to the player longest," reclaiming its slot for the active agent.

Incremental Tracking

The subsystem maintains a SessionMsgCountMap per pointer. This ensures that only textual deltas are pushed to the kernel, avoiding redundant compute cycles.

02 / Source Code Demo (C++)

How the subsystem manages session orchestration:

// 1. Map UObject address to physical hash
void* Key = (void*)this;

// 2. Internal Orchestration (LiteRtLmSubsystem.cpp)
void* Session = SessionMap.FindRef(Key);
if (!Session) {
    // Arbitrate slot and establish physical link
    Session = Internal_AllocateSlot(Key);
}