rasa-pro 3.14.0a22__py3-none-any.whl → 3.14.0a23__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 (329) hide show
  1. rasa/__main__.py +15 -3
  2. rasa/agents/__init__.py +0 -0
  3. rasa/agents/agent_factory.py +122 -0
  4. rasa/agents/agent_manager.py +211 -0
  5. rasa/agents/constants.py +43 -0
  6. rasa/agents/core/__init__.py +0 -0
  7. rasa/agents/core/agent_protocol.py +107 -0
  8. rasa/agents/core/types.py +81 -0
  9. rasa/agents/exceptions.py +38 -0
  10. rasa/agents/protocol/__init__.py +5 -0
  11. rasa/agents/protocol/a2a/__init__.py +0 -0
  12. rasa/agents/protocol/a2a/a2a_agent.py +879 -0
  13. rasa/agents/protocol/mcp/__init__.py +0 -0
  14. rasa/agents/protocol/mcp/mcp_base_agent.py +726 -0
  15. rasa/agents/protocol/mcp/mcp_open_agent.py +327 -0
  16. rasa/agents/protocol/mcp/mcp_task_agent.py +522 -0
  17. rasa/agents/schemas/__init__.py +13 -0
  18. rasa/agents/schemas/agent_input.py +38 -0
  19. rasa/agents/schemas/agent_output.py +26 -0
  20. rasa/agents/schemas/agent_tool_result.py +65 -0
  21. rasa/agents/schemas/agent_tool_schema.py +186 -0
  22. rasa/agents/templates/__init__.py +0 -0
  23. rasa/agents/templates/mcp_open_agent_prompt_template.jinja2 +20 -0
  24. rasa/agents/templates/mcp_task_agent_prompt_template.jinja2 +22 -0
  25. rasa/agents/utils.py +206 -0
  26. rasa/agents/validation.py +485 -0
  27. rasa/api.py +24 -9
  28. rasa/builder/config.py +6 -2
  29. rasa/builder/guardrails/{lakera.py → clients.py} +55 -5
  30. rasa/builder/guardrails/constants.py +3 -0
  31. rasa/builder/guardrails/models.py +45 -10
  32. rasa/builder/guardrails/policy_checker.py +324 -0
  33. rasa/builder/guardrails/utils.py +42 -276
  34. rasa/builder/llm_service.py +32 -5
  35. rasa/builder/models.py +1 -0
  36. rasa/builder/project_generator.py +6 -1
  37. rasa/builder/service.py +16 -13
  38. rasa/builder/training_service.py +18 -24
  39. rasa/builder/validation_service.py +1 -1
  40. rasa/cli/arguments/default_arguments.py +12 -0
  41. rasa/cli/arguments/run.py +2 -0
  42. rasa/cli/arguments/train.py +2 -0
  43. rasa/cli/data.py +10 -8
  44. rasa/cli/dialogue_understanding_test.py +10 -7
  45. rasa/cli/e2e_test.py +9 -6
  46. rasa/cli/evaluate.py +4 -2
  47. rasa/cli/export.py +5 -2
  48. rasa/cli/inspect.py +8 -4
  49. rasa/cli/interactive.py +5 -4
  50. rasa/cli/llm_fine_tuning.py +11 -6
  51. rasa/cli/project_templates/finance/actions/general/__init__.py +0 -0
  52. rasa/cli/project_templates/finance/actions/general/action_human_handoff.py +49 -0
  53. rasa/cli/project_templates/finance/data/general/bot_challenge.yml +6 -0
  54. rasa/cli/project_templates/finance/data/general/goodbye.yml +1 -1
  55. rasa/cli/project_templates/finance/data/general/human_handoff.yml +1 -1
  56. rasa/cli/project_templates/finance/data/system/patterns/pattern_session_start.yml +1 -1
  57. rasa/cli/project_templates/finance/domain/general/_shared.yml +0 -14
  58. rasa/cli/project_templates/finance/domain/general/bot_challenge.yml +4 -0
  59. rasa/cli/project_templates/finance/domain/general/goodbye.yml +7 -0
  60. rasa/cli/project_templates/finance/domain/general/human_handoff.yml +3 -6
  61. rasa/cli/project_templates/finance/domain/general/welcome.yml +29 -1
  62. rasa/cli/project_templates/finance/tests/e2e_test_cases/accounts/check_balance.yml +9 -0
  63. rasa/cli/project_templates/finance/tests/e2e_test_cases/accounts/download_statements.yml +43 -0
  64. rasa/cli/project_templates/finance/tests/e2e_test_cases/cards/block_card.yml +55 -0
  65. rasa/cli/project_templates/finance/tests/e2e_test_cases/general/bot_challenge.yml +8 -0
  66. rasa/cli/project_templates/finance/tests/e2e_test_cases/general/feedback.yml +46 -0
  67. rasa/cli/project_templates/finance/tests/e2e_test_cases/general/goodbye.yml +9 -0
  68. rasa/cli/project_templates/finance/tests/e2e_test_cases/general/hello.yml +8 -0
  69. rasa/cli/project_templates/finance/tests/e2e_test_cases/general/human_handoff.yml +35 -0
  70. rasa/cli/project_templates/finance/tests/e2e_test_cases/general/patterns.yml +22 -0
  71. rasa/cli/project_templates/finance/tests/e2e_test_cases/transfers/transfer_money.yml +56 -0
  72. rasa/cli/project_templates/telco/tests/e2e_test_cases/general/feedback.yml +1 -1
  73. rasa/cli/project_templates/telco/tests/e2e_test_cases/general/hello.yml +1 -1
  74. rasa/cli/project_templates/telco/tests/e2e_test_cases/general/human_handoff.yml +1 -1
  75. rasa/cli/project_templates/telco/tests/e2e_test_cases/general/patterns.yml +1 -1
  76. rasa/cli/project_templates/tutorial/credentials.yml +10 -0
  77. rasa/cli/run.py +12 -10
  78. rasa/cli/scaffold.py +4 -4
  79. rasa/cli/shell.py +9 -5
  80. rasa/cli/studio/studio.py +1 -1
  81. rasa/cli/test.py +34 -14
  82. rasa/cli/train.py +41 -28
  83. rasa/cli/utils.py +1 -393
  84. rasa/cli/validation/__init__.py +0 -0
  85. rasa/cli/validation/bot_config.py +223 -0
  86. rasa/cli/validation/config_path_validation.py +257 -0
  87. rasa/cli/x.py +8 -4
  88. rasa/constants.py +7 -1
  89. rasa/core/actions/action.py +51 -10
  90. rasa/core/actions/action_run_slot_rejections.py +1 -1
  91. rasa/core/actions/grpc_custom_action_executor.py +1 -1
  92. rasa/core/agent.py +19 -2
  93. rasa/core/available_agents.py +229 -0
  94. rasa/core/brokers/kafka.py +1 -1
  95. rasa/core/channels/__init__.py +82 -35
  96. rasa/core/channels/development_inspector.py +3 -3
  97. rasa/core/channels/inspector/README.md +25 -13
  98. rasa/core/channels/inspector/dist/assets/{arc-35222594.js → arc-6177260a.js} +1 -1
  99. rasa/core/channels/inspector/dist/assets/{blockDiagram-38ab4fdb-a0efbfd3.js → blockDiagram-38ab4fdb-b054f038.js} +1 -1
  100. rasa/core/channels/inspector/dist/assets/{c4Diagram-3d4e48cf-0584c0f2.js → c4Diagram-3d4e48cf-f25427d5.js} +1 -1
  101. rasa/core/channels/inspector/dist/assets/channel-bf9cbb34.js +1 -0
  102. rasa/core/channels/inspector/dist/assets/{classDiagram-70f12bd4-39f40dbe.js → classDiagram-70f12bd4-c7a2af53.js} +1 -1
  103. rasa/core/channels/inspector/dist/assets/{classDiagram-v2-f2320105-1ad755f3.js → classDiagram-v2-f2320105-58db65c0.js} +1 -1
  104. rasa/core/channels/inspector/dist/assets/clone-8f9083bb.js +1 -0
  105. rasa/core/channels/inspector/dist/assets/{createText-2e5e7dd3-b0f4f0fe.js → createText-2e5e7dd3-088372e2.js} +1 -1
  106. rasa/core/channels/inspector/dist/assets/{edges-e0da2a9e-9039bff9.js → edges-e0da2a9e-58676240.js} +1 -1
  107. rasa/core/channels/inspector/dist/assets/{erDiagram-9861fffd-65c9b127.js → erDiagram-9861fffd-0c14d7c6.js} +1 -1
  108. rasa/core/channels/inspector/dist/assets/{flowDb-956e92f1-4f08b38e.js → flowDb-956e92f1-ea63f85c.js} +1 -1
  109. rasa/core/channels/inspector/dist/assets/{flowDiagram-66a62f08-e95c362a.js → flowDiagram-66a62f08-a2af48cd.js} +1 -1
  110. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-96b9c2cf-9ecd5b59.js +1 -0
  111. rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-4a651766-703c3015.js → flowchart-elk-definition-4a651766-6937abe7.js} +1 -1
  112. rasa/core/channels/inspector/dist/assets/{ganttDiagram-c361ad54-699328ea.js → ganttDiagram-c361ad54-7473f357.js} +1 -1
  113. rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-72cf32ee-04cf4b05.js → gitGraphDiagram-72cf32ee-d0c9405e.js} +1 -1
  114. rasa/core/channels/inspector/dist/assets/{graph-ee94449e.js → graph-0a6f8466.js} +1 -1
  115. rasa/core/channels/inspector/dist/assets/{index-3862675e-940162b4.js → index-3862675e-7610671a.js} +1 -1
  116. rasa/core/channels/inspector/dist/assets/index-74e01d94.js +1354 -0
  117. rasa/core/channels/inspector/dist/assets/{infoDiagram-f8f76790-c79c2866.js → infoDiagram-f8f76790-be397dc7.js} +1 -1
  118. rasa/core/channels/inspector/dist/assets/{journeyDiagram-49397b02-84489d30.js → journeyDiagram-49397b02-4cefbf62.js} +1 -1
  119. rasa/core/channels/inspector/dist/assets/{layout-a9aa9858.js → layout-e7fbc2bf.js} +1 -1
  120. rasa/core/channels/inspector/dist/assets/{line-eb73cf26.js → line-a8aa457c.js} +1 -1
  121. rasa/core/channels/inspector/dist/assets/{linear-b3399f9a.js → linear-3351e0d2.js} +1 -1
  122. rasa/core/channels/inspector/dist/assets/{mindmap-definition-fc14e90a-b095bf1a.js → mindmap-definition-fc14e90a-b8cbf605.js} +1 -1
  123. rasa/core/channels/inspector/dist/assets/{pieDiagram-8a3498a8-07644b66.js → pieDiagram-8a3498a8-f327f774.js} +1 -1
  124. rasa/core/channels/inspector/dist/assets/{quadrantDiagram-120e2f19-573a3f9c.js → quadrantDiagram-120e2f19-2854c591.js} +1 -1
  125. rasa/core/channels/inspector/dist/assets/{requirementDiagram-deff3bca-d457e1e1.js → requirementDiagram-deff3bca-964985d5.js} +1 -1
  126. rasa/core/channels/inspector/dist/assets/{sankeyDiagram-04a897e0-9d26e1a2.js → sankeyDiagram-04a897e0-edeb4f33.js} +1 -1
  127. rasa/core/channels/inspector/dist/assets/{sequenceDiagram-704730f1-3a9cde10.js → sequenceDiagram-704730f1-fcf70125.js} +1 -1
  128. rasa/core/channels/inspector/dist/assets/{stateDiagram-587899a1-4f3e8cec.js → stateDiagram-587899a1-0e770395.js} +1 -1
  129. rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-d93cdb3a-e617e5bf.js → stateDiagram-v2-d93cdb3a-af8dcd22.js} +1 -1
  130. rasa/core/channels/inspector/dist/assets/{styles-6aaf32cf-eab30d2f.js → styles-6aaf32cf-36a9e70d.js} +1 -1
  131. rasa/core/channels/inspector/dist/assets/{styles-9a916d00-09994be2.js → styles-9a916d00-884a8b5b.js} +1 -1
  132. rasa/core/channels/inspector/dist/assets/{styles-c10674c1-b7110364.js → styles-c10674c1-dc097813.js} +1 -1
  133. rasa/core/channels/inspector/dist/assets/{svgDrawCommon-08f97a94-3ebc92ad.js → svgDrawCommon-08f97a94-5a2c7eed.js} +1 -1
  134. rasa/core/channels/inspector/dist/assets/{timeline-definition-85554ec2-7d13d2f2.js → timeline-definition-85554ec2-e89c4f6e.js} +1 -1
  135. rasa/core/channels/inspector/dist/assets/{xychartDiagram-e933f94c-488385e1.js → xychartDiagram-e933f94c-afb6fe56.js} +1 -1
  136. rasa/core/channels/inspector/dist/index.html +1 -1
  137. rasa/core/channels/inspector/package.json +18 -18
  138. rasa/core/channels/inspector/src/App.tsx +29 -4
  139. rasa/core/channels/inspector/src/components/DialogueAgentStack.tsx +108 -0
  140. rasa/core/channels/inspector/src/components/{DialogueStack.tsx → DialogueHistoryStack.tsx} +4 -2
  141. rasa/core/channels/inspector/src/helpers/audio/audiostream.ts +7 -4
  142. rasa/core/channels/inspector/src/helpers/formatters.test.ts +4 -0
  143. rasa/core/channels/inspector/src/helpers/formatters.ts +24 -3
  144. rasa/core/channels/inspector/src/helpers/utils.test.ts +127 -0
  145. rasa/core/channels/inspector/src/helpers/utils.ts +66 -1
  146. rasa/core/channels/inspector/src/theme/base/styles.ts +19 -1
  147. rasa/core/channels/inspector/src/types.ts +21 -0
  148. rasa/core/channels/inspector/yarn.lock +336 -189
  149. rasa/core/channels/studio_chat.py +6 -6
  150. rasa/core/channels/telegram.py +4 -9
  151. rasa/core/channels/voice_stream/browser_audio.py +2 -0
  152. rasa/core/channels/voice_stream/genesys.py +1 -1
  153. rasa/core/channels/voice_stream/tts/deepgram.py +140 -0
  154. rasa/core/channels/voice_stream/twilio_media_streams.py +5 -1
  155. rasa/core/channels/voice_stream/voice_channel.py +3 -0
  156. rasa/core/config/__init__.py +0 -0
  157. rasa/core/{available_endpoints.py → config/available_endpoints.py} +51 -16
  158. rasa/core/config/configuration.py +260 -0
  159. rasa/core/config/credentials.py +19 -0
  160. rasa/core/config/message_procesing_config.py +34 -0
  161. rasa/core/constants.py +5 -0
  162. rasa/core/iam_credentials_providers/aws_iam_credentials_providers.py +88 -3
  163. rasa/core/iam_credentials_providers/credentials_provider_protocol.py +2 -1
  164. rasa/core/lock_store.py +6 -4
  165. rasa/core/nlg/generator.py +1 -1
  166. rasa/core/policies/enterprise_search_policy.py +5 -3
  167. rasa/core/policies/flow_policy.py +4 -4
  168. rasa/core/policies/flows/agent_executor.py +632 -0
  169. rasa/core/policies/flows/flow_executor.py +137 -76
  170. rasa/core/policies/flows/mcp_tool_executor.py +298 -0
  171. rasa/core/policies/intentless_policy.py +1 -1
  172. rasa/core/policies/ted_policy.py +20 -12
  173. rasa/core/policies/unexpected_intent_policy.py +6 -0
  174. rasa/core/processor.py +68 -44
  175. rasa/core/redis_connection_factory.py +78 -20
  176. rasa/core/run.py +37 -8
  177. rasa/core/test.py +4 -0
  178. rasa/core/tracker_stores/sql_tracker_store.py +1 -1
  179. rasa/core/tracker_stores/tracker_store.py +3 -7
  180. rasa/core/train.py +1 -1
  181. rasa/core/training/interactive.py +20 -18
  182. rasa/core/training/story_conflict.py +5 -5
  183. rasa/core/utils.py +22 -23
  184. rasa/dialogue_understanding/commands/__init__.py +8 -0
  185. rasa/dialogue_understanding/commands/cancel_flow_command.py +19 -5
  186. rasa/dialogue_understanding/commands/chit_chat_answer_command.py +21 -2
  187. rasa/dialogue_understanding/commands/clarify_command.py +20 -2
  188. rasa/dialogue_understanding/commands/continue_agent_command.py +91 -0
  189. rasa/dialogue_understanding/commands/knowledge_answer_command.py +21 -2
  190. rasa/dialogue_understanding/commands/restart_agent_command.py +162 -0
  191. rasa/dialogue_understanding/commands/start_flow_command.py +68 -7
  192. rasa/dialogue_understanding/commands/utils.py +124 -2
  193. rasa/dialogue_understanding/generator/command_parser.py +4 -0
  194. rasa/dialogue_understanding/generator/llm_based_command_generator.py +50 -12
  195. rasa/dialogue_understanding/generator/llm_command_generator.py +1 -1
  196. rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +1 -1
  197. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_claude_3_5_sonnet_20240620_template.jinja2 +66 -0
  198. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_gpt_4o_2024_11_20_template.jinja2 +66 -0
  199. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_claude_3_5_sonnet_20240620_template.jinja2 +89 -0
  200. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +88 -0
  201. rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +42 -7
  202. rasa/dialogue_understanding/generator/single_step/search_ready_llm_command_generator.py +40 -3
  203. rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +20 -3
  204. rasa/dialogue_understanding/patterns/cancel.py +27 -6
  205. rasa/dialogue_understanding/patterns/clarify.py +3 -14
  206. rasa/dialogue_understanding/patterns/continue_interrupted.py +239 -6
  207. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +46 -8
  208. rasa/dialogue_understanding/processor/command_processor.py +136 -15
  209. rasa/dialogue_understanding/stack/dialogue_stack.py +98 -2
  210. rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +57 -0
  211. rasa/dialogue_understanding/stack/utils.py +57 -3
  212. rasa/dialogue_understanding/utils.py +24 -4
  213. rasa/dialogue_understanding_test/du_test_runner.py +8 -3
  214. rasa/e2e_test/e2e_test_runner.py +13 -3
  215. rasa/engine/caching.py +2 -2
  216. rasa/engine/constants.py +1 -1
  217. rasa/engine/recipes/default_components.py +138 -49
  218. rasa/engine/recipes/default_recipe.py +108 -11
  219. rasa/engine/runner/dask.py +8 -5
  220. rasa/engine/validation.py +19 -6
  221. rasa/graph_components/validators/default_recipe_validator.py +86 -28
  222. rasa/hooks.py +5 -5
  223. rasa/llm_fine_tuning/utils.py +2 -2
  224. rasa/model_training.py +60 -47
  225. rasa/nlu/classifiers/diet_classifier.py +198 -98
  226. rasa/nlu/classifiers/logistic_regression_classifier.py +1 -4
  227. rasa/nlu/classifiers/mitie_intent_classifier.py +3 -0
  228. rasa/nlu/classifiers/sklearn_intent_classifier.py +1 -3
  229. rasa/nlu/extractors/crf_entity_extractor.py +9 -10
  230. rasa/nlu/extractors/mitie_entity_extractor.py +3 -0
  231. rasa/nlu/extractors/spacy_entity_extractor.py +3 -0
  232. rasa/nlu/featurizers/dense_featurizer/convert_featurizer.py +4 -0
  233. rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py +5 -0
  234. rasa/nlu/featurizers/dense_featurizer/mitie_featurizer.py +2 -0
  235. rasa/nlu/featurizers/dense_featurizer/spacy_featurizer.py +3 -0
  236. rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +4 -2
  237. rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +4 -0
  238. rasa/nlu/selectors/response_selector.py +10 -2
  239. rasa/nlu/tokenizers/jieba_tokenizer.py +3 -4
  240. rasa/nlu/tokenizers/mitie_tokenizer.py +3 -2
  241. rasa/nlu/tokenizers/spacy_tokenizer.py +3 -2
  242. rasa/nlu/utils/mitie_utils.py +3 -0
  243. rasa/nlu/utils/spacy_utils.py +3 -2
  244. rasa/plugin.py +8 -8
  245. rasa/privacy/privacy_manager.py +12 -3
  246. rasa/server.py +15 -3
  247. rasa/shared/agents/__init__.py +0 -0
  248. rasa/shared/agents/auth/__init__.py +0 -0
  249. rasa/shared/agents/auth/agent_auth_factory.py +105 -0
  250. rasa/shared/agents/auth/agent_auth_manager.py +92 -0
  251. rasa/shared/agents/auth/auth_strategy/__init__.py +19 -0
  252. rasa/shared/agents/auth/auth_strategy/agent_auth_strategy.py +52 -0
  253. rasa/shared/agents/auth/auth_strategy/api_key_auth_strategy.py +42 -0
  254. rasa/shared/agents/auth/auth_strategy/bearer_token_auth_strategy.py +28 -0
  255. rasa/shared/agents/auth/auth_strategy/oauth2_auth_strategy.py +167 -0
  256. rasa/shared/agents/auth/constants.py +12 -0
  257. rasa/shared/agents/auth/types.py +12 -0
  258. rasa/shared/agents/utils.py +35 -0
  259. rasa/shared/constants.py +8 -0
  260. rasa/shared/core/constants.py +16 -1
  261. rasa/shared/core/domain.py +0 -7
  262. rasa/shared/core/events.py +327 -0
  263. rasa/shared/core/flows/constants.py +5 -0
  264. rasa/shared/core/flows/flow.py +1 -1
  265. rasa/shared/core/flows/flows_list.py +21 -5
  266. rasa/shared/core/flows/flows_yaml_schema.json +119 -184
  267. rasa/shared/core/flows/steps/call.py +49 -5
  268. rasa/shared/core/flows/steps/collect.py +98 -13
  269. rasa/shared/core/flows/validation.py +372 -8
  270. rasa/shared/core/flows/yaml_flows_io.py +3 -2
  271. rasa/shared/core/slots.py +2 -2
  272. rasa/shared/core/trackers.py +5 -2
  273. rasa/shared/exceptions.py +16 -0
  274. rasa/shared/importers/rasa.py +1 -1
  275. rasa/shared/importers/utils.py +9 -3
  276. rasa/shared/providers/llm/_base_litellm_client.py +41 -9
  277. rasa/shared/providers/llm/litellm_router_llm_client.py +8 -4
  278. rasa/shared/providers/llm/llm_client.py +7 -3
  279. rasa/shared/providers/llm/llm_response.py +66 -0
  280. rasa/shared/providers/llm/self_hosted_llm_client.py +8 -4
  281. rasa/shared/utils/common.py +24 -0
  282. rasa/shared/utils/health_check/health_check.py +7 -3
  283. rasa/shared/utils/llm.py +39 -16
  284. rasa/shared/utils/mcp/__init__.py +0 -0
  285. rasa/shared/utils/mcp/server_connection.py +247 -0
  286. rasa/shared/utils/mcp/utils.py +20 -0
  287. rasa/shared/utils/schemas/events.py +42 -0
  288. rasa/shared/utils/yaml.py +3 -1
  289. rasa/studio/pull/pull.py +3 -2
  290. rasa/studio/train.py +8 -7
  291. rasa/studio/upload.py +3 -6
  292. rasa/telemetry.py +69 -5
  293. rasa/tracing/config.py +45 -12
  294. rasa/tracing/constants.py +14 -0
  295. rasa/tracing/instrumentation/attribute_extractors.py +142 -9
  296. rasa/tracing/instrumentation/instrumentation.py +626 -21
  297. rasa/tracing/instrumentation/intentless_policy_instrumentation.py +4 -4
  298. rasa/tracing/instrumentation/metrics.py +32 -0
  299. rasa/tracing/metric_instrument_provider.py +68 -0
  300. rasa/utils/common.py +92 -1
  301. rasa/utils/endpoints.py +11 -2
  302. rasa/utils/log_utils.py +96 -5
  303. rasa/utils/ml_utils.py +1 -1
  304. rasa/utils/pypred.py +38 -0
  305. rasa/utils/tensorflow/__init__.py +7 -0
  306. rasa/utils/tensorflow/callback.py +136 -101
  307. rasa/utils/tensorflow/crf.py +1 -1
  308. rasa/utils/tensorflow/data_generator.py +21 -8
  309. rasa/utils/tensorflow/layers.py +21 -11
  310. rasa/utils/tensorflow/metrics.py +7 -3
  311. rasa/utils/tensorflow/models.py +56 -8
  312. rasa/utils/tensorflow/rasa_layers.py +8 -6
  313. rasa/utils/tensorflow/transformer.py +2 -3
  314. rasa/utils/train_utils.py +54 -24
  315. rasa/validator.py +17 -13
  316. rasa/version.py +1 -1
  317. {rasa_pro-3.14.0a22.dist-info → rasa_pro-3.14.0a23.dist-info}/METADATA +48 -42
  318. {rasa_pro-3.14.0a22.dist-info → rasa_pro-3.14.0a23.dist-info}/RECORD +321 -249
  319. rasa/builder/scrape_rasa_docs.py +0 -97
  320. rasa/cli/project_templates/finance/data/general/agent_details.yml +0 -6
  321. rasa/cli/project_templates/finance/domain/_system/patterns/pattern_session_start.yml +0 -11
  322. rasa/cli/project_templates/finance/domain/general/agent_details.yml +0 -31
  323. rasa/core/channels/inspector/dist/assets/channel-8e08bed9.js +0 -1
  324. rasa/core/channels/inspector/dist/assets/clone-78c82dea.js +0 -1
  325. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-96b9c2cf-2b08f601.js +0 -1
  326. rasa/core/channels/inspector/dist/assets/index-c941dcb3.js +0 -1336
  327. {rasa_pro-3.14.0a22.dist-info → rasa_pro-3.14.0a23.dist-info}/NOTICE +0 -0
  328. {rasa_pro-3.14.0a22.dist-info → rasa_pro-3.14.0a23.dist-info}/WHEEL +0 -0
  329. {rasa_pro-3.14.0a22.dist-info → rasa_pro-3.14.0a23.dist-info}/entry_points.txt +0 -0
