Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATO 678 missing slot set event on a custom action filled slot #12314

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/12314.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed check preventing SlotSet event from being raised when custom action sets slot value to existing value.
ancalita marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,8 +1098,7 @@ async def _run_custom_action(
)
for event in custom_events:
if isinstance(event, SlotSet):
if tracker.get_slot(event.key) != event.value:
ancalita marked this conversation as resolved.
Show resolved Hide resolved
slot_events.append(event)
slot_events.append(event)
elif isinstance(event, BotUttered):
slot_events.append(event)
else:
Expand Down
69 changes: 69 additions & 0 deletions tests/core/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2825,3 +2825,72 @@ async def test_action_extract_slots_priority_of_slot_mappings():
)
tracker.update_with_events(events, domain=domain)
assert tracker.get_slot("location_slot") == entity_value


async def test_action_extract_slots_does_allows_slotset_for_same_value(
caplog: LogCaptureFixture,
):
domain_yaml = textwrap.dedent(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"

slots:
custom_slot_a:
type: text
influence_conversation: false
mappings:
- type: custom
action: custom_extract_action

actions:
- custom_extract_action
- action_validate_slot_mappings
"""
)
domain = Domain.from_yaml(domain_yaml)
event = UserUttered("Hi")
tracker = DialogueStateTracker.from_events(
sender_id="test_id", evts=[event], slots=domain.slots
ancalita marked this conversation as resolved.
Show resolved Hide resolved
)

action_server_url = "http://my-action-server:5055/webhook"

with aioresponses() as mocked:
mocked.post(
action_server_url,
payload={
"events": [
{"event": "slot", "name": "custom_slot_a", "value": "test_A"}
]
},
)

mocked.post(
action_server_url,
payload={
"events": [
{"event": "slot", "name": "custom_slot_a", "value": "test_A"}
]
},
)

action_server = EndpointConfig(action_server_url)
action_extract_slots = ActionExtractSlots(action_server)

with caplog.at_level(logging.INFO):
events = await action_extract_slots.run(
CollectingOutputChannel(),
TemplatedNaturalLanguageGenerator(domain.responses),
tracker,
domain,
)

caplog_info_records = list(
filter(lambda x: x[1] == logging.INFO, caplog.record_tuples)
)
assert len(caplog_info_records) == 0

assert events == [
SlotSet("custom_slot_a", "test_A"),
SlotSet("custom_slot_a", "test_A"),
]