Built-in StateManager¶
Built-in StateManager is responsible for all database read and write operations, and it’s working with MongoDB database. You can assign it’s methods to services in your pipeline in order to properly save their responses to dialogs state. You can read more on the pipeline configuration in Services Config
Available methods¶
Each of the methods have a following input parameters, which are filled automatically by agent during message processing.
dialog- dialog object, which will be updatedpayload- response of the service with output formatter appliedlabel- label of the servicekwargs- minor arguments which are also provided by agent
You can use several state manager methods in your pipeline:
- add_annotation
- Adds a record to
annotationssection of the last utterance in dialog labelis used as a keypayloadis used as a value
- Adds a record to
- add_annotation_prev_bot_utt
- Adds a record to
annotationssection of the second utterance from the end of the dialog - Only works if that utterance is bot utterance
- Suitable for annotating last bot utterance on the next dialog round
labelis used as a keypayloadis used as a value
- Adds a record to
- add_hypothesis
- Adds a record to
hypothesessection of the last utterance in dialog - Works only for human utterance, since bot utterance doesn’t have such section
- Accepts list of hypotheses dicts, provided by service
- Two new keys are added to each hypothesis:
service_nameandannotations labelis used as a value forservice_namekey- Empty dict is used as a value for
annotationskey
- Adds a record to
- add_hypothesis_annotation
- Adds an annotation to a single element of the
hypothesessection of the last utterance in dialog underannotationskey - In order to identify a certain hypothesis, it’s index is used and stored in agent
labelis used as a keypayloadis used as a value
- Adds an annotation to a single element of the
- add_text
- Adds a value to
textfield of the last utterance in dialog - Suitable for modifying a response in a bot utterance (original text can be found in
orig_textfield) payloadus used as a value
- Adds a value to
- add_bot_utterance
- This method is intended to be associated with response selector service
- Adds a new bot utterance to the dialog
- Modifies associated user and bot objects
- We consider, that payload will be a single hypothesis, which was chosen as a bot response. So it will be parsed to different fields of bot utterance
textandorig_textfields of new bot utterance are filled withtextvalue from payloadactive_skillfield is filled withskill_namevalue from payloadconfidencefield is filled withconfidencevalue from payloadannotationsfrom payload are copyed toannotationsfield of bot utterance- We expect, that skills will return
textandconfidencefields at least.skill_nameandannotationsare created withinadd_hypothesismethod
- add_bot_utterance_last_chance
- This method is intended to be associated with a failure processing service, like timeout or last chance responder
- It is very similar in processing to
add_bot_utterance, but it performs an additional check on the type of a last utterance in dialog - If the last utterance is a human utterance the method acts as an
add_bot_utteranceone - Otherwise, it will skip a stage with creating a new bot utterance and inserting it at the end of the dialog
There are two additional state manager methods, which are automatically assigned during agent’s initialisation.
- add_human_utterance
- This method is assigned to an input service, which is created automatically during agent’s initialisation process
- Adds a new human utterance to the dialog
payloadis used fortextfield of the new human utterance
- save_dialog
- This method is assigned to a responder service, which is created automatically during agent’s initialisation process
- It just saves a dialog to database