Repository is archived
No release in over 3 years
Cognitive flexibility for LegionIO — switching between task sets, mental rules, and strategies with perseveration detection
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

 Project Readme

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_flexibility

Development

bundle install
bundle exec rspec
bundle exec rubocop

License

MIT