rasa-pro 3.12.0.dev11__py3-none-any.whl → 3.12.0.dev12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rasa-pro might be problematic. Click here for more details.

Files changed (71) hide show
  1. rasa/cli/inspect.py +1 -20
  2. rasa/cli/shell.py +3 -3
  3. rasa/core/actions/action.py +7 -20
  4. rasa/core/actions/forms.py +5 -10
  5. rasa/core/channels/__init__.py +0 -2
  6. rasa/core/channels/voice_ready/audiocodes.py +23 -42
  7. rasa/core/channels/voice_stream/browser_audio.py +0 -1
  8. rasa/core/channels/voice_stream/call_state.py +1 -7
  9. rasa/core/channels/voice_stream/tts/azure.py +1 -2
  10. rasa/core/channels/voice_stream/tts/cartesia.py +3 -16
  11. rasa/core/channels/voice_stream/twilio_media_streams.py +1 -2
  12. rasa/core/channels/voice_stream/voice_channel.py +1 -2
  13. rasa/core/migrate.py +2 -2
  14. rasa/core/policies/flows/flow_executor.py +42 -36
  15. rasa/core/run.py +3 -4
  16. rasa/dialogue_understanding/commands/can_not_handle_command.py +2 -2
  17. rasa/dialogue_understanding/commands/cancel_flow_command.py +4 -62
  18. rasa/dialogue_understanding/commands/change_flow_command.py +2 -2
  19. rasa/dialogue_understanding/commands/chit_chat_answer_command.py +2 -2
  20. rasa/dialogue_understanding/commands/clarify_command.py +2 -2
  21. rasa/dialogue_understanding/commands/correct_slots_command.py +2 -11
  22. rasa/dialogue_understanding/commands/human_handoff_command.py +2 -2
  23. rasa/dialogue_understanding/commands/knowledge_answer_command.py +2 -2
  24. rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +2 -2
  25. rasa/dialogue_understanding/commands/set_slot_command.py +15 -7
  26. rasa/dialogue_understanding/commands/skip_question_command.py +2 -2
  27. rasa/dialogue_understanding/commands/start_flow_command.py +2 -43
  28. rasa/dialogue_understanding/commands/utils.py +1 -1
  29. rasa/dialogue_understanding/constants.py +0 -1
  30. rasa/dialogue_understanding/generator/command_generator.py +73 -110
  31. rasa/dialogue_understanding/generator/command_parser.py +1 -1
  32. rasa/dialogue_understanding/generator/llm_based_command_generator.py +3 -161
  33. rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +2 -10
  34. rasa/dialogue_understanding/generator/nlu_command_adapter.py +3 -44
  35. rasa/dialogue_understanding/generator/single_step/command_prompt_template.jinja2 +79 -53
  36. rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +19 -11
  37. rasa/dialogue_understanding/generator/utils.py +1 -32
  38. rasa/dialogue_understanding/patterns/correction.py +1 -13
  39. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +2 -62
  40. rasa/dialogue_understanding/processor/command_processor.py +28 -115
  41. rasa/dialogue_understanding/utils.py +0 -31
  42. rasa/dialogue_understanding_test/README.md +0 -50
  43. rasa/dialogue_understanding_test/test_case_simulation/test_case_tracker_simulator.py +3 -3
  44. rasa/model_service.py +0 -4
  45. rasa/model_training.py +27 -24
  46. rasa/shared/core/constants.py +3 -28
  47. rasa/shared/core/domain.py +20 -13
  48. rasa/shared/core/events.py +2 -13
  49. rasa/shared/core/flows/flow.py +0 -17
  50. rasa/shared/core/flows/flows_yaml_schema.json +0 -38
  51. rasa/shared/core/flows/steps/collect.py +1 -18
  52. rasa/shared/core/flows/utils.py +1 -16
  53. rasa/shared/core/slot_mappings.py +108 -144
  54. rasa/shared/core/slots.py +2 -23
  55. rasa/shared/core/trackers.py +1 -3
  56. rasa/shared/nlu/constants.py +0 -1
  57. rasa/shared/utils/llm.py +1 -1
  58. rasa/shared/utils/schemas/domain.yml +1 -0
  59. rasa/telemetry.py +13 -43
  60. rasa/utils/common.py +1 -0
  61. rasa/validator.py +82 -189
  62. rasa/version.py +1 -1
  63. {rasa_pro-3.12.0.dev11.dist-info → rasa_pro-3.12.0.dev12.dist-info}/METADATA +1 -1
  64. {rasa_pro-3.12.0.dev11.dist-info → rasa_pro-3.12.0.dev12.dist-info}/RECORD +67 -71
  65. rasa/core/actions/action_handle_digressions.py +0 -142
  66. rasa/core/channels/voice_stream/genesys.py +0 -331
  67. rasa/dialogue_understanding/commands/handle_digressions_command.py +0 -150
  68. rasa/dialogue_understanding/patterns/handle_digressions.py +0 -81
  69. {rasa_pro-3.12.0.dev11.dist-info → rasa_pro-3.12.0.dev12.dist-info}/NOTICE +0 -0
  70. {rasa_pro-3.12.0.dev11.dist-info → rasa_pro-3.12.0.dev12.dist-info}/WHEEL +0 -0
  71. {rasa_pro-3.12.0.dev11.dist-info → rasa_pro-3.12.0.dev12.dist-info}/entry_points.txt +0 -0
