The MultiLogicAdapter

ChatterBot internally uses a special logic adapter that allows it to choose the best response generated by any number of other logic adapters.

Selecting a response from multiple logic adapters

The MultiLogicAdapter is used to select a single response from the responses returned by all of the logic adapters that the chat bot has been configured to use. Each response returned by the logic adapters includes a confidence score that indicates the likeliness that the returned statement is a valid response to the input.

Response selection

The MultiLogicAdapter will return the response statement that has the greatest confidence score. The only exception to this is a case where multiple logic adapters return the same statement and therefore agree on that response.

For this example, consider a scenario where multiple logic adapters are being used. Assume the following results were returned by a chat bot’s logic adapters.

Confidence Statement
0.2 Good morning
0.5 Good morning
0.7 Good night

In this case, two of the logic adapters have generated the same result. When multiple logic adapters come to the same conclusion, that statement is given priority over another response with a possibly higher confidence score. The fact that the multiple adapters agreed on a response is a significant indicator that a particular statement has a greater probability of being a more accurate response to the input.

When multiple adapters agree on a response, the greatest confidence score that was generated for that response will be returned with it.


class chatterbot.logic.multi_adapter.MultiLogicAdapter(**kwargs)[source]

MultiLogicAdapter allows ChatterBot to use multiple logic adapters. It has methods that allow ChatterBot to add an adapter, set the chat bot, and process an input statement to get a response.

add_adapter(adapter, **kwargs)[source]

Appends a logic adapter to the list of logic adapters being used.

Parameters:adapter (LogicAdapter) – The logic adapter to be added.

Return a list of all logic adapters being used, including system logic adapters.

get_greatest_confidence(statement, options)[source]

Returns the greatest confidence value for a statement that occurs multiple times in the set of options.

  • statement – A statement object.
  • options – A tuple in the format of (confidence, statement).

Get the initialization functions for each logic adapter.

insert_logic_adapter(logic_adapter, insert_index, **kwargs)[source]

Adds a logic adapter at a specified index.

  • logic_adapter (str) – The string path to the logic adapter to add.
  • insert_index (int) – The index to insert the logic adapter into the list at.

Returns the output of a selection of logic adapters for a given input statement.

Parameters:statement – The input statement to be processed.

Removes a logic adapter from the chat bot.

Parameters:adapter_name (str) – The class name of the adapter to remove.

Set the chatbot for each of the contained logic adapters.