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
annotations
section of the last utterance in dialog label
is used as a keypayload
is used as a value
- Adds a record to
- add_annotation_prev_bot_utt
- Adds a record to
annotations
section 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
label
is used as a keypayload
is used as a value
- Adds a record to
- add_hypothesis
- Adds a record to
hypotheses
section 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_name
andannotations
label
is used as a value forservice_name
key- Empty dict is used as a value for
annotations
key
- Adds a record to
- add_hypothesis_annotation
- Adds an annotation to a single element of the
hypotheses
section of the last utterance in dialog underannotations
key - In order to identify a certain hypothesis, it’s index is used and stored in agent
label
is used as a keypayload
is used as a value
- Adds an annotation to a single element of the
- add_text
- Adds a value to
text
field of the last utterance in dialog - Suitable for modifying a response in a bot utterance (original text can be found in
orig_text
field) payload
us 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
text
andorig_text
fields of new bot utterance are filled withtext
value from payloadactive_skill
field is filled withskill_name
value from payloadconfidence
field is filled withconfidence
value from payloadannotations
from payload are copyed toannotations
field of bot utterance- We expect, that skills will return
text
andconfidence
fields at least.skill_name
andannotations
are created withinadd_hypothesis
method
- 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_utterance
one - 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
payload
is used fortext
field 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