Module: Dispatcher

class diskurs.dispatcher.AsynchronousConversationDispatcher

Bases: ConversationDispatcher

__init__()
async publish(topic, conversation)

Dispatch a conversation to all participants subscribed to the topic.

This method sends the given conversation to all participants who are subscribed to the specified topic. Each participant will receive the conversation and can process it accordingly.

Parameters:
  • topic (str) – The topic to which the conversation will be published.

  • conversation (Conversation) – The conversation to be dispatched.

Return type:

None

async publish_final(topic, conversation)

Dispatch a conversation to a finalizing agent

This method sends the given conversation to a finalizing agent that will create the final answer to the conversation.

Parameters:
  • topic (str) – The name of the finalizing agent.

  • conversation (Conversation) – The conversation to be dispatched.

Return type:

None

async request_response(topic, conversation)

Method for requesting a direct response from a participant.

This is used if you need an answer to a question from a participant, e.g. to ask an agent whether we can finalize the conversation.

Parameters:
  • topic (str) – The ConversationParticipant to ask the question.

  • conversation (Conversation) – The Conversation object representing the current state of the conversation.

Returns:

The updated Conversation object with the response from the participant.

Return type:

Conversation

async run(participant, conversation)

Entry point for starting a conversation with a participant.

This method starts a conversation by dispatching it to the participant, passed into it. It also handles the finalization of the conversation, as soon as the future object is set. returns a dictionary containing the final response data.

Parameters:
  • participant (ConversationParticipant) – The ConversationParticipant that is involved in the conversation.

  • conversation (Conversation) – The Conversation object representing the current state of the conversation.

Returns:

A dictionary containing the final response data.

Return type:

Conversation

subscribe(topic, subscriber)

Subscribe a participant to a specific topic.

This method registers a ConversationParticipant to receive conversations related to the specified topic. When a conversation is published to the topic, all subscribed participants will be notified and can process the conversation.

Parameters:
Return type:

None

unsubscribe(topic, subscriber)

Unsubscribe a participant from a specific topic.

This method removes a ConversationParticipant from the list of subscribers for the given topic. Once unsubscribed, the participant will no longer receive conversations related to that topic.

Parameters:
Return type:

None