@@ -1,18 +1,14 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from functools import lru_cache
3
- from typing import Any, Dict, List, Optional, Set, Text, Tuple, Union
3
+ from typing import Any, Dict, List, Optional, Text, Tuple, Union
4
4
 
5
5
  import structlog
6
6
  from jinja2 import Template
7
7
 
8
- import rasa.dialogue_understanding.generator.utils
9
8
  import rasa.shared.utils.io
10
9
  from rasa.dialogue_understanding.commands import (
11
10
  Command,
12
- SetSlotCommand,
13
- StartFlowCommand,
14
11
  )
15
- from rasa.dialogue_understanding.constants import KEY_MINIMIZE_NUM_CALLS
16
12
  from rasa.dialogue_understanding.generator import CommandGenerator
17
13
  from rasa.dialogue_understanding.generator.constants import (
18
14
  DEFAULT_LLM_CONFIG,
@@ -22,18 +18,13 @@ from rasa.dialogue_understanding.generator.constants import (
22
18
  LLM_CONFIG_KEY,
23
19
  )
24
20
  from rasa.dialogue_understanding.generator.flow_retrieval import FlowRetrieval
25
- from rasa.dialogue_understanding.stack.utils import top_flow_frame
26
21
  from rasa.engine.graph import ExecutionContext, GraphComponent
27
22
  from rasa.engine.recipes.default_recipe import DefaultV1Recipe
28
23
  from rasa.engine.storage.resource import Resource
29
24
  from rasa.engine.storage.storage import ModelStorage
30
- from rasa.shared.core.constants import (
31
- SetSlotExtractor,
32
- )
33
25
  from rasa.shared.core.domain import Domain
34
26
  from rasa.shared.core.flows import Flow, FlowsList, FlowStep
35
27
  from rasa.shared.core.flows.steps.collect import CollectInformationFlowStep
36
- from rasa.shared.core.slot_mappings import SlotFillingManager
37
28
  from rasa.shared.core.trackers import DialogueStateTracker
38
29
  from rasa.shared.exceptions import FileIOException, ProviderClientAPIException
39
30
  from rasa.shared.nlu.constants import FLOWS_IN_PROMPT
@@ -366,7 +357,8 @@ class LLMBasedCommandGenerator(
366
357
  "slots": slots_with_info,
367
358
  }
368
359
  )
369
- return result
360
+
361
+ return sorted(result, key=lambda x: x["name"])
370
362
 
371
363
  @staticmethod
372
364
  def is_extractable(
@@ -462,153 +454,3 @@ class LLMBasedCommandGenerator(
462
454
  if isinstance(current_step, CollectInformationFlowStep)
463
455
  else (None, None)
464
456
  )
465
-
466
- @staticmethod
467
- def _prior_commands_contain_start_flow(prior_commands: List[Command]) -> bool:
468
- return any(isinstance(command, StartFlowCommand) for command in prior_commands)
469
-
470
- @staticmethod
471
- def _prior_commands_contain_set_slot_for_active_collect_step(
472
- prior_commands: List[Command],
473
- flows: FlowsList,
474
- tracker: DialogueStateTracker,
475
- ) -> bool:
476
- latest_user_frame = top_flow_frame(tracker.stack, ignore_call_frames=False)
477
-
478
- if latest_user_frame is None:
479
- return False
480
-
481
- active_flow = latest_user_frame.flow(flows)
482
- active_step = active_flow.step_by_id(latest_user_frame.step_id)
483
-
484
- if not isinstance(active_step, CollectInformationFlowStep):
485
- return False
486
-
487
- return any(
488
- command.name == active_step.collect
489
- for command in prior_commands
490
- if isinstance(command, SetSlotCommand)
491
- )
492
-
493
- def _should_skip_llm_call(
494
- self,
495
- prior_commands: List[Command],
496
- flows: FlowsList,
497
- tracker: DialogueStateTracker,
498
- ) -> bool:
499
- """Skip invoking the LLM.
500
-
501
- This returns True if the bot builder sets the property
502
- KEY_MINIMIZE_NUM_CALLS to True and the prior commands
503
- either contain a StartFlowCommand or a SetSlot command
504
- for the current collect step.
505
- """
506
- return self.config.get(KEY_MINIMIZE_NUM_CALLS, False) and (
507
- self._prior_commands_contain_start_flow(prior_commands)
508
- or self._prior_commands_contain_set_slot_for_active_collect_step(
509
- prior_commands, flows, tracker
510
- )
511
- )
512
-
513
- @staticmethod
514
- def _check_commands_against_slot_mappings(
515
- commands: List[Command],
516
- tracker: DialogueStateTracker,
517
- domain: Optional[Domain] = None,
518
- ) -> List[Command]:
519
- """Check if the LLM-issued slot commands are fillable.
520
-
521
- The LLM-issued slot commands are fillable if the slot
522
- mappings are satisfied (in particular the mapping conditions).
523
- """
524
- if not domain:
525
- return commands
526
-
527
- llm_fillable_slots = [
528
- tracker.slots.get(command.name)
529
- for command in commands
530
- if isinstance(command, SetSlotCommand)
531
- and command.extractor == SetSlotExtractor.LLM.value
532
- and tracker.slots.get(command.name) is not None
533
- ]
534
-
535
- if not llm_fillable_slots:
536
- return commands
537
-
538
- slot_filling_manager = SlotFillingManager(domain, tracker)
539
- slots_to_be_removed = []
540
-
541
- structlogger.debug(
542
- "command_processor.check_commands_against_slot_mappings.active_flow",
543
- active_flow=tracker.active_flow,
544
- )
545
-
546
- for slot in llm_fillable_slots:
547
- should_fill_slot = False
548
- for mapping in slot.mappings: # type: ignore[union-attr]
549
- should_fill_slot = slot_filling_manager.should_fill_slot(
550
- slot.name, # type: ignore[union-attr]
551
- mapping,
552
- )
553
-
554
- if should_fill_slot:
555
- break
556
-
557
- if not should_fill_slot:
558
- structlogger.debug(
559
- "command_processor.check_commands_against_slot_mappings.slot_not_fillable",
560
- slot_name=slot.name, # type: ignore[union-attr]
561
- )
562
- slots_to_be_removed.append(slot.name) # type: ignore[union-attr]
563
-
564
- if not slots_to_be_removed:
565
- return commands
566
-
567
- filtered_commands = [
568
- command
569
- for command in commands
570
- if not (
571
- isinstance(command, SetSlotCommand)
572
- and command.name in slots_to_be_removed
573
- )
574
- ]
575
-
576
- return filtered_commands
577
-
578
- def _check_start_flow_command_overlap(
579
- self,
580
- prior_commands: List[Command],
581
- commands: List[Command],
582
- prior_start_flow_names: Set[str],
583
- current_start_flow_names: Set[str],
584
- ) -> List[Command]:
585
- """Prioritize the prior commands over the LLM-issued commands."""
586
- different_flow_names = current_start_flow_names.difference(
587
- prior_start_flow_names
588
- )
589
-
590
- if not different_flow_names:
591
- return prior_commands + commands
592
-
593
- # discard the flow names that are different to prior start flow commands
594
- filtered_commands = [
595
- command
596
- for command in commands
597
- if not isinstance(command, StartFlowCommand)
598
- or command.flow not in different_flow_names
599
- ]
600
- return prior_commands + filtered_commands
601
-
602
- def _filter_slot_commands(
603
- self,
604
- prior_commands: List[Command],
605
- commands: List[Command],
606
- overlapping_slot_names: Set[str],
607
- ) -> Tuple[List[Command], List[Command]]:
608
- """Prioritize prior commands over LLM ones in the case of same slot."""
609
- filtered_commands = (
610
- rasa.dialogue_understanding.generator.utils.filter_slot_commands(
611
- commands, overlapping_slot_names
612
- )
613
- )
614
- return prior_commands, filtered_commands
@@ -190,14 +190,9 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
190
190
  Returns:
191
191
  The commands generated by the llm.
192
192
  """
193
- prior_commands = self._get_prior_commands(message)
194
-
195
193
  if tracker is None or flows.is_empty():
196
194
  # cannot do anything if there are no flows or no tracker
197
- return prior_commands
198
-
199
- if self._should_skip_llm_call(prior_commands, flows, tracker):
200
- return prior_commands
195
+ return []
201
196
 
202
197
  try:
203
198
  commands = await self._predict_commands_with_multi_step(
@@ -226,10 +221,7 @@ class MultiStepLLMCommandGenerator(LLMBasedCommandGenerator):
226
221
  commands=commands,
227
222
  )
228
223
 
229
- domain = kwargs.get("domain")
230
- commands = self._check_commands_against_slot_mappings(commands, tracker, domain)
231
-
232
- return self._check_commands_overlap(prior_commands, commands)
224
+ return commands
233
225
 
234
226
  @classmethod
235
227
  def parse_commands(
@@ -1,8 +1,7 @@
1
- from typing import Any, Dict, List, Optional, Set, Text, Tuple
1
+ from typing import Any, Dict, List, Optional, Text
2
2
 
3
3
  import structlog
4
4
 
5
- import rasa.dialogue_understanding.generator.utils
6
5
  from rasa.dialogue_understanding.commands import (
7
6
  Command,
8
7
  SetSlotCommand,
@@ -99,11 +98,9 @@ class NLUCommandAdapter(GraphComponent, CommandGenerator):
99
98
  Returns:
100
99
  The commands triggered by NLU.
101
100
  """
102
- prior_commands = self._get_prior_commands(message)
103
-
104
101
  if tracker is None or flows.is_empty():
105
102
  # cannot do anything if there are no flows or no tracker
106
- return prior_commands
103
+ return []
107
104
 
108
105
  domain = kwargs.get("domain", None)
109
106
  commands = self.convert_nlu_to_commands(message, tracker, flows, domain)
@@ -149,7 +146,7 @@ class NLUCommandAdapter(GraphComponent, CommandGenerator):
149
146
  commands=commands,
150
147
  )
151
148
 
152
- return self._check_commands_overlap(prior_commands, commands)
149
+ return commands
153
150
 
154
151
  @staticmethod
155
152
  def convert_nlu_to_commands(
@@ -211,44 +208,6 @@ class NLUCommandAdapter(GraphComponent, CommandGenerator):
211
208
  )
212
209
  return commands
213
210
 
214
- def _check_start_flow_command_overlap(
215
- self,
216
- prior_commands: List[Command],
217
- commands: List[Command],
218
- prior_start_flow_names: Set[str],
219
- current_start_flow_names: Set[str],
220
- ) -> List[Command]:
221
- """Prioritize the current NLU commands over the prior commands."""
222
- different_flow_names = prior_start_flow_names.difference(
223
- current_start_flow_names
224
- )
225
-
226
- if not different_flow_names:
227
- return prior_commands + commands
228
-
229
- filtered_commands = [
230
- command
231
- for command in prior_commands
232
- if not isinstance(command, StartFlowCommand)
233
- or command.flow not in different_flow_names
234
- ]
235
-
236
- return filtered_commands + commands
237
-
238
- def _filter_slot_commands(
239
- self,
240
- prior_commands: List[Command],
241
- commands: List[Command],
242
- overlapping_slot_names: Set[str],
243
- ) -> Tuple[List[Command], List[Command]]:
244
- """Prioritize NLU commands over prior_commands in the case of same slot."""
245
- filtered_prior_commands = (
246
- rasa.dialogue_understanding.generator.utils.filter_slot_commands(
247
- prior_commands, overlapping_slot_names
248
- )
249
- )
250
- return filtered_prior_commands, commands
251
-
252
211
 
