Skip to content

Commit

Permalink
ATO-218 Always set slot values
Browse files Browse the repository at this point in the history
This fixes a bug where slot values vanish when using the augmented
memoization policy. If in the past, the slot is set to a specific value,
and then later the slot being set to the same value, no new SlotSet
event is emitted. However, this leads to the augmented memoiziation
policy wrongly assuming this slot to be unset, as the older, original
SlotSet event was pruned already.
  • Loading branch information
losterloh committed Jul 13, 2022
1 parent dc67adf commit f377154
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,7 @@ async def run(
if not isinstance(slot, ListSlot):
value = value[-1]

if tracker.get_slot(slot.name) != value:
slot_events.append(SlotSet(slot.name, value))
slot_events.append(SlotSet(slot.name, value))

should_fill_custom_slot = mapping_type == SlotMappingType.CUSTOM

Expand Down
56 changes: 56 additions & 0 deletions tests/core/actions/test_extract_slots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import textwrap
from unittest.mock import Mock

from rasa.core.actions.action import ActionExtractSlots
from rasa.core.channels import CollectingOutputChannel
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import UserUttered, SlotSet
from rasa.shared.core.trackers import DialogueStateTracker


async def test_action_extract_slots_returns_slot_set_even_if_slot_value_is_unchanged():
event_with_slot_entity = UserUttered(
text="I am a text",
intent={"name": "intent_with_entity"},
entities=[{"entity": "entity", "value": "value"}],
)

domain = textwrap.dedent(
"""
intents:
- intent_with_entity
entities:
- entity
slots:
entity:
type: text
mappings:
- type: from_entity
entity: entity
"""
)

domain = Domain.from_yaml(domain)

tracker = DialogueStateTracker.from_events(
"some-sender",
evts=[
event_with_slot_entity,
],
)

tracker._set_slot("entity", "value")

action = ActionExtractSlots(None)

events = await action.run(
output_channel=CollectingOutputChannel(),
nlg=Mock(),
tracker=tracker,
domain=domain,
)

assert len(events) == 1
assert type(events[0]) == SlotSet
assert events[0].key == "entity"
assert events[0].value == "value"

0 comments on commit f377154

Please sign in to comment.