-
Notifications
You must be signed in to change notification settings - Fork 0
Core Concepts Locks
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.
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.
-
Lock Name (
LockName
): A unique identifier for the lock, used for debugging and configuration. -
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.
-
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.
- A list of
-
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.
- Originally intended to link locks to specific
-
Open State (
isOpen
):- Tracks whether the lock is open.
- If open, the lock allows executables to fire without rechecking conditions.
-
Evaluate Conditions:
- The lock evaluates all conditions using
IsSatisfiedByAgent
. - It checks each
KLEPCondition
against the current set of keys.
- The lock evaluates all conditions using
-
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.
-
State Management:
- The lock can explicitly open and close using
Unlock()
andLock()
methods. - Manual control over lock state is useful for persistent behaviors or forced resets.
- The lock can explicitly open and close using
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 Name (
keyName
):- The name of the key this condition evaluates.
- If the neuron has a key with this name, the condition may be satisfied.
-
Existence Requirement (
keyMustExist
):- True: The key must exist for the condition to pass.
- False: The key must not exist for the condition to pass.
-
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.
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.
-
Locks Control Flow:
- Ensure actions only fire when specific conditions are met.
-
Support Complex Logic:
- Mix AND/OR conditions to handle complex scenarios.
-
Manual Locking/Unlocking:
- Explicit control over lock state allows for persistent behaviors and manual overrides.
-
Modular Design with Key Loaders:
- By linking locks to SLASHkeyLoader instances, you can modularize lock behavior.
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.