Skip to content

Core Concepts Locks

Roll4d4 edited this page Feb 22, 2025 · 2 revisions

๐Ÿ” KLEPLock: The Gatekeeper of Executable Actions

In KLEP, a lock acts as a gatekeeper, determining whether certain actions (executables) are allowed to fire. By evaluating conditions against available keys, KLEPLock provides a controlled and predictable flow of AI behaviors.


๐Ÿง  What Is a KLEPLock?

A KLEPLock is a ScriptableObject that manages access to behaviors in KLEP's key-lock-executable process. It assesses conditions and decides whether an executable can fire based on the keys present in the neuron's key set.

๐Ÿ” Core Components of KLEPLock:

  1. Lock Name (LockName): A unique identifier for the lock, used for debugging and configuration.

  2. Attractiveness (Attractiveness):

    • Represents the priority of the lock.
    • When combined with the attraction value of a key, it helps the KLEPAgent decide which action to take.
  3. Conditions (conditions):

    • A list of KLEPCondition objects that set the requirements for unlocking the lock.
    • Supports basic checks, such as "Key exists", as well as more complex logic through AND/OR evaluations.
    • Designed with extensibility in mind, allowing for future development to incorporate additional condition types and more advanced checks.
  4. Key Loaders (keyLoader):

    • Originally intended to link locks to specific SLASHkeyLoader instances, providing modular property management.
    • However, this feature is currently unused, as locks do not directly interact with properties through key loaders.
    • This functionality is likely to be phased out, simplifying lock behavior and reducing unnecessary complexity in future iterations of KLEP.
  5. Open State (isOpen):

    • Tracks whether the lock is open.
    • If open, the lock allows executables to fire without rechecking conditions.

๐Ÿ”— How Does a Lock Work?

  1. Evaluate Conditions:

    • The lock evaluates all conditions using IsSatisfiedByAgent.
    • It checks each KLEPCondition against the current set of keys.
  2. OR and AND Logic:

    • OR Conditions: The lock opens if any OR condition is true.
    • AND Conditions: The lock only opens if all AND conditions are true.
  3. State Management:

    • The lock can explicitly open and close using Unlock() and Lock() methods.
    • Manual control over lock state is useful for persistent behaviors or forced resets.

๐Ÿง  How KLEPCondition Works:

๐Ÿ” What Is a KLEPCondition?

A KLEPCondition is a simple rule that determines whether a lock should open. Each condition is tied to a specific key and evaluates whether that key must exist or not exist in the neuron's set of keys.

๐Ÿ› ๏ธ Key Components:

  1. Key Name (keyName):

    • The name of the key this condition evaluates.
    • If the neuron has a key with this name, the condition may be satisfied.
  2. Existence Requirement (keyMustExist):

    • True: The key must exist for the condition to pass.
    • False: The key must not exist for the condition to pass.
  3. OR Logic (isOrCondition):

    • Determines whether this condition operates as an OR condition.
    • OR conditions are evaluated first, and if any OR condition is true, the lock opens.

๐Ÿ” How Does It Evaluate?

public bool EvaluateCondition(HashSet<KLEPKey> elements)
{
    bool keyExists = elements.Any(k => k.KeyName == keyName);
    return keyMustExist ? keyExists : !keyExists;
}
  • Searches for the key in the neuron's current keys.
  • Returns true if the condition is met, allowing the lock to potentially open.

๐Ÿšฆ Key Takeaways:

  1. Locks Control Flow:

    • Ensure actions only fire when specific conditions are met.
  2. Support Complex Logic:

    • Mix AND/OR conditions to handle complex scenarios.
  3. Manual Locking/Unlocking:

    • Explicit control over lock state allows for persistent behaviors and manual overrides.
  4. Modular Design with Key Loaders:

    • By linking locks to SLASHkeyLoader instances, you can modularize lock behavior.

โœ… Conclusion:

KLEPLocks are the gatekeepers of KLEP's decision-making process. By evaluating conditions and controlling when executables can fire, they maintain a structured flow in the neuron's behavior cycle. This ensures that agents only act when appropriate, supporting both simple triggers and complex logical flows.