@@ -12,7 +12,11 @@ from rasa.dialogue_understanding.commands.free_form_answer_command import (
12
12
  FreeFormAnswerCommand,
13
13
  )
14
14
  from rasa.dialogue_understanding.patterns.search import SearchPatternFlowStackFrame
15
- from rasa.shared.core.events import Event
15
+ from rasa.dialogue_understanding.stack.frames.flow_stack_frame import (
16
+ AgentStackFrame,
17
+ AgentState,
18
+ )
19
+ from rasa.shared.core.events import AgentInterrupted, Event
16
20
  from rasa.shared.core.flows import FlowsList
17
21
  from rasa.shared.core.trackers import DialogueStateTracker
18
22
 
@@ -52,8 +56,23 @@ class KnowledgeAnswerCommand(FreeFormAnswerCommand):
52
56
  The events to apply to the tracker.
53
57
  """
54
58
  stack = tracker.stack
59
+
60
+ applied_events: List[Event] = []
61
+
62
+ # if the top stack frame is an agent stack frame, we need to
63
+ # update the state to INTERRUPTED and add an AgentInterrupted event
64
+ if top_stack_frame := stack.top():
65
+ if isinstance(top_stack_frame, AgentStackFrame):
66
+ applied_events.append(
67
+ AgentInterrupted(
68
+ top_stack_frame.agent_id,
69
+ top_stack_frame.flow_id,
70
+ )
71
+ )
72
+ top_stack_frame.state = AgentState.INTERRUPTED
73
+
55
74
  stack.push(SearchPatternFlowStackFrame())
56
- return tracker.create_stack_updated_events(stack)
75
+ return applied_events + tracker.create_stack_updated_events(stack)
57
76
 
58
77
  def __hash__(self) -> int:
59
78
  return hash(self.command())
@@ -0,0 +1,162 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from dataclasses import dataclass
5
+ from typing import Any, Dict, List, Optional
6
+
7
+ from rasa.dialogue_understanding.commands.command import Command
8
+ from rasa.dialogue_understanding.commands.command_syntax_manager import (
9
+ CommandSyntaxManager,
10
+ CommandSyntaxVersion,
11
+ )
12
+ from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
13
+ from rasa.dialogue_understanding.stack.frames.flow_stack_frame import (
14
+ AgentStackFrame,
15
+ AgentState,
16
+ )
17
+ from rasa.shared.core.events import AgentStarted, Event
18
+ from rasa.shared.core.flows import FlowsList
19
+ from rasa.shared.core.flows.steps import CallFlowStep
20
+ from rasa.shared.core.trackers import DialogueStateTracker
21
+
22
+
23
+ @dataclass
24
+ class RestartAgentCommand(Command):
25
+ """A command to restart an agentic loop within a flow."""
26
+
27
+ agent_id: str
28
+
29
+ @classmethod
30
+ def command(cls) -> str:
31
+ """Returns the command type."""
32
+ return "restart agent"
33
+
34
+ @classmethod
35
+ def from_dict(cls, data: Dict[str, Any]) -> RestartAgentCommand:
36
+ """Converts the dictionary to a command.
37
+
38
+ Returns:
39
+ The converted dictionary.
40
+ """
41
+ try:
42
+ return RestartAgentCommand(agent_id=data["agent_id"])
43
+ except KeyError as e:
44
+ raise ValueError(
45
+ f"Missing parameter '{e}' while parsing RestartAgentCommand."
46
+ ) from e
47
+
48
+ def run_command_on_tracker(
49
+ self,
50
+ tracker: DialogueStateTracker,
51
+ all_flows: FlowsList,
52
+ original_tracker: DialogueStateTracker,
53
+ ) -> List[Event]:
54
+ """Runs the command on the tracker.
55
+
56
+ Args:
57
+ tracker: The tracker to run the command on.
58
+ all_flows: All flows in the assistant.
59
+ original_tracker: The tracker before any command was executed.
60
+
61
+ Returns:
62
+ The events to apply to the tracker.
63
+ """
64
+ stack = tracker.stack
65
+
66
+ # get the agent flow
67
+ agent_flow_id = self._get_agent_flow(original_tracker)
68
+
69
+ # create a new agent stack frame to restart the agent
70
+ restart_agent_frame = self.create_restart_agent_stack_frame(
71
+ all_flows, agent_flow_id
72
+ )
73
+
74
+ # if the stack contains an agent stack frame with status
75
+ # "waiting for input" update the status to "interrupted"
76
+ self.update_agent_stack_frames_on_stack(stack)
77
+
78
+ # push the stack frame on the top of the stack
79
+ stack.push(restart_agent_frame)
80
+ return tracker.create_stack_updated_events(stack)
81
+
82
+ def __hash__(self) -> int:
83
+ return hash(self.command())
84
+
85
+ def __eq__(self, other: object) -> bool:
86
+ return isinstance(other, RestartAgentCommand)
87
+
88
+ def to_dsl(self) -> str:
89
+ """Converts the command to a DSL string."""
90
+ mapper = {
91
+ CommandSyntaxVersion.v1: f"RestartAgent({self.agent_id})",
92
+ CommandSyntaxVersion.v2: f"restart agent {self.agent_id}",
93
+ CommandSyntaxVersion.v3: f"restart agent {self.agent_id}",
94
+ }
95
+ return mapper.get(
96
+ CommandSyntaxManager.get_syntax_version(),
97
+ mapper[CommandSyntaxManager.get_default_syntax_version()],
98
+ )
99
+
100
+ @classmethod
101
+ def from_dsl(cls, match: re.Match, **kwargs: Any) -> RestartAgentCommand:
102
+ """Converts a DSL string to a command."""
103
+ return RestartAgentCommand(agent_id=str(match.group(1).strip()))
104
+
105
+ @staticmethod
106
+ def regex_pattern() -> str:
107
+ mapper = {
108
+ CommandSyntaxVersion.v1: r"RestartAgent\(['\"]?([a-zA-Z0-9_-]+)['\"]?\)",
109
+ CommandSyntaxVersion.v2: (
110
+ r"""^[\s\W\d]*restart agent ['"`]?([a-zA-Z0-9_-]+)['"`]*"""
111
+ ),
112
+ CommandSyntaxVersion.v3: (
113
+ r"""^[\s\W\d]*restart agent ['"`]?([a-zA-Z0-9_-]+)['"`]*"""
114
+ ),
115
+ }
116
+ return mapper.get(
117
+ CommandSyntaxManager.get_syntax_version(),
118
+ mapper[CommandSyntaxManager.get_default_syntax_version()],
119
+ )
120
+
121
+ def create_restart_agent_stack_frame(
122
+ self, all_flows: FlowsList, agent_flow_id: str
123
+ ) -> AgentStackFrame:
124
+ # get the agent flow
125
+ agent_flow = all_flows.flow_by_id(agent_flow_id)
126
+ if not agent_flow:
127
+ raise ValueError(f"Agent flow {agent_flow_id} not found")
128
+
129
+ # find the call flow step for the agent
130
+ # set the state to "waiting for input" so that the agent can process
131
+ # the latest user message
132
+ for step in agent_flow.steps:
133
+ if isinstance(step, CallFlowStep) and step.call == self.agent_id:
134
+ return AgentStackFrame(
135
+ frame_id=f"restart_agent_{self.agent_id}",
136
+ flow_id=agent_flow_id,
137
+ step_id=step.id,
138
+ agent_id=self.agent_id,
139
+ state=AgentState.WAITING_FOR_INPUT,
140
+ )
141
+
142
+ raise ValueError(f"Call step in agent flow {agent_flow_id} not found")
143
+
144
+ def update_agent_stack_frames_on_stack(self, stack: DialogueStack) -> None:
145
+ for frame in stack.frames:
146
+ if (
147
+ isinstance(frame, AgentStackFrame)
148
+ and frame.state == AgentState.WAITING_FOR_INPUT
149
+ ):
150
+ frame.state = AgentState.INTERRUPTED
151
+
152
+ def _get_agent_flow(self, tracker: DialogueStateTracker) -> Optional[str]:
153
+ # find events associated with the agent
154
+ agent_started_events = [
155
+ event
156
+ for event in tracker.events
157
+ if type(event) == AgentStarted and event.agent_id == self.agent_id
158
+ ]
159
+ # take the last one if the agent was started multiple times
160
+ if agent_started_events:
161
+ return agent_started_events[-1].flow_id
162
+ return None
@@ -11,15 +11,25 @@ from rasa.dialogue_understanding.commands.command_syntax_manager import (
11
11
  CommandSyntaxManager,
12
12
  CommandSyntaxVersion,
13
13
  )
