rasa.shared.core.trackers
TrackerActiveLoop Objects
Dataclass for DialogueStateTracker.active_loop
.
EventVerbosity Objects
Filter on which events to include in tracker dumps.
AnySlotDict Objects
A slot dictionary that pretends every slot exists, by creating slots on demand.
This only uses the generic slot type! This means certain functionality wont work, e.g. properly featurizing the slot.
DialogueStateTracker Objects
Maintains the state of a conversation.
The field max_event_history will only give you these last events, it can be set in the tracker_store.
from_dict
Create a tracker from dump.
The dump should be an array of dumped events. When restoring the tracker, these events will be replayed to recreate the state.
from_events
Creates tracker from existing events.
Arguments:
sender_id
- The ID of the conversation.evts
- Existing events which should be applied to the new tracker.slots
- Slots which can be set.max_event_history
- Maximum number of events which should be stored.sender_source
- File source of the messages.domain
- The current model domain.
Returns:
Instantiated tracker with its state updated according to the given events.
__init__
Initialize the tracker.
A set of events can be stored externally, and we will run through all of them to get the current state. The tracker will represent all the information we captured while processing messages of the dialogue.
current_state
Returns the current tracker state as an object.
freeze_current_state
Convert State dict into a hashable format FrozenState.
Arguments:
state
- The state which should be converted
Returns:
hashable form of the state of type FrozenState
past_states
Generates the past states of this tracker based on the history.
Arguments:
domain
- The Domain.omit_unset_slots
- IfTrue
do not include the initial values of slots.ignore_rule_only_turns
- If True ignore dialogue turns that are present only in rules.rule_only_data
- Slots and loops, which only occur in rules but not in stories.
Returns:
A list of states
change_loop_to
Set the currently active loop.
Arguments:
loop_name
- The name of loop which should be marked as active.
interrupt_loop
Interrupt loop and mark that we entered an unhappy path in the conversation.
Arguments:
is_interrupted
-True
if the loop was run after an unhappy path.
reject_action
Notify active loop that it was rejected.
set_latest_action
Sets latest action name or text.
Resets loop validation and rejection parameters.
Arguments:
action
- Serialized action event.
current_slot_values
Return the currently set values of the slots.
get_slot
Retrieves the value of a slot.
get_latest_entity_values
Get entity values found for the passed entity type and optional role and group in latest message.
If you are only interested in the first entity of a given type use
next(tracker.get_latest_entity_values(
"my_entity_name
"), None)
.
If no entity is found None
is the default result.
Arguments:
entity_type
- the entity type of interestentity_role
- optional entity role of interestentity_group
- optional entity group of interest
Returns:
Entity values.
get_latest_input_channel
Get the name of the input_channel of the latest UserUttered event.
is_paused
State whether the tracker is currently paused.
idx_after_latest_restart
Return the idx of the most recent restart in the list of events.
If the conversation has not been restarted, 0
is returned.
events_after_latest_restart
Return a list of events after the most recent restart.
init_copy
Creates a new state tracker with the same initial values.
generate_all_prior_trackers
Returns a generator of the previous trackers of this tracker.
Returns:
The tuple with the tracker before each action, and the boolean flag representing whether this action should be hidden in the dialogue history created for ML-based policies.
applied_events
Returns all actions that should be applied - w/o reverted events.
Returns:
The events applied to the tracker.
replay_events
Update the tracker based on a list of events.
recreate_from_dialogue
Use a serialised Dialogue
to update the trackers state.
This uses the state as is persisted in a TrackerStore
. If the
tracker is blank before calling this method, the final state will be
identical to the tracker from which the dialogue was created.
copy
Creates a duplicate of this tracker.
travel_back_in_time
Creates a new tracker with a state at a specific timestamp.
A new tracker will be created and all events previous to the passed time stamp will be replayed. Events that occur exactly at the target time will be included.
as_dialogue
Return a Dialogue
object containing all of the turns.
This can be serialised and later used to recover the state of this tracker exactly.
update
Modify the state of the tracker according to an Event
.
update_with_events
Adds multiple events to the tracker.
Arguments:
new_events
- Events to apply.domain
- The current model's domain.override_timestamp
- IfTrue
refresh all timestamps of the events. As the events are usually created at some earlier point, this makes sure that all new events come after any current tracker events.
as_story
Dump the tracker as a story in the Rasa Core story format.
Returns the dumped tracker as a string.
export_stories
Dump the tracker as a story in the Rasa Core story format.
Returns:
The dumped tracker as a string.
export_stories_to_file
Dump the tracker as a story to a file.
get_last_event_for
Gets the last event of a given type which was actually applied.
Arguments:
event_type
- The type of event you want to find.action_names_to_exclude
- Events of typeActionExecuted
which should be excluded from the results. Can be used to skipaction_listen
events.skip
- Skips n possible results before return an event.event_verbosity
- WhichEventVerbosity
should be used to search for events.
Returns:
event which matched the query or None
if no event matched.
last_executed_action_has
Returns whether last ActionExecuted
event had a specific name.
Arguments:
name
- Name of the event which should be matched.skip
- Skips n possible results in between.
Returns:
True
if last executed action had name name
, otherwise False
.
trigger_followup_action
Triggers another action following the execution of the current.
clear_followup_action
Clears follow up action when it was executed.
active_loop_name
Get the name of the currently active loop.
Returns: None
if no active loop or the name of the currently active loop.
latest_action_name
Get the name of the previously executed action or text of e2e action.
Returns: name of the previously executed action or text of e2e action
is_active_loop_rejected
Return True if there is an active loop and it's rejected.
is_active_loop_interrupted
Return True if there is an active loop and it's interrupted.
fingerprint
Returns a unique hash for the tracker which is stable across python runs.
Returns:
fingerprint of the tracker
TrackerEventDiffEngine Objects
Computes event difference of two trackers.
event_difference
Returns all events from the new tracker which are not present in the original tracker.
Arguments:
tracker
- Tracker containing events from the current conversation session.
get_active_loop_name
Get the name of current active loop.
Arguments:
state
- The state from which the name of active loop should be extracted
Returns:
the name of active loop or None
is_prev_action_listen_in_state
Check if action_listen is the previous executed action.
Arguments:
state
- The state for which the check should be performed
Returns:
boolean value indicating whether action_listen is previous action
get_trackers_for_conversation_sessions
Generate trackers for tracker
that are split by conversation sessions.
Arguments:
tracker
- Instance ofDialogueStateTracker
to split.
Returns:
The trackers split by conversation sessions.