status_managerο
AI-generated Discord status with glitch-cycling effects.
Platform-agnostic core with Discord-specific presence integration.
Started as a background task by the Inference service
(inference_main.InferenceService); presence updates are published
over the event bus via the workerβs ProxyPlatformAdapter.
- class status_manager.StatusConfig(min_interval=60, max_interval=3600, max_length=128, emoji='π', glitch_interval=300, num_variants=200, name_glitch_interval=30, enable_name_glitch=True)[source]ο
Bases:
objectTunable knobs for the AI status generator and glitch cycler.
Holds the cadence and sizing parameters that drive
StatusManager: how often a fresh LLM-generated base status is requested (max_interval), how often the glitch-cycled variant is pushed to Discord (glitch_interval), how many glitch variants to precompute (num_variants), the presence emoji, and the Discord custom-status length cap (max_length). It is a pure data container with no behavior; an instance is passed toStatusManager.__init__or defaulted there when omitted. Instantiated by the inference service when it constructs the manager and by the presence test suite (tests/test_status_presence.py).- Parameters:
- class status_manager.StatusManager(openrouter, discord_adapter=None, config=None, leader_guard=None)[source]ο
Bases:
objectGenerate, glitch-cycle, and publish the botβs Discord presence.
Drives the dark-AI-persona custom status: periodically asks the LLM (via the injected
openrouterclientβschat) for a fresh themed base line, precomputes a pool of glitched variants from it, and rotates through them on a timer so the presence visibly shimmers without a new LLM call each tick. The actual presence write goes through the injected discord adapter; in the microservice deployment that is aProxyPlatformAdapterwhoseset_presencepublishes apresenceaction over the event bus for the Gateway to apply, which is how presence crosses the service boundary.Constructed and owned by the inference service (
inference_main.InferenceService), which callsstart()once the event bus and discord proxy exist andstop()on shutdown. Aleader_guardcallable may gate the periodic loop so only one worker publishes presence. The message-processing path also injects this manager and callsset_status_from_tag()when the model emits an explicit status tag.- Parameters:
openrouter (Any)
discord_adapter (Any | None)
config (StatusConfig | None)
leader_guard (Any | None)
- __init__(openrouter, discord_adapter=None, config=None, leader_guard=None)[source]ο
Initialize the instance.
- Parameters:
openrouter (
Any) β The openrouter value.config (
StatusConfig|None) β Bot configuration object.leader_guard (
Any|None) β Optional async callable returningTruewhen this node should drive the periodic status loop. Used in the microservice deployment so only one worker generates/publishes presence (avoids flapping). WhenNonethe loop always runs (monolith / single-instance).
- Return type:
None
- start()[source]ο
Start the background presence loop if it is not already running.
Sets the running flag and schedules
_loop()as a fire-and-forgetasynciotask (stored onself._task) that periodically generates and publishes status updates; logsStatusManager started. Idempotent: returns immediately when a loop is already active. Invoked byinference_main.InferenceServiceafter the event bus and discord proxy are wired up.- Return type:
- stop()[source]ο
Signal the presence loop to stop and cancel its background task.
Clears the running flag and cancels the
asynciotask created bystart()(if any); does not await the cancellation. Safe to call when the loop was never started. Invoked byinference_main.InferenceServiceduring service shutdown.- Return type:
- async force_update()[source]ο
Run one status-generation/publish cycle immediately, off-schedule.
Bypasses the periodic timer by awaiting
_cycle()directly, which may request a fresh LLM base status, rebuild the glitch variants, and push the next variant to Discord via the adapter. Intended for manual or test-driven refreshes; no production caller invokes it (exercised by the presence test suite).- Return type:
- async set_status_from_tag(text)[source]ο
Override the presence with a model-supplied status string.
Used when the LLM emits an explicit status tag during a response: the raw text is stripped of any
<thinking>block and surrounding quotes, clamped toconfig.max_length(truncating with an ellipsis if needed), then underself._status_lockit rebuilds the glitch-variant pool via_generate_variants(), resets the rotation cursor and base-update timestamp, and records the cleaned text ascurrent_status. Finally pushes the cleaned text to Discord through_set_discord_status(). Called from the message-processing path (message_processor.generate_and_sendandmessage_processor.channel_heartbeat).
- get_info()[source]ο
Return a small snapshot of the managerβs current state.
Reports the active status text, whether the background loop is running, and how many glitch variants are currently precomputed. A pure read with no side effects, intended for diagnostics and status surfaces; no in-repo caller invokes it directly.