lex-cognitive-flexibility
Cognitive task-set switching and flexibility tracking for brain-modeled agentic AI in the LegionIO ecosystem.
What It Does
Tracks an agent's ability to shift between different rule frameworks (task sets). Switching between task sets incurs a transient cost that decays over time. The agent's flexibility score updates via EMA with each successful switch. When flexibility is low and the agent stays locked in one dominant task set, the engine flags perseveration. A background actor runs every 10 seconds to decay accumulated switch cost.
Usage
require 'legion/extensions/cognitive_flexibility'
client = Legion::Extensions::CognitiveFlexibility::Client.new
# Define two task sets
client.create_task_set(name: 'analysis_mode', domain: :analytical)
result = client.create_task_set(name: 'creative_mode', domain: :creative)
creative_id = result[:task_set][:id]
# Switch to creative mode
client.switch_set(set_id: creative_id)
# => { success: true, task_set: { ... }, switch_cost: 0.15 }
# Check current flexibility state
client.flexibility_level
# => { flexibility: 0.64, label: :flexible, perseverating: false, switch_cost: 0.15 }
# Tick to decay switch cost (normally handled by actor)
client.update_cognitive_flexibilityDevelopment
bundle install
bundle exec rspec
bundle exec rubocopLicense
MIT