message_processor
Central message processor shared across all platforms.
- class message_processor.MessageProcessor(config, conversation_manager, openrouter, message_cache=None, kg_manager=None, auto_search=None, task_manager=None, classifier=None, threadweave=None, embedding_queue=None, status_manager=None, web_search=None)[source]
Bases:
objectPlatform-agnostic message handler.
- Parameters:
config (
Config) – Global bot configuration (forwarded to the context builder).conversation_manager (
ConversationManager) – Manages per-channel conversation histories.openrouter (
OpenRouterClient) – The OpenRouter API client for LLM completions.message_cache (
MessageCache|None) – Optional Redis-backed message cache. When provided, every message the bot sees is logged with an embedding vector.kg_manager (KnowledgeGraphManager | None)
auto_search (RAGAutoSearchManager | None)
task_manager (TaskManager | None)
classifier (VectorClassifier | None)
threadweave (ThreadweaveManager | None)
embedding_queue (EmbeddingBatchQueue | None)
status_manager (StatusManager | None)
web_search (WebSearchContextManager | None)
- __init__(config, conversation_manager, openrouter, message_cache=None, kg_manager=None, auto_search=None, task_manager=None, classifier=None, threadweave=None, embedding_queue=None, status_manager=None, web_search=None)[source]
Initialize the instance.
- Parameters:
config (
Config) – Bot configuration object.conversation_manager (
ConversationManager) – The conversation manager value.openrouter (
OpenRouterClient) – The openrouter value.message_cache (
MessageCache|None) – The message cache value.kg_manager (
KnowledgeGraphManager|None) – The kg manager value.auto_search (
RAGAutoSearchManager|None) – The auto search value.task_manager (
TaskManager|None) – The task manager value.classifier (
VectorClassifier|None) – The classifier value.threadweave (
ThreadweaveManager|None) – The threadweave value.embedding_queue (
EmbeddingBatchQueue|None) – The embedding queue value.status_manager (
StatusManager|None) – The status manager value.web_search (
WebSearchContextManager|None) – The web search value.
- Return type:
None
- async recover_pending_responses(enqueue_callback, adapters)[source]
Re-enqueue messages whose responses were interrupted by a restart.
Called once during startup after all platform adapters are running. Returns the number of recovered messages.
- Return type:
- Parameters:
enqueue_callback (Callable[[IncomingMessage, PlatformAdapter], Awaitable[None]])
adapters (list[PlatformAdapter])
- async handle_message(msg, platform)[source]
Process an incoming message from any platform.
Handle special commands (e.g.
!clear).Skip if the bot was not addressed.
Build conversation context and call the LLM.
Send the reply back via the originating platform.
- Return type:
- Parameters:
msg (IncomingMessage)
platform (PlatformAdapter)
- async handle_message_update(platform_name, channel_id, message_id, user_name, user_id, new_text, timestamp_iso, reply_to_id='')[source]
Silently update an already-cached message (no LLM response).
Called when Discord delivers an embed-only or bot-message edit that should refresh the cached content without triggering a new response cycle.
- async handle_message_delete(platform_name, channel_id, message_id, deleted_at_iso)[source]
Mark a message as deleted in both cache and conversation history.
The original content is preserved with a
[deleted at TIMESTAMP]tag so the bot retains context about what was said.
- async handle_reaction_update(platform_name, channel_id, message_id, reactions_str)[source]
Patch the
[Reactions: ...]tag on an existing history entry.Called by platform adapters when a reaction is added or removed so the LLM context window always reflects the latest reactions.
- async handle_batch(batch, representative, platform)[source]
Process a batch of rapid-succession messages as a single LLM call.
Combines the text of every message in batch into one
IncomingMessage(using representative as the base) and delegates tohandle_message()with batch metadata set so that the system prompt includes thebatch_response_contextsection.- Return type:
- Parameters:
batch (MessageBatch)
representative (IncomingMessage)
platform (PlatformAdapter)