Table of Contents

Event MemoryEvicted

Namespace
LMKit.Agents
Assembly
LM-Kit.NET.dll

Occurs before a memory entry is evicted due to capacity enforcement.

public event EventHandler<MemoryEvictedEventArgs> MemoryEvicted

Returns

EventHandler<MemoryEvictedEventArgs>
Occurs before a memory entry is evicted due to capacity enforcement.

Examples

Example: Protecting critical memories from eviction

memory.MemoryEvicted += (sender, e) =>
{
    Console.WriteLine($"Evicting: {e.Text}");

    // Protect high-value data sources
    if (e.DataSourceIdentifier == "critical_knowledge")
    {
        e.Cancel = true;
    }
};

Remarks

Set Cancel to true to prevent eviction of a specific entry. The next candidate in the eviction order will be evaluated instead.

If all candidates are cancelled, no eviction occurs and the memory count may exceed MaxMemoryEntries.