14
+ from rasa.dialogue_understanding.commands.utils import (
15
+ remove_pattern_continue_interrupted_frames,
16
+ resume_flow,
17
+ )
14
18
  from rasa.dialogue_understanding.stack.frames.flow_stack_frame import (
19
+ AgentState,
15
20
  FlowStackFrameType,
16
21
  UserFlowStackFrame,
17
22
  )
18
23
  from rasa.dialogue_understanding.stack.utils import (
24
+ is_continue_interrupted_flow_active,
19
25
  top_user_flow_frame,
20
26
  user_flows_on_the_stack,
21
27
  )
22
- from rasa.shared.core.events import Event, FlowInterrupted
28
+ from rasa.shared.core.events import (
29
+ AgentInterrupted,
30
+ Event,
31
+ FlowInterrupted,
32
+ )
23
33
  from rasa.shared.core.flows import FlowsList
24
34
  from rasa.shared.core.trackers import DialogueStateTracker
25
35
 
@@ -71,12 +81,7 @@ class StartFlowCommand(Command):
71
81
  original_stack = original_tracker.stack
72
82
  applied_events: List[Event] = []
73
83
 
74
- if self.flow in user_flows_on_the_stack(stack):
75
- structlogger.debug(
76
- "start_flow_command.skip_command.already_started_flow", command=self
77
- )
78
- return []
79
- elif self.flow not in all_flows.flow_ids:
84
+ if self.flow not in all_flows.flow_ids:
80
85
  structlogger.debug(
81
86
  "start_flow_command.skip_command.start_invalid_flow_id", command=self
82
87
  )
