-
Notifications
You must be signed in to change notification settings - Fork 0
SlashMemory
Roll4d4 edited this page Feb 23, 2025
·
1 revision
The SLASHMemory class is an experimental module for KLEP, introducing a memory system to AI agents. It allows agents to remember experiences, evaluate key importance, and transfer significant experiences to long-term memory. This feature is designed to support adaptive behavior by leveraging past experiences.
-
Short-Term Memory Management:
- Stores active experiences with heat values, indicating recent importance.
- Cools down over time, simulating natural memory decay.
-
Long-Term Memory Storage:
- Transfers highly significant experiences to long-term memory.
- Maintains a fixed capacity, automatically discarding the oldest memories.
-
Memory Scoring System:
- Evaluates key importance using positive and negative scores.
- Aids decision-making by influencing the desirability of actions.
-
Emotional Integration:
- Can interface with the
KLEPEmotionsystem to create emotionally charged memories.
- Can interface with the
private Dictionary<string, (float heat, float positiveScore, float negativeScore)> shortTermMemory = new Dictionary<string, (float, float, float)>();
private List<HashSet<string>> longTermMemory;-
Short-Term Memory (
Dictionary<string, (float heat, float positiveScore, float negativeScore)>):-
Stores active keys with associated metadata, including:
- Heat: Indicates recency and importance.
- Positive & Negative Scores: Tracks success or failure linked to keys.
-
Stores active keys with associated metadata, including:
-
Long-Term Memory (
List<HashSet<string>>):- Holds significant snapshots of key states, typically triggered by important events.
- Snapshots are represented as sets of key names, allowing contextual recall.
public void Initialize(KLEPNeuron neuron)
{
currentNeuron = neuron;
}- Associates the memory system with a specific KLEPNeuron.
- Prepares the system to store and evaluate keys based on the neuron's experiences.
public void AddOrUpdateKey(string keyName, bool success)
{
if (!shortTermMemory.ContainsKey(keyName))
{
shortTermMemory[keyName] = (1.0f, 0f, 0f); // Initial heat, positive, and negative scores
}
var (heat, positiveScore, negativeScore) = shortTermMemory[keyName];
heat = 1.0f; // Reset heat to max
positiveScore += success ? 1 : 0;
negativeScore += success ? 0 : 1;
shortTermMemory[keyName] = (heat, positiveScore, negativeScore);
EvaluateForKeyTransfer(keyName);
OnMemoryUpdated?.Invoke(keyName);
}-
Manages key heat:
- Heat represents recency, resetting to max on key reactivation.
- Higher heat values make keys candidates for long-term memory transfer.
-
Score Management:
- Increments positive/negative scores based on success parameter.
- Allows KLEP agents to evaluate the historical reliability of keys.
private void CoolDownKeys()
{
foreach (var key in shortTermMemory.Keys.ToList())
{
var (heat, positiveScore, negativeScore) = shortTermMemory[key];
heat -= coolDownRate * Time.deltaTime;
if (heat <= 0)
{
shortTermMemory.Remove(key);
OnMemoryUpdated?.Invoke(key); // Notify removal
}
else
{
shortTermMemory[key] = (heat, positiveScore, negativeScore);
}
}
}- Gradually reduces heat, simulating natural memory decay.
- Removes keys when heat reaches zero, cleaning up short-term memory.
- Emulates forgetfulness, ensuring only relevant keys persist.
private void TransferToLongTermMemory()
{
HashSet<string> snapshot = new HashSet<string>(shortTermMemory.Keys);
if (longTermMemory.Count >= longTermMemoryCapacity)
{
longTermMemory.RemoveAt(0); // Remove the oldest snapshot
}
longTermMemory.Add(snapshot);
OnMemoryTransferredToLongTerm?.Invoke("Snapshot added");
foreach (var key in snapshot)
{
shortTermMemory.Remove(key);
}
}- Captures a snapshot of current short-term memory.
- Adds significant experiences to long-term memory, enforcing capacity limits.
- Cleans up short-term memory by removing transferred keys.
public void CaptureSnapshotForTraumaticExperience()
{
HashSet<string> snapshot = new HashSet<string>(currentNeuron.heldElements.Select(key => key.Name));
if (longTermMemory.Count >= longTermMemoryCapacity)
{
longTermMemory.RemoveAt(0);
}
longTermMemory.Add(snapshot);
}- Manually captures memory snapshots, ideal for traumatic or significant experiences.
- Overrides normal thresholds, forcing memory storage.
- Useful for critical events, such as near-death experiences or major successes.
- During combat, the SLASHMemory system tracks keys such as "Enemy_KEY", "LowHealth_KEY", and "FindCover_KEY".
- If the NPC survives, the keys are positively reinforced, increasing their heat and positive score.
- If the NPC fails, negative scores are increased, decreasing desirability for future use.
- Highly significant experiences, such as escaping with 1% health, are immediately transferred to long-term memory.
- In future encounters, the NPC might prioritize cover if similar keys are present, showing learned behavior.
- SLASHMemory introduces a memory model to KLEP AI, allowing agents to learn from experiences.
- Heat values and positive/negative scores enable adaptive decision-making.
- Short-term memory decay ensures only relevant experiences are retained, avoiding memory bloat.
- Long-term memory captures significant events, enabling agents to adapt over extended periods.
- This module is experimental, but illustrates the potential for AI agents to develop learned behaviors over time.
Would you like further integration of SLASHMemory with KLEPEmotion, goals, or reinforcement learning in KLEP? ๐