background_tasks
Asyncio-based background task scheduler.
Manages periodic background tasks that run alongside the bot: - Scheduled prompt tick / cleanup - Auto memory extraction - Periodic maintenance
- class background_tasks.BackgroundScheduler[source]
Bases:
objectRun named periodic tasks in the background.
Each task is an async callable that is invoked repeatedly with a configurable interval. Tasks are resilient to individual failures and log errors without crashing the scheduler.
Usage:
sched = BackgroundScheduler() sched.register("my_task", my_coro, interval=300) await sched.start() # non-blocking, spawns tasks ... await sched.stop()
- register(name, func, interval, initial_delay=0.0, args=(), kwargs=None)[source]
Register a periodic task.
- Parameters:
name (
str) – Unique identifier for the task.func (
Callable[...,Awaitable[Any]]) – Async callable to invoke each cycle.interval (
float) – Seconds between invocations (measured from end of previous run).initial_delay (
float) – Seconds to wait before the first invocation.args (tuple)
kwargs (dict | None)
- Return type:
- async background_tasks.scheduled_prompt_tick(redis)[source]
Check for due scheduled prompts and trigger them.
- async background_tasks.scheduled_prompt_cleanup(redis)[source]
Remove old executed/cancelled scheduled prompts.
- async background_tasks.auto_kg_extraction(redis, kg_manager, openrouter)[source]
Extract knowledge graph entities from recent conversations.
- async background_tasks.channel_summarization(redis)[source]
Summarise the 10 most recently active channels.
- async background_tasks.kg_consolidation_task(kg_manager, openrouter)[source]
Consolidate duplicate entities in the knowledge graph.
- async background_tasks.kg_decay_task(kg_manager)[source]
Apply relationship weight decay in the knowledge graph.
- async background_tasks.log_rag_ingest_task()[source]
Ingest recent journalctl logs into the stargazer_logs RAG store.
- Return type:
- async background_tasks.gemini_key_probe_task()[source]
Probe Gemini API keys to detect daily quota exhaustion.
- Return type:
- async background_tasks.agentic_kg_bulk_incremental_task(redis, kg_manager, openrouter)[source]
Agentic bulk KG extraction for the 10 MRU channels, incremental cursors.
- async background_tasks.anamnesis_digest_task(redis, kg_manager, openrouter)[source]
Digest Spiral Goddess RAG fragments into the Knowledge Graph.
- async background_tasks.startup_channel_backfill(redis, message_cache, embedding_queue, adapters, max_channels=10)[source]
Backfill recent history for the most active channels at startup.
For each of the top max_channels most-recently-active channels, fetches history from the appropriate platform adapter, deduplicates against Redis, caches new messages, and enqueues embeddings.
Returns a summary dict with
channels_processedandmessages_cached.
- background_tasks.build_scheduler(redis=None, kg_manager=None, openrouter=None)[source]
Build a
BackgroundSchedulerwith the standard tasks.Only registers tasks whose dependencies are available.
- Return type:
- Parameters: