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: object

Platform-agnostic message handler.

Parameters:
__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:
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:

int

Parameters:
async handle_message(msg, platform)[source]

Process an incoming message from any platform.

  1. Handle special commands (e.g. !clear).

  2. Skip if the bot was not addressed.

  3. Build conversation context and call the LLM.

  4. Send the reply back via the originating platform.

Return type:

None

Parameters:
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.

Return type:

None

Parameters:
  • platform_name (str)

  • channel_id (str)

  • message_id (str)

  • user_name (str)

  • user_id (str)

  • new_text (str)

  • timestamp_iso (str)

  • reply_to_id (str)

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.

Return type:

None

Parameters:
  • platform_name (str)

  • channel_id (str)

  • message_id (str)

  • deleted_at_iso (str)

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.

Return type:

None

Parameters:
  • platform_name (str)

  • channel_id (str)

  • message_id (str)

  • reactions_str (str)

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 to handle_message() with batch metadata set so that the system prompt includes the batch_response_context section.

Return type:

None

Parameters: