Atomic cognitive processing cycle for brain-modeled agentic AI. Implements the core tick loop with 16 active phases, 4 operating modes, and mode transition logic.
lex-tick is the central orchestrator of the LegionIO cognitive architecture. Every cognitive action the agent performs happens within a tick. A tick advances the agent's internal state, runs the appropriate phases for the current mode, and produces a result record.
The agent operates in one of four modes at any time:
| Mode | Description | Phases Run | Tick Budget |
|---|---|---|---|
dormant |
No active signals | memory_consolidation only |
0.2s |
dormant_active |
Dream cycle — idle consolidation | 10 dream phases, then backoff | 5.0s |
sentinel |
Low-activity monitoring | 5 phases | 0.5s |
full_active |
Full cognitive engagement | All 16 phases | 5.0s |
Mode transitions are driven by signal salience thresholds and time-since-signal:
- Any signal:
dormant->sentinel - High salience (>= 0.7) or human direct input:
sentinel->full_active - No high-salience signal for 300s:
full_active->sentinel - No signal for 600s while sentinel and dream backoff elapsed:
sentinel->dormant_active(dream cycle) - No signal for 3600s while sentinel:
sentinel->dormant - No signal for 1800s while dormant and dream backoff elapsed:
dormant->dormant_active(dream cycle) - Completed dream cycle:
dormant_active->dormant, with backoff before another dream cycle - Emergency trigger (
:firmware_violation,:extinction_protocol): immediatefull_active
sensory_processing(12% budget)emotional_evaluation(8%)memory_retrieval(12%)knowledge_retrieval(5%)identity_entropy_check(4%)working_memory_integration(5%)procedural_check(8%)prediction_engine(12%)mesh_interface(4%)social_cognition(4%)theory_of_mind(4%)gut_instinct(4%)action_selection(4%)memory_consolidation(4%)homeostasis_regulation(5%)post_tick_reflection(5%)
Phase budgets are informational — enforcement is at the tick level, not per-phase.
memory_auditassociation_walkcontradiction_resolutionidentity_entropy_checkagenda_formationconsolidation_commitknowledge_promotiondream_reflectionpartner_reflectiondream_narration
Add to your Gemfile:
gem 'lex-tick'require 'legion/extensions/tick'
# Execute a tick with signals and phase handlers
result = Legion::Extensions::Tick::Runners::Orchestrator.execute_tick(
signals: [{ salience: 0.8, source_type: :human_direct, content: "Hello" }],
phase_handlers: {
sensory_processing: ->(state:, signals:, prior_results:) {
{ processed: signals.size }
},
action_selection: ->(state:, signals:, prior_results:) {
{ action: :respond }
}
}
)
# Result shape
result[:mode] # => :full_active
result[:tick_number] # => 1
result[:phases_executed] # => [:sensory_processing, ..., :post_tick_reflection]
result[:elapsed] # => 0.001
# Check/set mode
Legion::Extensions::Tick::Runners::Orchestrator.tick_status
Legion::Extensions::Tick::Runners::Orchestrator.set_mode(mode: :sentinel)
# set_mode is sticky for one tick — automatic mode evaluation is skipped on the next execute_tick call
# Force mode transition for emergency
Legion::Extensions::Tick::Runners::Orchestrator.evaluate_mode_transition(
emergency: :firmware_violation
)The State object (Helpers::State) persists across ticks and tracks:
mode- current operating modetick_count- total ticks executedlast_signal_at/last_high_salience_at- timestamps driving mode decayphase_results- results from the current tick's phasesmode_history- last 50 mode transitions with timestamps
bundle install
bundle exec rspec
bundle exec rubocopMIT