lex-tick
Atomic cognitive processing cycle for brain-modeled agentic AI. Implements 16 default active phases, 4 operating modes, mode transitions, and explicitly enabled optional work.
Overview
lex-tick schedules bounded cognitive phase handlers and returns their results. Request/event processing and extension-owned background maintenance remain outside the tick; loading a handler does not schedule it.
Operating Modes
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:
- Low-salience non-human signal:
dormant->sentinel - High salience (>= 0.7) or human direct input:
dormant,dormant_active, orsentinel->full_activeon that interaction - No high-salience or human signal for 300s:
full_active->sentinel; an empty heartbeat alone does not demote - 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) - Finished or deferred dream cycle:
dormant_active->dormant, with backoff before another dream cycle - Emergency trigger (
:firmware_violation,:extinction_protocol): immediatefull_active
16 Active Phases (full_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. Execution budgets use a monotonic clock and stop starting phases once the mode's budget is exhausted; an already-running handler is not forcibly interrupted. Corrected promotion runs the existing 16-phase, 5-second-budget active schedule instead of the 5-phase sentinel schedule for the first human interaction. Optional work shares that budget and is disabled by default.
10 Dream Phases (dormant_active)
memory_auditassociation_walkcontradiction_resolutionidentity_entropy_checkagenda_formationconsolidation_commitknowledge_promotiondream_reflectionpartner_reflectiondream_narration
Optional phases
Version 0.1.18 adds execute_tick(enabled_optional_phases: []). Existing callers
retain exactly their existing schedules, even if they supply additional handlers.
Only these opt-ins are supported:
| Phase | Mode and placement | Required preceding result |
|---|---|---|
global_workspace |
full_active, after gut instinct and before action selection |
Successful sensory processing |
metacognition |
full_active, after post-tick reflection |
Successful reflection |
result = client.execute_tick(
signals: signals,
phase_handlers: handlers,
enabled_optional_phases: %i[global_workspace metacognition]
)Unknown names or a non-array opt-in raise ArgumentError before tick state
advances. Repeated names run once. An opt-in does not override the operating
mode. Missing optional handlers return status: :unavailable; failed, missing,
or deferred prerequisite results return status: :deferred without invoking
the dependent handler. The caller remains responsible for domain readiness:
submit real candidates to the same workspace that competes, consume its result,
and do not supply fabricated claim, belief, or intention IDs.
phases_scheduled is the selected schedule, phases_executed contains the
visited phases (including unavailable/no-handler results), and phases_skipped
contains phases not visited because the shared tick budget expired. Inspect each
phase's result status rather than treating a visited phase as completed work.
The other currently unscheduled GAIA mappings are deliberately not tick opt-ins:
| Mapping | Activation owner / reason |
|---|---|
curiosity_execution |
Explicit background inquiry; performs LLM calls and knowledge writes |
dream_cycle |
Existing imagination dream actor; do not duplicate its maintenance cycle |
creativity_tick |
Background idea maintenance; no verified tick consumer |
lucid_dream |
Request/event supplying a real theme and content |
epistemic_vigilance |
Claim submission/review with a real source and claim ID |
predictive_processing |
Prediction/outcome event pair with a meaningful domain and consumer |
free_energy |
Belief observation event; stale-state maintenance remains actor-owned |
default_mode_network |
Existing idle-aware background lifecycle, not unconditional thought generation |
prospective_memory |
Intention lifecycle events; monitoring is not task execution |
inner_speech |
Meaningful narration event; decay remains actor-owned |
Consumers must require 0.1.18 or verify the explicit keyword before opting in. Older versions accept arbitrary context keywords and would silently ignore it.
Installation
Add to your Gemfile:
gem 'lex-tick'Usage
require 'legion/extensions/tick'
client = Legion::Extensions::Tick::Client.new
# Execute a tick with signals and phase handlers
result = client.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
client.tick_status
client.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
client.evaluate_mode_transition(
emergency: :firmware_violation
)State Object
The State object (Helpers::State) persists across ticks and tracks:
-
mode- current operating mode -
tick_count- total ticks executed -
last_signal_at/last_high_salience_at- timestamps driving mode decay -
last_dream_completed_at- most recent fully successful dream cycle -
last_dream_deferred_at- most recent incomplete, failed, unhandled, or interrupted dream; both timestamps enforce dream backoff -
phase_results- results from the current tick's phases -
mode_history- last 50 mode transitions with timestamps
Development
bundle install
bundle exec rspec
bundle exec rubocopLicense
MIT