253
212
  def _issue_set_slot_commands(
254
213
  message: Message,
@@ -1,58 +1,84 @@
1
+ ## Task Description
1
2
  Your task is to analyze the current conversation context and generate a list of actions to start new business processes that we call flows, to extract slots, or respond to small talk and knowledge requests.
2
3
 
3
- These are the flows that can be started, with their description and slots:
4
- {% for flow in available_flows %}
5
- {{ flow.name }}: {{ flow.description }}
6
- {% for slot in flow.slots -%}
7
- slot: {{ slot.name }}{% if slot.description %} ({{ slot.description }}){% endif %}{% if slot.allowed_values %}, allowed values: {{ slot.allowed_values }}{% endif %}
8
- {% endfor %}
9
- {%- endfor %}
4
+ --
10
5
 
11
- ===
12
- Here is what happened previously in the conversation:
6
+ ## Available Actions:
7
+ * `start flow flow_name`: Starting a flow. For example, `start flow transfer_money` or `start flow list_contacts`
8
+ * `set slot slot_name slot_value`: Slot setting. For example, `set slot transfer_money_recipient Freddy`. Can be used to correct and change previously set values
9
+ * `cancel flow`: Cancelling the current flow
10
+ * `disambiguate flows flow_name1 flow_name2 ... flow_name_n`: Disambiguate which flow should be started when user input is ambiguous by listing the potential flows as options. For example, `clarify flows list_contacts add_contact remove_contact ...` if the user just wrote "contacts".
11
+ * `provide info`: Responding to the user's questions by supplying relevant information, such as answering FAQs or explaining services
12
+ * `offtopic reply`: Responding to casual or social user messages that are unrelated to any flows, engaging in friendly conversation and addressing off-topic remarks.
13
+ * `hand over`: Handing over to a human, in case the user seems frustrated or explicitly asks to speak to one
14
+
15
+ --
16
+
17
+ ## General Tips
18
+ * Do not fill slots with abstract values or placeholders.
19
+ * Only use information provided by the user.
20
+ * Use clarification in ambiguous cases.
21
+ * Multiple flows can be started. If a user wants to digress into a second flow, you do not need to cancel the current flow.
22
+ * Strictly adhere to the provided action format.
23
+ * For categorical slots try to match the user message with potential slot values. Use "other" if you cannot match it
24
+ * Focus on the last message and take it one step at a time.
25
+ * Use the previous conversation steps only to aid understanding.
26
+
27
+ --
28
+
29
+ ## Available Flows and Slots
30
+ Use the following structured date:
31
+ ```json
32
+ {
33
+ "flows": [
34
+ {% for flow in available_flows %}{
35
+ "name": "{{ flow.name }}",
36
+ "description": "{{ flow.description }}"{% if flow.slots %},
37
+ "slots": [{% for slot in flow.slots %}
38
+ {
39
+ "name": "{{ slot.name }}"{% if slot.description %},
40
+ "description": "{{ slot.description }}"{% endif %}{% if slot.allowed_values %},
41
+ "allowed_values": {{ slot.allowed_values }}{% endif %}
42
+ }{% if not loop.last %},{% endif %}{% endfor %}
43
+ ]{% endif %}
44
+ }{% if not loop.last %},
45
+ {% endif %}{% endfor %}
46
+ ]
47
+ }
48
+ ```
49
+
50
+ --
51
+
52
+ ## Current State
53
+ {% if current_flow != None %}Use the following structured date:
54
+ ```json
55
+ {
56
+ "active_flow": "{{ current_flow }}",
57
+ "current_step": {
58
+ "requested_slot": "{{ current_slot }}",
59
+ "requested_slot_description": "{{ current_slot_description }}"
60
+ },
61
+ "slots": [{% for slot in flow_slots %}
62
+ {
63
+ "name": "{{ slot.name }}",
64
+ "value": "{{ slot.value }}",
65
+ "type": "{{ slot.type }}"{% if slot.description %},
66
+ "description": "{{ slot.description }}"{% endif %}{% if slot.allowed_values %},
67
+ "allowed_values": "{{ slot.allowed_values }}"{% endif %}
68
+ }{% if not loop.last %},{% endif %}{% endfor %}
69
+ ]
70
+ }
71
+ ```{% else %}
72
+ You are currently not inside any flow.{% endif %}
73
+
74
+ ---
75
+
76
+ ## Conversation History
13
77
  {{ current_conversation }}
14
78
 
15
- ===
16
- {% if current_flow != None %}
17
- You are currently in the flow "{{ current_flow }}".
18
- You have just asked the user for the slot "{{ current_slot }}"{% if current_slot_description %} ({{ current_slot_description }}){% endif %}.
19
-
20
- {% if flow_slots|length > 0 %}
21
- Here are the slots of the currently active flow:
22
- {% for slot in flow_slots -%}
23
- - name: {{ slot.name }}, value: {{ slot.value }}, type: {{ slot.type }}, description: {{ slot.description}}{% if slot.allowed_values %}, allowed values: {{ slot.allowed_values }}{% endif %}
24
- {% endfor %}
25
- {% endif %}
26
- {% else %}
27
- You are currently not in any flow and so there are no active slots.
28
- This means you can only set a slot if you first start a flow that requires that slot.
29
- {% endif %}
30
- If you start a flow, first start the flow and then optionally fill that flow's slots with information the user provided in their message.
31
-
32
- The user just said """{{ user_message }}""".
33
-
34
- ===
35
- Based on this information generate a list of actions you want to take. Your job is to start flows and to fill slots where appropriate. Any logic of what happens afterwards is handled by the flow engine. These are your available actions:
36
- * Slot setting, described by "SetSlot(slot_name, slot_value)". An example would be "SetSlot(recipient, Freddy)"
37
- * Starting another flow, described by "StartFlow(flow_name)". An example would be "StartFlow(transfer_money)"
38
- * Cancelling the current flow, described by "CancelFlow()"
39
- * Clarifying which flow should be started. An example would be Clarify(list_contacts, add_contact, remove_contact) if the user just wrote "contacts" and there are multiple potential candidates. It also works with a single flow name to confirm you understood correctly, as in Clarify(transfer_money).
40
- * Intercepting and handle user messages with the intent to bypass the current step in the flow, described by "SkipQuestion()". Examples of user skip phrases are: "Go to the next question", "Ask me something else".
41
- * Responding to knowledge-oriented user messages, described by "SearchAndReply()"
42
- * Responding to a casual, non-task-oriented user message, described by "ChitChat()".
43
- * Handing off to a human, in case the user seems frustrated or explicitly asks to speak to one, described by "HumanHandoff()".
44
- * Repeat the last bot messages, described by "RepeatLastBotMessages()". This is useful when the user asks to repeat the last bot messages.
45
-
46
- ===
47
- Write out the actions you want to take, one per line, in the order they should take place.
48
- Do not fill slots with abstract values or placeholders.
49
- Only use information provided by the user.
50
- Only start a flow if it's completely clear what the user wants. Imagine you were a person reading this message. If it's not 100% clear, clarify the next step.
51
- Don't be overly confident. Take a conservative approach and clarify before proceeding.
52
- If the user asks for two things which seem contradictory, clarify before starting a flow.
53
- If it's not clear whether the user wants to skip the step or to cancel the flow, cancel the flow.
54
- Strictly adhere to the provided action types listed above.
55
- Focus on the last message and take it one step at a time.
56
- Use the previous conversation steps only to aid understanding.
57
-
58
- Your action list:
79
+ ---
80
+
81
+ ## Task
82
+ Create an action list with one action per line in response to the users last message: """{{ user_message }}""".
83
+
84
+ Your action list:
@@ -51,6 +51,7 @@ from rasa.shared.utils.llm import (
51
51
  sanitize_message_for_prompt,
52
52
  tracker_as_readable_transcript,
53
53
  )
54
+ from rasa.utils.beta import BetaNotEnabledException, ensure_beta_feature_is_enabled
54
55
  from rasa.utils.log_utils import log_llm
55
56
 
56
57
  COMMAND_PROMPT_FILE_NAME = "command_prompt.jinja2"
@@ -110,6 +111,7 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
110
111
  )