@@ -87,9 +92,47 @@ class StartFlowCommand(Command):
87
92
  original_user_frame.flow(all_flows) if original_user_frame else None
88
93
  )
89
94
 
95
+ # if the original top flow is the same as the flow to start, the flow is
96
+ # already active, do nothing
97
+ if original_top_flow is not None and original_top_flow.id == self.flow:
98
+ # in case continue_interrupted is not active, skip the already active start
99
+ # flow command
100
+ if not is_continue_interrupted_flow_active(stack):
101
+ return []
102
+
103
+ # if the continue interrupted flow is active, and the command generator
104
+ # predicted a start flow command for the flow which is on top of the stack,
105
+ # we just need to remove the pattern_continue_interrupted frame(s) from the
106
+ # stack
107
+ stack = remove_pattern_continue_interrupted_frames(stack)
108
+ return applied_events + tracker.create_stack_updated_events(stack)
109
+
110
+ # if the flow is already on the stack, resume it
111
+ if (
112
+ self.flow in user_flows_on_the_stack(stack)
113
+ and original_user_frame is not None
114
+ ):
115
+ # if pattern_continue_interrupted is active, we need to remove it
116
+ # from the stack before resuming the flow
117
+ stack = remove_pattern_continue_interrupted_frames(stack)
118
+ applied_events.extend(resume_flow(self.flow, tracker, stack))
119
+ # the current active flow is interrupted
120
+ applied_events.append(
121
+ FlowInterrupted(
122
+ original_user_frame.flow_id, original_user_frame.step_id
123
+ )
124
+ )
125
+ return applied_events
126
+
90
127
  frame_type = FlowStackFrameType.REGULAR
