swarmauri.experimental.conversations.SemanticConversation module

class swarmauri.experimental.conversations.SemanticConversation.SemanticConversation[source]

Bases: IConversation, ABC

A concrete implementation of the Conversation class that includes semantic routing. Semantic routing involves analyzing the content of messages to understand their intent or category and then routing them to appropriate handlers based on that analysis.

This class requires subclasses to implement the _analyze_message method for semantic analysis.

abstract add_message(message)[source]

Adds a message to the conversation history and routes it to the appropriate handler based on its semantic category.

Parameters:

message (Message) – The message to be added and processed.

abstract clear_history()

Clears the conversation history.

Return type:

None

abstract get_last()

Retrieves the latest message from the conversation history.

Return type:

Optional[IMessage]

property history: List[IMessage]

Provides read-only access to the conversation history.

abstract register_handler(category, handler)[source]

Registers a message handler for a specific semantic category.

Parameters:
  • category (str) – The category of messages this handler should process.

  • handler (Callable[[Message], None]) – The function to call for messages of the specified category.