111
112
 
112
113
  self.trace_prompt_tokens = self.config.get("trace_prompt_tokens", False)
114
+ self.repeat_command_enabled = self.is_repeat_command_enabled()
113
115
 
114
116
  ### Implementations of LLMBasedCommandGenerator parent
115
117
  @staticmethod
@@ -196,14 +198,9 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
196
198
  Returns:
197
199
  The commands generated by the llm.
198
200
  """
199
- prior_commands = self._get_prior_commands(message)
200
-
201
201
  if tracker is None or flows.is_empty():
202
202
  # cannot do anything if there are no flows or no tracker
203
- return prior_commands
204
-
205
- if self._should_skip_llm_call(prior_commands, flows, tracker):
206
- return prior_commands
203
+ return []
207
204
 
208
205
  try:
209
206
  commands = await self._predict_commands(message, flows, tracker)
@@ -212,7 +209,7 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
212
209
  # "predict" the ErrorCommand
213
210
  commands = [ErrorCommand()]
214
211
 
215
- if not commands and not prior_commands:
212
+ if not commands:
216
213
  # no commands are parsed or there's an invalid command
217
214
  structlogger.warning(
218
215
  "single_step_llm_command_generator.predict_commands",
@@ -233,10 +230,7 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
233
230
  commands=commands,
234
231
  )
235
232
 
236
- domain = kwargs.get("domain")
237
- commands = self._check_commands_against_slot_mappings(commands, tracker, domain)
238
-
239
- return self._check_commands_overlap(prior_commands, commands)
233
+ return commands
240
234
 
241
235
  async def _predict_commands(
242
236
  self,
@@ -412,6 +406,20 @@ class SingleStepLLMCommandGenerator(LLMBasedCommandGenerator):
412
406
  "current_slot": current_slot,
413
407
  "current_slot_description": current_slot_description,
414
408
  "user_message": latest_user_message,
409
+ "is_repeat_command_enabled": self.repeat_command_enabled,
415
410
  }
416
411
 
417
412
  return self.compile_template(self.prompt_template).render(**inputs)
413
+
414
+ def is_repeat_command_enabled(self) -> bool:
415
+ """Check for feature flag"""
416
+ RASA_PRO_BETA_REPEAT_COMMAND_ENV_VAR_NAME = "RASA_PRO_BETA_REPEAT_COMMAND"
417
+ try:
418
+ ensure_beta_feature_is_enabled(
419
+ "Repeat Command",
420
+ env_flag=RASA_PRO_BETA_REPEAT_COMMAND_ENV_VAR_NAME,
421
+ )
422
+ except BetaNotEnabledException:
423
+ return False
424
+
425
+ return True
@@ -1,16 +1,14 @@
1
- from typing import Dict, List, Set, Type
1
+ from typing import Dict, Type
2
2
 
3
3
  from rasa.dialogue_understanding.commands import (
4
4
  CancelFlowCommand,
5
5
  CannotHandleCommand,
6
6
  ChitChatAnswerCommand,
7
7
  Command,
8
- CorrectSlotsCommand,
9
8
  HumanHandoffCommand,
10
9
  KnowledgeAnswerCommand,
11
10
  RestartCommand,
12
11
  SessionStartCommand,
13
- SetSlotCommand,
14
12
  SkipQuestionCommand,
15
13
  )
16
14
  from rasa.dialogue_understanding.commands.user_silence_command import UserSilenceCommand
@@ -45,32 +43,3 @@ triggerable_pattern_to_command_class: Dict[str, Type[Command]] = {
45
43
  CannotHandlePatternFlowStackFrame.flow_id: CannotHandleCommand,
46
44
  RestartPatternFlowStackFrame.flow_id: RestartCommand,
47
45
  }
48
-
49
-
50
- def filter_slot_commands(
51
- commands: List[Command], overlapping_slot_names: Set[str]
52
- ) -> List[Command]:
53
- """Filter out slot commands that set overlapping slots."""
54
- filtered_commands = []
55
-
56
- for command in commands:
57
- if (
58
- isinstance(command, SetSlotCommand)
59
- and command.name in overlapping_slot_names
60
- ):
61
- continue
62
-
63
- if isinstance(command, CorrectSlotsCommand):
64
- allowed_slots = [
65
- slot
66
- for slot in command.corrected_slots
67
- if slot.name not in overlapping_slot_names
68
- ]
69
- if not allowed_slots:
70
- continue
71
-
72
- command.corrected_slots = allowed_slots
73
-
74
- filtered_commands.append(command)
75
-
76
- return filtered_commands
@@ -54,8 +54,6 @@ class CorrectionPatternFlowStackFrame(PatternFlowStackFrame):
54
54
  """The ID of the flow to reset to."""
55
55
  reset_step_id: Optional[str] = None
56
56
  """The ID of the step to reset to."""
57
- new_slot_values: List[Any] = field(default_factory=list)
58
- """The new values for the corrected slots."""
59
57
 
60
58
  @classmethod
61
59
  def type(cls) -> str:
@@ -72,10 +70,6 @@ class CorrectionPatternFlowStackFrame(PatternFlowStackFrame):
72
70
  Returns:
73
71
  The created `DialogueStackFrame`.
74
72
  """
75
- new_slot_values = [
76
- val.get("value") for _, val in data["corrected_slots"].items()
77
- ]
78
-
79
73
  return CorrectionPatternFlowStackFrame(
80
74
  frame_id=data["frame_id"],
81
75
  step_id=data["step_id"],
@@ -83,7 +77,6 @@ class CorrectionPatternFlowStackFrame(PatternFlowStackFrame):
83
77
  corrected_slots=data["corrected_slots"],
84
78
  reset_flow_id=data["reset_flow_id"],
85
79
  reset_step_id=data["reset_step_id"],
86
- new_slot_values=new_slot_values,
87
80
  )
88
81
 
89
82
 
@@ -125,12 +118,7 @@ class ActionCorrectFlowSlot(action.Action):
125
118
  )
126
119
  events.extend(tracker.create_stack_updated_events(updated_stack))
127
120
 
128
- events.extend(
129
- [
130
- SlotSet(name, value=val.get("value"), filled_by=val.get("filled_by"))
131
- for name, val in top.corrected_slots.items()
132
- ]
133
- )
121
+ events.extend([SlotSet(k, v) for k, v in top.corrected_slots.items()])
134
122
  return events
135
123
 
136
124