91
128
 
129
+ # remove the pattern_continue_interrupted frames from the stack
130
+ # if it is currently active but the user digressed from the pattern
131
+ stack = remove_pattern_continue_interrupted_frames(stack)
132
+
92
133
  if original_top_flow:
134
+ # if the original top flow is not the same as the flow to start,
135
+ # interrupt the current active flow
93
136
  frame_type = FlowStackFrameType.INTERRUPT
94
137
 
95
138
  if original_user_frame is not None:
@@ -99,6 +142,24 @@ class StartFlowCommand(Command):
99
142
  )
100
143
  )
101
144
 
145
+ # If there is an active agent frame, interrupt it
146
+ active_agent_stack_frame = stack.find_active_agent_frame()
147
+ if active_agent_stack_frame:
148
+ structlogger.debug(
149
+ "start_flow_command.interrupt_agent",
150
+ command=self,
151
+ agent_id=active_agent_stack_frame.agent_id,
152
+ frame_id=active_agent_stack_frame.frame_id,
153
+ flow_id=active_agent_stack_frame.flow_id,
154
+ )
155
+ active_agent_stack_frame.state = AgentState.INTERRUPTED
156
+ applied_events.append(
157
+ AgentInterrupted(
158
+ active_agent_stack_frame.agent_id,
159
+ active_agent_stack_frame.flow_id,
160
+ )
161
+ )
162
+
102
163
  structlogger.debug("start_flow_command.start_flow", command=self)
