deeppavlov.core.agent

Basic classes for building DeepPavlov agents.

class deeppavlov.core.agent.agent.Agent(skills: List[deeppavlov.core.models.component.Component])[source]

Abstract class for agents.

Agent is an entity which receives inputs from the outer word, processes them and returns response to each input. Usually agent implements real-life task, business or user case. Agent encapsulates skills instances, management of skills inference and skills inference results processing. Also agent provides management both for history and state for each utterance and uses only incoming utterances IDs to distinguish them.

Parameters:skills – List of initiated agent skills instances.
skills

List of initiated Skill or Component instances. Components API should should implement API of Skill abstract class.

history

Histories for each each dialog with agent indexed by dialog ID. Each history is represented by list of incoming and outcoming replicas of the dialog and updated automatically.

states

States for each skill with agent indexed by dialog ID. Each state updated automatically after each wrapped skill inference. So we highly recommend use this attribute only for reading and not to use it for your custom skills management.

wrapped_skills

Skills wrapped to SkillWrapper objects. SkillWrapper object gives to Skill __call__ signature of Agent __call__ and handles automatic state management for skill. All skills are wrapped to SkillsWrapper automatically during agent initialisation. We highly recommend to use wrapped skills for skills inference.

dialog_logger

DeepPavlov dialog logging facility.

class deeppavlov.core.agent.agent.SkillWrapper(skill: deeppavlov.core.models.component.Component, skill_id: int, agent: deeppavlov.core.agent.agent.Agent)[source]

Skill instances wrapper for internal use in Agent.

SkillWrapper gives to skill interface of Agent and handles automatic state management for skill.

Parameters:
  • skill – Wrapped skill.
  • skill_id – Skill index in Agent.skills list.
  • agent – Agent instance.
skill

Wrapped skill.

skill_id

Skill index in Agent.skills list.

agent

Agent instance.

class deeppavlov.core.agent.dialog_logger.DialogLogger(enabled: bool = False, agent_name: Optional[str] = None)[source]

DeepPavlov dialog logging facility.

DialogLogger is an entity which provides tools for dialogs logging.

Parameters:
  • enabled – DialogLogger on/off flag.
  • agent_name – Agent name which is used for organising log files.
agent_name

Agent name which is used for organising log files.

log_max_size

Maximum size of log file, kb.

self.log_file

Current log file object.

log_in(utterance: Any, dialog_id: collections.abc.Hashable = None) → None[source]

Wraps _log method for all input utterances. :param utterance: Dialog utterance. :param dialog_id: Dialog ID.

log_out(utterance: Any, dialog_id: collections.abc.Hashable = None) → None[source]

Wraps _log method for all output utterances. :param utterance: Dialog utterance. :param dialog_id: Dialog ID.

class deeppavlov.core.agent.filter.Filter[source]

Abstract class for filters. Filter is a DeepPavlov component, which is used in Agent to select utterances from incoming batch to be processed for each Agent skill.

class deeppavlov.core.agent.processor.Processor[source]

Abstract class for processors. Processor is a DeepPavlov component, which is used in Agent to process skills responses and give one final response for each utterance.

class deeppavlov.core.agent.rich_content.RichControl(control_type: str)[source]

Base class for rich controls.

Rich control can be a button, buttons box, plain text, image, etc. All rich control classes should be derived from RichControl.

Parameters:control_type – Name of the rich control type.
control_type

Name of the rich control type.

content

Arbitrary used control content holder.

control_json

Control json representation template, which contains control type and content fields.

class deeppavlov.core.agent.rich_content.RichItem[source]

Base class for rich content elements.

Every rich content element is presumed to return its state (including state of nested controls) at least in json format (mandatory) as well as in the formats compatible with other channels.

alexa()[source]

Returns Amazon Alexa compatible state of the control instance including its nested controls.

Returns:Amazon Alexa representation of control state.
Return type:control
json() → Union[list, dict][source]

Returns json compatible state of the control instance including its nested controls.

Returns:Json representation of control state.
Return type:control
ms_bot_framework()[source]

Returns MS Bot Framework compatible state of the control instance including its nested controls.

Returns:MS Bot Framework representation of control state.
Return type:control
telegram()[source]

Returns Telegram compatible state of the control instance including its nested controls.

Returns:Telegram representation of control state.
Return type:control
class deeppavlov.core.agent.rich_content.RichMessage[source]

Container for rich controls.

All rich content elements returned by agent as a result of single inference should be embedded into RichMessage instance in the order these elements should be displayed.

controls

Container for RichControl instances.

add_control(control: deeppavlov.core.agent.rich_content.RichControl)[source]

Adds RichControl instance to RichMessage.

Parameters:control – RichControl instance.
alexa() → list[source]

Returns list of Amazon Alexa compatible states of the RichMessage instance nested controls.

Returns:
Amazon Alexa representation of RichMessage instance nested
controls.
Return type:alexa_controls
json() → list[source]

Returns list of json compatible states of the RichMessage instance nested controls.

Returns:
Json representation of RichMessage instance
nested controls.
Return type:json_controls
ms_bot_framework() → list[source]

Returns list of MS Bot Framework compatible states of the RichMessage instance nested controls.

Returns:
MS Bot Framework representation of RichMessage instance
nested controls.
Return type:ms_bf_controls
telegram() → list[source]

Returns list of Telegram compatible states of the RichMessage instance nested controls.

Returns:
Telegram representation of RichMessage instance nested
controls.
Return type:telegram_controls