Stargazer v3 — Technical Documentation
Architectural Overview
Stargazer v3 is a multi-platform conversational AI bot that bridges Discord, Matrix, and WebChat with a shared LLM inference pipeline, an extensible tool-calling framework, and a neurochemical simulation engine for affective computing.
As of the Phase T3 migration (2026-06-02) the original main.BotRunner
monolith has been retired. Stargazer now runs as five independent
microservices that communicate over Redis Streams. Each boots from the shared
StargazerService contract and exposes /healthz
and /readyz probes via HealthServer.
Services
Gateway (gateway_main) — the only service that holds live platform
connections. It runs a PlatformAdapter for each enabled
platform, normalizes inbound events into IncomingMessage
objects, wraps each in a validated
InboundEnvelopeModel, and publishes it to the
sg:stream:inbound stream. It also consumes the per-platform
sg:stream:outbound:{platform} streams and dispatches replies back through the
real adapters.
Inference (inference_main) — the stateless, horizontally scalable LLM
worker. It consumes sg:stream:inbound (consumer group sg:workers) under a
per-channel DistributedLock, reconstructs the
message, and runs the full
MessageProcessor pipeline — sending every
reply through a ProxyPlatformAdapter that publishes
to the outbound streams instead of calling a platform SDK directly.
Agents (agents_main) — recurring/background work (knowledge-graph
extraction and summarization, limbic/NCM upkeep, scheduled prompts, optional
game/dyadic agents, SWORD, StarWiki), guarded by a cluster-singleton
TaskSupervisor so each job runs on exactly one node.
Consolidation (consolidation_main) — long-horizon knowledge-graph
consolidation and decay, isolated so this slow, LLM-heavy work scales and
restarts independently of the request path.
Web (web_main) — the FastAPI management dashboard and StarWiki,
serving operational state without booting message processing.
Message flow
A single user message traverses the services as follows:
Platform event
→ Gateway: PlatformAdapter → IncomingMessage
→ _make_inbound_envelope() → InboundEnvelopeModel
→ RedisEventBus.publish_inbound() → sg:stream:inbound
→ Inference: InboundStreamConsumer (group sg:workers, per-channel lock)
→ _incoming_message_from_envelope() → IncomingMessage
→ MessageProcessor.handle_message(msg, ProxyPlatformAdapter)
· preprocess · classify tools · gather RAG/web/context · build prompt
· OpenRouterClient.chat() (tool-call loop) · response postprocessing
→ ProxyPlatformAdapter.send() → RedisEventBus.publish_outbound()
→ sg:stream:outbound:{platform}
→ Gateway: OutboundStreamConsumer → real PlatformAdapter.send()
→ Platform
Platform Adapters
The platforms package provides a
PlatformAdapter interface implemented by
platforms.discord, platforms.matrix, and platforms.webchat.
Adapters normalize incoming messages into
IncomingMessage objects and expose a uniform reply API.
They run inside the Gateway; the Inference worker sees the same interface via the
ProxyPlatformAdapter.
Message Processing Pipeline
Inside the Inference worker, message_processor orchestrates each message.
For each incoming message it:
Preprocesses (URL extraction, attachment handling, multimodal parts)
Resolves conversation history via
conversationandmessage_cacheClassifies and selects relevant tools via
classifiers.vector_classifierGathers RAG context from
rag_systemBuilds the LLM prompt with
prompt_contextandprompt_rendererCalls the LLM via
openrouter_clientPostprocesses the response with
response_postprocessor
Tool Framework — tools provides the ToolRegistry
decorator system. Each tool file in the tools/ directory is auto-loaded by
tool_loader. Tools are async callables that receive an optional
ToolContext for bot-internal access. The
classifiers.vector_classifier selects tools per-message via semantic
embedding similarity.
Neurochemical Model (NCM) — An affective computing layer that simulates neurochemical states:
limbic_system— Core neurochemical vector state machinecascade_engine— Multi-turn event cascadesncm_engine— Top-level NCM orchestratorncm_desire_engine— Desire/motivation modelingncm_semantic_triggers— Semantic trigger evaluationcadence_refiner— Response cadence and style adjustmentuser_limbic_mirror— Per-user affective modeling
Knowledge & Memory — Long-term memory and knowledge management:
knowledge_graph— FalkorDB-backed knowledge graphrag_system— RAG pipeline with embedding searchmessage_cache— Redis-backed message historythreadweave— Multi-thread conversation management
Background Processing — Async agents in background_agents, scheduled
by the Agents and Consolidation services:
background_agents.channel_summarizer— Automatic channel summariesbackground_agents.research_agent— Background research tasksbackground_agents.deep_think_agent— Extended reasoning
Configuration — config loads config.yaml with environment variable
overrides, supporting per-platform settings.
API Reference
Core Modules
- Core Modules
- agents_main
- anamnesis_engine
- api_key_encryption
- arche_audit
- attachment_ledger
- backfill_entity_provenance
- background_tasks
- btc_networks
- btc_wallet_manager
- build_kg
- cadence_refiner
- callbacks
- cascade_engine
- chaos_switch_router
- check_skeleton_remote
- chroma_registry
- config
- consolidation_main
- conversation
- ego_ablation
- egregore_bridge
- egregore_tag_parser
- embedding_queue
- entrainment_detector
- entrainment_loopfield
- eth_networks
- extract_tags_to_concepts
- feature_toggles
- flash_dyadic_mirror
- flavor_engine
- flavor_memory
- game_assets
- game_characters
- game_memory
- game_ncm
- game_session
- gateway_main
- gemini_embed_pool
- gemini_kg_bulk_client
- hosting_metadata
- inference_main
- init_redis_indexes
- jsonutil
- kg_agentic_extraction
- kg_bulk_runner
- kg_consolidation
- kg_extraction
- latex_converter
- log_rag_ingest
- log_redaction
- lore_amplifier
- media
- media_cache
- memory_search
- message_cache
- message_queue
- message_utils
- migrate_kg_overhaul
- migrate_kg_uuids
- model_capabilities
- ncm_appraisal
- ncm_delta_parser
- ncm_desire_engine
- ncm_engine
- ncm_local_embeddings
- ncm_semantic_triggers
- ncm_variant_cache
- oauth_manager
- observability
- ops_planner
- parallax_engine
- patch
- patch2
- patch_v1.0
- patch_v13
- patch_v6
- patience_engine
- persona_preference_extraction
- persona_preferences
- proactive_triage
- prompt_context
- prompt_renderer
- response_postprocessor
- sapphic
- scrape_leafly
- search_query_generator
- server_stats
- shadow_ban
- star_avatar
- star_self_mirror
- star_toggle_ui
- status_manager
- strangler_router
- task_manager
- terpene_engine
- test_crosswalk
- test_image
- test_image_colors
- test_inject
- test_loopmother
- test_postprocessor
- test_postprocessor2
- test_postprocessor3
- test_timebender
- test_v4
- threadweave
- tool_context
- tool_loader
- tools_main
- update_md
- url_content_extractor
- user_limbic_mirror
- user_llm_config
- vector_store
- visual_memory
- wallet_key_utils
- wallet_manager
- web_main
- web_search_context
- xray_engine
Core Infrastructure (core/)
Tools
Classifiers
Platform Adapters
RAG System
Background Agents