103
164
  stack.push(UserFlowStackFrame(flow_id=self.flow, frame_type=frame_type))
104
165
  return applied_events + tracker.create_stack_updated_events(stack)
@@ -5,8 +5,23 @@ import structlog
5
5
  from rasa.dialogue_understanding.patterns.validate_slot import (
6
6
  ValidateSlotPatternFlowStackFrame,
7
7
  )
8
+ from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
9
+ from rasa.dialogue_understanding.stack.frames.dialogue_stack_frame import (
10
+ DialogueStackFrame,
11
+ )
12
+ from rasa.dialogue_understanding.stack.frames.flow_stack_frame import (
13
+ AgentStackFrame,
14
+ FlowStackFrameType,
15
+ UserFlowStackFrame,
16
+ )
17
+ from rasa.dialogue_understanding.stack.frames.pattern_frame import PatternFlowStackFrame
8
18
  from rasa.shared.constants import ACTION_ASK_PREFIX, UTTER_ASK_PREFIX
9
- from rasa.shared.core.events import Event, SlotSet
19
+ from rasa.shared.core.events import (
20
+ AgentResumed,
21
+ Event,
22
+ FlowResumed,
23
+ SlotSet,
24
+ )
10
25
  from rasa.shared.core.flows import FlowsList
11
26
  from rasa.shared.core.slots import Slot
12
27
  from rasa.shared.core.trackers import DialogueStateTracker
@@ -103,7 +118,8 @@ def create_validate_frames_from_slot_set_events(
103
118
  Args:
104
119
  tracker: The dialogue state tracker.
105
120
  events: List of events to process.
106
- should_break: whether or not to break after the first non-SlotSet event.
121
+ validate_frames: List to collect validation frames.
122
+ should_break: whether to break after the first non-SlotSet event.
107
123
  if True, break out of the event loop as soon as the first non-SlotSet
108
124
  event is encountered.
109
125
  if False, continue processing the events until the end.
@@ -150,3 +166,109 @@ def find_default_flows_collecting_slot(
150
166
  for step in flow.get_collect_steps()
151
167
  )
152
168
  ]
169
+
170
+
171
+ def resume_flow(
172
+ flow_to_resume: str,
173
+ tracker: DialogueStateTracker,
174
+ stack: DialogueStack,
175
+ ) -> List[Event]:
176
+ """Resumes a flow by reordering frames."""
177
+ applied_events: List[Event] = []
178
+
179
+ # Resume existing flow by reordering frames
180
+ frames_to_resume, user_frame_to_resume = collect_frames_to_resume(
181
+ stack, flow_to_resume
182
+ )
183
+
184
+ # if the flow is not on the stack, do nothing
185
+ # this should not happen, but just in case
186
+ if user_frame_to_resume is None:
187
+ structlogger.error(
188
+ "resume_flow.no_user_frame_to_resume",
189
+ flow_to_resume=flow_to_resume,
190
+ )
191
+ return []
192
+
193
+ # move the frames to the top of the stack, e.g. reorder the frames
194
+ # on the stack
195
+ stack.move_frames_to_top(frames_to_resume)
196
+
197
+ # create agent resumed events if the agent frame is now on top of the stack
198
+ agent_stack_frame = next(
199
+ (frame for frame in frames_to_resume if isinstance(frame, AgentStackFrame)),
200
+ None,
201
+ )
202
+ if agent_stack_frame:
203
+ agent_id = agent_stack_frame.agent_id
204
+ applied_events.append(AgentResumed(agent_id, agent_stack_frame.flow_id))
205
+
206
+ # Create flow interruption and resumption events
207
+ applied_events.extend(
208
+ [
209
+ # the flow, which was on the stack, is resumed
210
+ FlowResumed(user_frame_to_resume.flow_id, user_frame_to_resume.step_id),
211
+ ]
212
+ )
213
+
214
+ return applied_events + tracker.create_stack_updated_events(stack)
215
+
216
+
217
+ def collect_frames_to_resume(
218
+ stack: DialogueStack,
219
+ target_flow_id: str, # pyright: ignore[reportUndefinedVariable]
220
+ ) -> Tuple[List[DialogueStackFrame], Optional[UserFlowStackFrame]]:
221
+ """Collect frames that need to be resumed for the target flow.
222
+
223
+ Args:
224
+ stack: The stack to collect frames from.
225
+ target_flow_id: The ID of the flow to resume.
226
+
227
+ Returns:
228
+ A tuple containing (frames_to_resume, frame_to_resume).
229
+ """
230
+ frames_to_resume: List[DialogueStackFrame] = []
231
+ frame_found = False
232
+ frame_to_resume = None
233
+
234
+ for frame in stack.frames:
235
+ if isinstance(frame, UserFlowStackFrame) and (
236
+ frame.frame_type == FlowStackFrameType.REGULAR
237
+ or frame.frame_type == FlowStackFrameType.INTERRUPT
238
+ ):
239
+ if frame.flow_id == target_flow_id:
240
+ frames_to_resume.append(frame)
241
+ frame_to_resume = frame
242
+ frame_found = True
243
+ continue
244
+ elif frame_found:
245
+ break
246
+
247
+ if frame_found:
248
+ frames_to_resume.append(frame)
249
+
250
+ return list(frames_to_resume), frame_to_resume
251
+
252
+
253
+ def remove_pattern_continue_interrupted_frames(stack: DialogueStack) -> DialogueStack:
254
+ """Remove pattern_continue_interrupted frames from the stack."""
255
+ from rasa.dialogue_understanding.stack.utils import (
256
+ is_continue_interrupted_flow_active,
257
+ )
258
+
259
+ if not is_continue_interrupted_flow_active(stack):
260
+ return stack
261
+
262
+ # remove pattern_continue_interrupted from the stack
263
+ top_frame = stack.top()
264
+ while isinstance(top_frame, PatternFlowStackFrame):
265
+ # If the top frame is a pattern frame, we need to remove it
266
+ # before continuing with the active user flow frame.
267
+ # This prevents the pattern frame
268
+ # from being left on the stack when the flow is started
269
+ # which would prevent pattern_completed to be triggered
270
+ # once the user flow is completed.
271
+ stack.pop()
272
+ top_frame = stack.top()
273
+
274
+ return stack
@@ -9,9 +9,11 @@ from rasa.dialogue_understanding.commands import (
9
9
  ChitChatAnswerCommand,
10
10
  ClarifyCommand,
11
11
  Command,
12
+ ContinueAgentCommand,
12
13
  HumanHandoffCommand,
13
14
  KnowledgeAnswerCommand,
14
15
  RepeatBotMessagesCommand,
16
+ RestartAgentCommand,
15
17
  SetSlotCommand,
16
18
  SkipQuestionCommand,
17
19
  StartFlowCommand,
@@ -34,6 +36,8 @@ DEFAULT_COMMANDS = [
34
36
  HumanHandoffCommand,
35
37
  ClarifyCommand,
36
38
  RepeatBotMessagesCommand,
39
+ ContinueAgentCommand,
40
+ RestartAgentCommand,
37
41
  ]
38
42
 
39
43
 
@@ -7,6 +7,7 @@ from jinja2 import Environment, Template, select_autoescape
7
7
 
8
8
  import rasa.dialogue_understanding.generator.utils
9
9
  import rasa.shared.utils.io
10
+ from rasa.core.available_agents import AvailableAgents
10
11
  from rasa.dialogue_understanding.commands import (
11
12
  Command,
12
13
  SetSlotCommand,
@@ -31,6 +32,7 @@ from rasa.engine.storage.resource import Resource
31
32
  from rasa.engine.storage.storage import ModelStorage
32
33
  from rasa.shared.core.constants import SetSlotExtractor
33
34
  from rasa.shared.core.domain import Domain
35
+ from rasa.shared.core.events import AgentStarted
34
36
  from rasa.shared.core.flows import Flow, FlowsList, FlowStep
35
37
  from rasa.shared.core.flows.steps.collect import CollectInformationFlowStep
36
38
  from rasa.shared.core.slot_mappings import SlotFillingManager
@@ -225,8 +227,7 @@ class LLMBasedCommandGenerator(
225
227
 
226
228
  @lru_cache
227
229
  def compile_template(self, template: str) -> Template:
228
- """
229
- Compile the prompt template and register custom filters.
230
+ """Compile the prompt template and register custom filters.
230
231
 
231
232
  Compiling the template is an expensive operation,
232
233
  so we cache the result.
@@ -361,20 +362,24 @@ class LLMBasedCommandGenerator(
361
362
  )
362
363
 
363
364
  def prepare_flows_for_template(
364
- self, flows: FlowsList, tracker: DialogueStateTracker
365
+ self,
366
+ flows: FlowsList,
367
+ tracker: DialogueStateTracker,
368
+ add_agent_info: bool = False,
365
369
  ) -> List[Dict[str, Any]]:
366
370
  """Format data on available flows for insertion into the prompt template.
367
371
 
368
372
  Args:
369
373
  flows: The flows available to the user.
370
374
  tracker: The tracker containing the current state of the conversation.
375
+ add_agent_info: Whether to add agent info to flows or not.
371
376
 
372
377
  Returns:
373
378
  The inputs for the prompt template.
374
379
  """
375
- result = []
380
+ result: List[Dict[str, Any]] = []
376
381
  for flow in flows.user_flows:
377
- slots_with_info = [
382
+ slots_with_info: List[Dict[str, Any]] = [
378
383
  {
379
384
  "name": q.collect,
380
385
  "description": q.description,
@@ -383,13 +388,46 @@ class LLMBasedCommandGenerator(
383
388
  for q in flow.get_collect_steps()
384
389
  if self.is_extractable(q, tracker)
385
390
  ]
386
- result.append(
387
- {
388
- "name": flow.id,
389
- "description": flow.description,
390
- "slots": slots_with_info,
391
- }
392
- )
391
+
392
+ agent_info: List[Dict[str, Any]] = []
393
+ if add_agent_info:
394
+ # add information about agents that have been started for this flow
395
+ agent_events = [
396
+ event
397
+ for event in tracker.events
398
+ if isinstance(event, AgentStarted) and event.flow_id == flow.id
399
+ ]
400
+ available_agents = [
401
+ AvailableAgents.get_agent_config(event.agent_id)
402
+ for event in agent_events
403
+ ]
404
+ if available_agents:
405
+ agent_info = [
406
+ {
407
+ "name": available_agent.agent.name,
408
+ "description": available_agent.agent.description,
409
+ }
410
+ for available_agent in available_agents
411
+ if available_agent is not None
412
+ ]
413
+
414
+ if agent_info:
415
+ result.append(
416
+ {
417
+ "name": flow.id,
418
+ "description": flow.description,
419
+ "slots": slots_with_info,
420
+ "agent_info": agent_info,
421
+ }
422
+ )
423
+ else:
424
+ result.append(
425
+ {
426
+ "name": flow.id,
427
+ "description": flow.description,
428
+ "slots": slots_with_info,
429
+ }
430
+ )
393
431
  return result
394
432
 
395
433
  @staticmethod
@@ -1,7 +1,7 @@
1
1
  from typing import Any, Dict, List, Optional, Text, Union
2
2
 
3
3
  import structlog
4
- from deprecated import deprecated # type: ignore[import]
4
+ from deprecated import deprecated # type: ignore[import-untyped]
5
5
 
6
6
  from rasa.dialogue_understanding.generator.single_step.single_step_llm_command_generator import ( # noqa: E501
7
7
  SingleStepLLMCommandGenerator,
@@ -2,7 +2,7 @@ import importlib.resources
2
2
  from typing import Any, Dict, List, Optional, Text, Tuple, Union
3
3
 
4
4
  import structlog
5
- from deprecated import deprecated # type: ignore[import]
5
+ from deprecated import deprecated # type: ignore[import-untyped]
6
6
  from jinja2 import Template
7
7
 
8
8
  import rasa.shared.utils.io
@@ -0,0 +1,66 @@
1
+ ## Task Description
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.
3
+
4
+ --
5
+
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. ONLY use slots that are explicitly defined in the flow's slot list.
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, `disambiguate 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
+ * `repeat message`: Repeating the last bot message.{% if active_agent %}
15
+ * `continue agent`: Continue the currently active agent {{ active_agent.name }}. This has HIGHEST PRIORITY when an agent is active and the user is responding to agent questions.{% endif %}{% if completed_agents %}
16
+ * `restart agent agent_name`: Restart the agent with the given name, in case the user wants to change some answer to a previous question asked by the agent. For example, `restart agent car_research_agent` if the user changed his mind about the car he wants to buy. ONLY use agents that are listed in the `completed_agents` section.{% endif %}
17
+
18
+ --
19
+
20
+ ## General Tips
21
+ * Do not fill slots with abstract values or placeholders.
22
+ * For categorical slots try to match the user message with allowed slot values. Use "other" if you cannot match it.
23
+ * Set the boolean slots based on the user response. Map positive responses to `True`, and negative to `False`.
24
+ * Always refer to the slot description to determine what information should be extracted and how it should be formatted.
25
+ * For text slots, extract values exactly as provided by the user unless the slot description specifies otherwise. Preserve formatting and avoid rewording, truncation, or making assumptions.
26
+ * ONLY use `set slot` with slots that are explicitly defined in the current flow's slot list. Do NOT create or assume slots that don't exist.
27
+ * Only use information provided by the user.
28
+ * Use clarification in ambiguous cases.
29
+ * Multiple flows can be started. If a user wants to digress into a second flow, you do not need to cancel the current flow.
30
+ * Do not cancel the flow unless the user explicitly requests it.
31
+ * Strictly adhere to the provided action format.
32
+ * ONLY use the exact actions listed above. Do NOT invent new actions like "respond <message>" or any other variations.
33
+ * Focus on the last message and take it one step at a time.
34
+ * Use the previous conversation steps only to aid understanding.{% if active_agent %}
35
+ * When an agent is active, ALWAYS prioritize `continue agent` over `provide info` or `offtopic reply` unless the user is clearly asking something unrelated to the agent's task.{% endif %}{% if completed_agents %}
36
+ * ONLY use `restart agent` with agents that are listed in the `completed_agents` section. Do NOT restart non-existent agents.{% endif %}{% if active_agent or completed_agents %}
37
+ * If you're unsure about agent names, refer to the structured data provided in the `Current State` section.{% endif %}
38
+
39
+ --
40
+
41
+ ## Available Flows and Slots
42
+ Use the following structured data:
43
+ ```json
44
+ {"flows":[{% for flow in available_flows %}{"name":"{{ flow.name }}","description":{{ flow.description | to_json_escaped_string }}{% if flow.agent_info %},"sub-agents":[{% for agent in flow.agent_info %}{"name":"{{ agent.name }}","description":{{ agent.description | to_json_escaped_string }}}{% if not loop.last %},{% endif %}{% endfor %}]{% endif %}{% if flow.slots %},"slots":[{% for slot in flow.slots %}{"name":"{{ slot.name }}"{% if slot.description %},"description":{{ slot.description | to_json_escaped_string }}{% endif %}{% if slot.allowed_values %},"allowed_values":{{ slot.allowed_values }}{% endif %}}{% if not loop.last %},{% endif %}{% endfor %}]{% endif %}}{% if not loop.last %},{% endif %}{% endfor %}]}
45
+ ```
46
+
47
+ --
48
+
49
+ ## Current State
50
+ {% if current_flow != None %}Use the following structured data:
51
+ ```json
52
+ {"active_flow":{"name":"{{ current_flow }}","current_step":{"requested_slot":"{{ current_slot }}","requested_slot_description":{{ current_slot_description | to_json_escaped_string }}},"slots":[{% for slot in flow_slots %}{"name":"{{ slot.name }}","value":"{{ slot.value }}","type":"{{ slot.type }}"{% if slot.description %},"description":{{ slot.description | to_json_escaped_string }}{% endif %}{% if slot.allowed_values %},"allowed_values":"{{ slot.allowed_values }}"{% endif %}}{% if not loop.last %},{% endif %}{% endfor %}]}{% if active_agent %},"active_agent":{"name":"{{ active_agent.name }}","description":{{ active_agent.description | to_json_escaped_string }}}{% endif %}{% if completed_agents %},"completed_agents":[{% for agent in completed_agents %}{"name":"{{ agent.name }}","description":{{ agent.description | to_json_escaped_string }}}{% if not loop.last %},{% endif %}{% endfor %}]{% endif %}}
53
+ ```{% else %}
54
+ You are currently not inside any flow.{% endif %}
55
+
56
+ ---
57
+
58
+ ## Conversation History
59
+ {{ current_conversation }}
60
+
61
+ ---
62
+
63
+ ## Task
64
+ Create an action list with one action per line in response to the user's last message: """{{ user_message }}""".
65
+
66
+ Your action list: