rasa-pro 3.14.0.dev9__py3-none-any.whl → 3.14.0.dev11__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 (298) hide show
  1. rasa/__main__.py +15 -3
  2. rasa/agents/agent_factory.py +2 -2
  3. rasa/agents/agent_manager.py +50 -2
  4. rasa/agents/constants.py +3 -0
  5. rasa/agents/core/types.py +11 -0
  6. rasa/agents/protocol/a2a/a2a_agent.py +76 -17
  7. rasa/agents/protocol/mcp/mcp_base_agent.py +29 -5
  8. rasa/agents/protocol/mcp/mcp_open_agent.py +27 -13
  9. rasa/agents/protocol/mcp/mcp_task_agent.py +46 -31
  10. rasa/agents/schemas/__init__.py +2 -1
  11. rasa/agents/schemas/agent_tool_result.py +0 -2
  12. rasa/agents/schemas/agent_tool_schema.py +55 -3
  13. rasa/agents/templates/mcp_open_agent_prompt_template.jinja2 +6 -1
  14. rasa/agents/templates/mcp_task_agent_prompt_template.jinja2 +5 -0
  15. rasa/agents/utils.py +42 -3
  16. rasa/agents/validation.py +4 -4
  17. rasa/builder/copilot/telemetry.py +35 -19
  18. rasa/builder/main.py +5 -14
  19. rasa/builder/project_generator.py +1 -1
  20. rasa/builder/service.py +5 -0
  21. rasa/builder/template_cache.py +9 -184
  22. rasa/cli/project_templates/basic/data/data.md +5 -6
  23. rasa/cli/project_templates/basic/domain/domain.md +5 -2
  24. rasa/cli/project_templates/finance/README.md +8 -7
  25. rasa/cli/project_templates/finance/actions/__init__.py +0 -46
  26. rasa/cli/project_templates/finance/actions/accounts/check_balance.py +18 -0
  27. rasa/cli/project_templates/finance/actions/{transfers/action_process_immediate_payment.py → cards/check_that_card_exists.py} +6 -3
  28. rasa/cli/project_templates/finance/actions/cards/list_cards.py +22 -0
  29. rasa/cli/project_templates/finance/actions/contacts/__init__.py +0 -0
  30. rasa/cli/project_templates/finance/actions/contacts/add_contact.py +30 -0
  31. rasa/cli/project_templates/finance/actions/contacts/list_contacts.py +22 -0
  32. rasa/cli/project_templates/finance/actions/contacts/remove_contact.py +35 -0
  33. rasa/cli/project_templates/finance/actions/db.py +117 -0
  34. rasa/cli/project_templates/finance/actions/transfers/check_transfer_funds.py +27 -0
  35. rasa/cli/project_templates/finance/actions/transfers/check_transfer_limit.py +36 -0
  36. rasa/cli/project_templates/finance/actions/transfers/execute_recurrent_payment.py +20 -0
  37. rasa/cli/project_templates/finance/actions/transfers/execute_transfer.py +45 -0
  38. rasa/cli/project_templates/finance/actions/transfers/list_transactions.py +32 -0
  39. rasa/cli/project_templates/finance/config.yml +6 -0
  40. rasa/cli/project_templates/finance/credentials.yml +7 -6
  41. rasa/cli/project_templates/finance/data/accounts/check_balance.yml +3 -4
  42. rasa/cli/project_templates/finance/data/accounts/download_statements.yml +26 -0
  43. rasa/cli/project_templates/finance/data/bills/bill_pay_reminder.yml +25 -0
  44. rasa/cli/project_templates/finance/data/cards/activate_card.yml +35 -0
  45. rasa/cli/project_templates/finance/data/cards/block_card.yml +37 -58
  46. rasa/cli/project_templates/finance/data/cards/list_cards.yml +14 -0
  47. rasa/cli/project_templates/finance/data/cards/replace_card.yml +16 -0
  48. rasa/cli/project_templates/finance/data/cards/replace_eligible_card.yml +29 -0
  49. rasa/cli/project_templates/finance/data/contacts/add_contact.yml +33 -0
  50. rasa/cli/project_templates/finance/data/contacts/list_contacts.yml +14 -0
  51. rasa/cli/project_templates/finance/data/contacts/remove_contact.yml +31 -0
  52. rasa/cli/project_templates/finance/data/data.md +6 -3
  53. rasa/cli/project_templates/finance/data/general/agent_details.yml +6 -0
  54. rasa/cli/project_templates/finance/data/general/hello.yml +1 -2
  55. rasa/cli/project_templates/finance/data/general/human_handoff.yml +1 -1
  56. rasa/cli/project_templates/finance/data/transfers/check_transfer_limit.yml +18 -0
  57. rasa/cli/project_templates/finance/data/transfers/list_transactions.yml +46 -0
  58. rasa/cli/project_templates/finance/data/transfers/move_money_between_accounts.yml +51 -0
  59. rasa/cli/project_templates/finance/data/transfers/transfer_money.yml +29 -62
  60. rasa/cli/project_templates/finance/data/transfers/transfer_money_to_a_third_party.yml +175 -0
  61. rasa/cli/project_templates/finance/db/cards.json +18 -0
  62. rasa/cli/project_templates/finance/db/contacts.json +10 -0
  63. rasa/cli/project_templates/finance/db/my_account.json +6 -0
  64. rasa/cli/project_templates/finance/db/transactions.json +22 -0
  65. rasa/cli/project_templates/finance/docs/docs.md +8 -0
  66. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/account_features/budgeting_analytics.txt +22 -0
  67. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/account_features/multi_currency_accounts.txt +19 -0
  68. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/account_features/premium_benefits.txt +19 -0
  69. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/card_management/contactless_limits.txt +16 -0
  70. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/card_management/freeze_unfreeze_card.txt +16 -0
  71. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/card_management/lost_stolen_card.txt +19 -0
  72. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/money_transfers/instant_payments.txt +19 -0
  73. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/money_transfers/international_transfers.txt +19 -0
  74. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/security_fraud/fraud_protection.txt +22 -0
  75. rasa/cli/project_templates/finance/docs/fenlo_banking_faq/security_fraud/secure_payments.txt +22 -0
  76. rasa/cli/project_templates/finance/domain/_system/patterns/pattern_session_start.yml +11 -0
  77. rasa/cli/project_templates/finance/domain/accounts/check_balance.yml +9 -5
  78. rasa/cli/project_templates/finance/domain/accounts/download_statements.yml +40 -0
  79. rasa/cli/project_templates/finance/domain/bills/bill_pay_reminder.yml +49 -0
  80. rasa/cli/project_templates/finance/domain/cards/activate_card.yml +24 -0
  81. rasa/cli/project_templates/finance/domain/cards/block_card.yml +33 -90
  82. rasa/cli/project_templates/finance/domain/cards/list_cards.yml +16 -0
  83. rasa/cli/project_templates/finance/domain/cards/replace_card.yml +43 -0
  84. rasa/cli/project_templates/finance/domain/cards/shared.yml +15 -0
  85. rasa/cli/project_templates/finance/domain/contacts/add_contact.yml +37 -0
  86. rasa/cli/project_templates/finance/domain/contacts/list_contacts.yml +16 -0
  87. rasa/cli/project_templates/finance/domain/contacts/remove_contact.yml +32 -0
  88. rasa/cli/project_templates/finance/domain/domain.md +9 -1
  89. rasa/cli/project_templates/finance/domain/general/_shared.yml +53 -0
  90. rasa/cli/project_templates/finance/domain/general/agent_details.yml +19 -0
  91. rasa/cli/project_templates/finance/domain/general/cannot_handle.yml +5 -2
  92. rasa/cli/project_templates/finance/domain/general/feedback.yml +0 -3
  93. rasa/cli/project_templates/finance/domain/general/human_handoff.yml +7 -3
  94. rasa/cli/project_templates/finance/domain/general/welcome.yml +5 -2
  95. rasa/cli/project_templates/finance/domain/transfers/check_transfer_limit.yml +32 -0
  96. rasa/cli/project_templates/finance/domain/transfers/list_transactions.yml +44 -0
  97. rasa/cli/project_templates/finance/domain/transfers/shared.yml +17 -0
  98. rasa/cli/project_templates/finance/domain/transfers/transfer_money.yml +203 -61
  99. rasa/cli/project_templates/finance/endpoints.yml +3 -2
  100. rasa/cli/project_templates/finance/prompts/rephraser_demo_personality_prompt.jinja2 +31 -12
  101. rasa/cli/project_templates/telco/data/data.md +1 -1
  102. rasa/cli/project_templates/telco/docs/docs.md +3 -0
  103. rasa/cli/project_templates/telco/domain/domain.md +1 -2
  104. rasa/constants.py +1 -1
  105. rasa/core/actions/direct_custom_actions_executor.py +9 -2
  106. rasa/core/agent.py +2 -3
  107. rasa/core/available_agents.py +8 -6
  108. rasa/core/brokers/broker.py +1 -1
  109. rasa/core/brokers/kafka.py +52 -8
  110. rasa/core/channels/__init__.py +82 -35
  111. rasa/core/channels/inspector/README.md +1 -1
  112. rasa/core/channels/telegram.py +4 -9
  113. rasa/core/channels/voice_stream/twilio_media_streams.py +5 -1
  114. rasa/core/concurrent_lock_store.py +66 -16
  115. rasa/core/iam_credentials_providers/aws_iam_credentials_providers.py +76 -1
  116. rasa/core/iam_credentials_providers/credentials_provider_protocol.py +1 -1
  117. rasa/core/lock_store.py +41 -7
  118. rasa/core/policies/flows/agent_executor.py +632 -0
  119. rasa/core/policies/flows/flow_executor.py +3 -418
  120. rasa/core/policies/flows/mcp_tool_executor.py +35 -14
  121. rasa/core/processor.py +49 -28
  122. rasa/core/run.py +22 -0
  123. rasa/dialogue_understanding/commands/cancel_flow_command.py +1 -1
  124. rasa/dialogue_understanding/commands/chit_chat_answer_command.py +11 -3
  125. rasa/dialogue_understanding/commands/clarify_command.py +11 -3
  126. rasa/dialogue_understanding/commands/knowledge_answer_command.py +11 -3
  127. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_claude_3_5_sonnet_20240620_template.jinja2 +3 -3
  128. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_gpt_4o_2024_11_20_template.jinja2 +3 -3
  129. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_claude_3_5_sonnet_20240620_template.jinja2 +3 -3
  130. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +3 -3
  131. rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +2 -0
  132. rasa/dialogue_understanding/processor/command_processor.py +70 -0
  133. rasa/dialogue_understanding/stack/dialogue_stack.py +0 -25
  134. rasa/engine/loader.py +12 -0
  135. rasa/engine/recipes/default_components.py +111 -82
  136. rasa/engine/recipes/default_recipe.py +79 -22
  137. rasa/engine/runner/dask.py +8 -5
  138. rasa/graph_components/validators/default_recipe_validator.py +59 -19
  139. rasa/model_manager/warm_rasa_process.py +13 -3
  140. rasa/model_training.py +0 -14
  141. rasa/nlu/classifiers/logistic_regression_classifier.py +1 -22
  142. rasa/nlu/classifiers/mitie_intent_classifier.py +3 -0
  143. rasa/nlu/classifiers/sklearn_intent_classifier.py +1 -3
  144. rasa/nlu/extractors/crf_entity_extractor.py +9 -10
  145. rasa/nlu/extractors/mitie_entity_extractor.py +3 -0
  146. rasa/nlu/extractors/spacy_entity_extractor.py +3 -0
  147. rasa/nlu/featurizers/dense_featurizer/mitie_featurizer.py +2 -0
  148. rasa/nlu/featurizers/dense_featurizer/spacy_featurizer.py +3 -0
  149. rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +4 -2
  150. rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +4 -0
  151. rasa/nlu/tokenizers/jieba_tokenizer.py +3 -4
  152. rasa/nlu/tokenizers/mitie_tokenizer.py +3 -2
  153. rasa/nlu/tokenizers/spacy_tokenizer.py +3 -2
  154. rasa/nlu/utils/mitie_utils.py +3 -0
  155. rasa/nlu/utils/spacy_utils.py +3 -2
  156. rasa/shared/agents/auth/agent_auth_manager.py +6 -3
  157. rasa/shared/agents/auth/auth_strategy/oauth2_auth_strategy.py +13 -5
  158. rasa/shared/core/constants.py +5 -1
  159. rasa/shared/utils/mcp/server_connection.py +1 -1
  160. rasa/telemetry.py +63 -0
  161. rasa/utils/log_utils.py +95 -4
  162. rasa/utils/tensorflow/__init__.py +0 -22
  163. rasa/utils/tensorflow/callback.py +17 -7
  164. rasa/utils/tensorflow/layers.py +10 -7
  165. rasa/utils/tensorflow/rasa_layers.py +1 -1
  166. rasa/version.py +1 -1
  167. {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/METADATA +99 -89
  168. {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/RECORD +171 -242
  169. rasa/cli/project_templates/finance/actions/accounts/action_ask_account.py +0 -47
  170. rasa/cli/project_templates/finance/actions/accounts/action_check_balance.py +0 -40
  171. rasa/cli/project_templates/finance/actions/action_session_start.py +0 -74
  172. rasa/cli/project_templates/finance/actions/cards/action_ask_card.py +0 -48
  173. rasa/cli/project_templates/finance/actions/cards/action_check_card_existence.py +0 -36
  174. rasa/cli/project_templates/finance/actions/cards/action_update_card_status.py +0 -54
  175. rasa/cli/project_templates/finance/actions/database.py +0 -277
  176. rasa/cli/project_templates/finance/actions/transfers/action_add_payee.py +0 -52
  177. rasa/cli/project_templates/finance/actions/transfers/action_ask_account_from.py +0 -51
  178. rasa/cli/project_templates/finance/actions/transfers/action_check_payee_existence.py +0 -40
  179. rasa/cli/project_templates/finance/actions/transfers/action_check_sufficient_funds.py +0 -40
  180. rasa/cli/project_templates/finance/actions/transfers/action_list_payees.py +0 -46
  181. rasa/cli/project_templates/finance/actions/transfers/action_remove_payee.py +0 -49
  182. rasa/cli/project_templates/finance/actions/transfers/action_schedule_payment.py +0 -19
  183. rasa/cli/project_templates/finance/actions/transfers/action_validate_payment_date.py +0 -36
  184. rasa/cli/project_templates/finance/csvs/accounts.csv +0 -8
  185. rasa/cli/project_templates/finance/csvs/advisors.csv +0 -7
  186. rasa/cli/project_templates/finance/csvs/appointments.csv +0 -211
  187. rasa/cli/project_templates/finance/csvs/branches.csv +0 -10
  188. rasa/cli/project_templates/finance/csvs/cards.csv +0 -11
  189. rasa/cli/project_templates/finance/csvs/payees.csv +0 -11
  190. rasa/cli/project_templates/finance/csvs/transactions.csv +0 -71
  191. rasa/cli/project_templates/finance/csvs/users.csv +0 -4
  192. rasa/cli/project_templates/finance/data/cards/select_card.yml +0 -12
  193. rasa/cli/project_templates/finance/data/general/bot_identity.yml +0 -6
  194. rasa/cli/project_templates/finance/data/system/patterns/pattern_chitchat.yml +0 -5
  195. rasa/cli/project_templates/finance/data/system/source/accounts.json +0 -51
  196. rasa/cli/project_templates/finance/data/system/source/advisors.json +0 -44
  197. rasa/cli/project_templates/finance/data/system/source/appointments.json +0 -1474
  198. rasa/cli/project_templates/finance/data/system/source/branches.json +0 -47
  199. rasa/cli/project_templates/finance/data/system/source/cards.json +0 -72
  200. rasa/cli/project_templates/finance/data/system/source/payees.json +0 -74
  201. rasa/cli/project_templates/finance/data/system/source/transactions.json +0 -492
  202. rasa/cli/project_templates/finance/data/system/source/users.json +0 -29
  203. rasa/cli/project_templates/finance/data/transfers/add_payee.yml +0 -29
  204. rasa/cli/project_templates/finance/data/transfers/list_payees.yml +0 -5
  205. rasa/cli/project_templates/finance/data/transfers/remove_payee.yml +0 -21
  206. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/consequences_of_blocking_card.txt +0 -8
  207. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/reasons_to_block_card.txt +0 -8
  208. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/recovering_from_card_fraud.txt +0 -8
  209. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/tips_for_card_security.txt +0 -8
  210. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/what_to_do_if_card_is_lost.txt +0 -8
  211. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/account_balance_security.txt +0 -7
  212. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/common_balance_inquiries.txt +0 -8
  213. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/methods_to_check_balance.txt +0 -8
  214. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/understanding_balance_updates.txt +0 -8
  215. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/what_to_do_if_balance_is_incorrect.txt +0 -8
  216. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/benefits_of_authorised_payees.txt +0 -8
  217. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/common_issues_with_payees.txt +0 -8
  218. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/general_payee_information.txt +0 -8
  219. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/payee_management_tips.txt +0 -8
  220. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/understanding_payee_types.txt +0 -8
  221. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/common_transfer_errors.txt +0 -8
  222. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/fees_for_transfers.txt +0 -8
  223. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/general_transfer_information.txt +0 -8
  224. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/security_tips_for_transfers.txt +0 -8
  225. rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/transfer_processing_times.txt +0 -8
  226. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part1.txt +0 -50
  227. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part10.txt +0 -50
  228. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part11.txt +0 -48
  229. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part12.txt +0 -50
  230. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part13.txt +0 -50
  231. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part14.txt +0 -47
  232. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part15.txt +0 -50
  233. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part16.txt +0 -50
  234. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part17.txt +0 -47
  235. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part18.txt +0 -50
  236. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part19.txt +0 -50
  237. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part2.txt +0 -50
  238. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part20.txt +0 -47
  239. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part21.txt +0 -50
  240. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part22.txt +0 -50
  241. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part23.txt +0 -47
  242. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part24.txt +0 -50
  243. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part25.txt +0 -50
  244. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part26.txt +0 -47
  245. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part27.txt +0 -50
  246. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part28.txt +0 -50
  247. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part29.txt +0 -47
  248. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part3.txt +0 -47
  249. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part30.txt +0 -50
  250. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part31.txt +0 -50
  251. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part32.txt +0 -47
  252. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part33.txt +0 -50
  253. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part34.txt +0 -50
  254. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part35.txt +0 -47
  255. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part36.txt +0 -50
  256. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part37.txt +0 -50
  257. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part38.txt +0 -47
  258. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part39.txt +0 -50
  259. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part4.txt +0 -50
  260. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part40.txt +0 -50
  261. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part41.txt +0 -47
  262. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part42.txt +0 -50
  263. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part43.txt +0 -50
  264. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part44.txt +0 -47
  265. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part45.txt +0 -50
  266. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part46.txt +0 -50
  267. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part47.txt +0 -47
  268. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part48.txt +0 -50
  269. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part49.txt +0 -50
  270. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part5.txt +0 -50
  271. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part50.txt +0 -47
  272. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part51.txt +0 -50
  273. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part52.txt +0 -50
  274. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part53.txt +0 -47
  275. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part54.txt +0 -50
  276. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part55.txt +0 -50
  277. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part56.txt +0 -47
  278. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part57.txt +0 -50
  279. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part58.txt +0 -50
  280. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part59.txt +0 -47
  281. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part6.txt +0 -47
  282. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part60.txt +0 -50
  283. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part61.txt +0 -50
  284. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part7.txt +0 -50
  285. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part8.txt +0 -50
  286. rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part9.txt +0 -47
  287. rasa/cli/project_templates/finance/domain/cards/select_card.yml +0 -12
  288. rasa/cli/project_templates/finance/domain/general/bot_identity.yml +0 -5
  289. rasa/cli/project_templates/finance/domain/general/defaults.yml +0 -24
  290. rasa/cli/project_templates/finance/domain/general/goodbye.yml +0 -7
  291. rasa/cli/project_templates/finance/domain/general/help.yml +0 -5
  292. rasa/cli/project_templates/finance/domain/general/utils.yml +0 -13
  293. rasa/cli/project_templates/finance/domain/transfers/add_payee.yml +0 -47
  294. rasa/cli/project_templates/finance/domain/transfers/list_payees.yml +0 -4
  295. rasa/cli/project_templates/finance/domain/transfers/remove_payee.yml +0 -16
  296. {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/NOTICE +0 -0
  297. {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/WHEEL +0 -0
  298. {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/entry_points.txt +0 -0
@@ -1,27 +1,15 @@
1
1
  from __future__ import annotations
2
2
 
3
- import asyncio
4
- from typing import Any, Dict, List, Optional, Text, cast
3
+ from typing import Any, Dict, List, Optional, Text
5
4
 
6
5
  import structlog
7
6
  from jinja2 import Template
8
7
  from pypred import Predicate
9
8
  from structlog.contextvars import bound_contextvars
10
9
 
11
- from rasa.agents.agent_manager import AgentManager
12
- from rasa.agents.constants import (
13
- A2A_AGENT_CONTEXT_ID_KEY,
14
- AGENT_METADATA_AGENT_RESPONSE_KEY,
15
- AGENT_METADATA_EXIT_IF_KEY,
16
- AGENT_METADATA_STRUCTURED_RESULTS_KEY,
17
- MAX_AGENT_RETRY_DELAY_SECONDS,
18
- )
19
- from rasa.agents.core.types import AgentStatus, ProtocolType
20
- from rasa.agents.schemas import AgentInput, AgentOutput
21
- from rasa.agents.schemas.agent_input import AgentInputSlot
22
- from rasa.core.available_agents import AvailableAgents
23
10
  from rasa.core.available_endpoints import AvailableEndpoints
24
11
  from rasa.core.constants import ACTIVE_FLOW_METADATA_KEY, STEP_ID_METADATA_KEY
12
+ from rasa.core.policies.flows.agent_executor import run_agent
25
13
  from rasa.core.policies.flows.flow_exceptions import (
26
14
  FlowCircuitBreakerTrippedException,
27
15
  FlowException,
@@ -34,7 +22,6 @@ from rasa.core.policies.flows.flow_step_result import (
34
22
  PauseFlowReturnPrediction,
35
23
  )
36
24
  from rasa.core.policies.flows.mcp_tool_executor import call_mcp_tool
37
- from rasa.core.utils import get_slot_names_from_exit_conditions
38
25
  from rasa.dialogue_understanding.patterns.cancel import CancelPatternFlowStackFrame
39
26
  from rasa.dialogue_understanding.patterns.collect_information import (
40
27
  FLOW_PATTERN_COLLECT_INFORMATION,
@@ -62,29 +49,18 @@ from rasa.dialogue_understanding.stack.frames import (
62
49
  )
63
50
  from rasa.dialogue_understanding.stack.frames.flow_stack_frame import (
64
51
  AgentStackFrame,
65
- AgentState,
66
52
  FlowStackFrameType,
67
53
  )
68
54
  from rasa.dialogue_understanding.stack.utils import (
69
55
  user_frames_on_the_stack,
70
56
  )
71
57
  from rasa.dialogue_understanding.utils import assemble_options_string
72
- from rasa.shared.agents.utils import get_protocol_type
73
58
  from rasa.shared.constants import RASA_PATTERN_HUMAN_HANDOFF
74
59
  from rasa.shared.core.constants import (
75
- ACTION_AGENT_REQUEST_USER_INPUT_NAME,
76
60
  ACTION_LISTEN_NAME,
77
- ACTION_METADATA_MESSAGE_KEY,
78
- ACTION_METADATA_TEXT_KEY,
79
- ACTION_SEND_TEXT_NAME,
80
- FLOW_HASHES_SLOT,
81
61
  SILENCE_TIMEOUT_SLOT,
82
62
  )
83
63
  from rasa.shared.core.events import (
84
- AgentCancelled,
85
- AgentCompleted,
86
- AgentResumed,
87
- AgentStarted,
88
64
  Event,
89
65
  FlowCompleted,
90
66
  FlowResumed,
@@ -109,19 +85,13 @@ from rasa.shared.core.flows.steps import (
109
85
  SetSlotsFlowStep,
110
86
  )
111
87
  from rasa.shared.core.flows.steps.constants import START_STEP
112
- from rasa.shared.core.slots import CategoricalSlot, Slot, SlotRejection
88
+ from rasa.shared.core.slots import Slot, SlotRejection
113
89
  from rasa.shared.core.trackers import DialogueStateTracker
114
- from rasa.shared.utils.llm import tracker_as_readable_transcript
115
90
 
116
91
  structlogger = structlog.get_logger()
117
92
 
118
93
  MAX_NUMBER_OF_STEPS = 250
119
94
 
120
- MAX_AGENT_RETRIES = 3
121
-
122
- # Slots that should not be forwarded to sub-agents via AgentInput
123
- SLOTS_EXCLUDED_FOR_AGENT = [FLOW_HASHES_SLOT]
124
-
125
95
 
126
96
  def render_template_variables(text: str, context: Dict[Text, Any]) -> str:
127
97
  """Replace context variables in a text."""
@@ -909,388 +879,3 @@ def _append_global_silence_timeout_event(
909
879
  AvailableEndpoints.get_instance().interaction_handling.global_silence_timeout,
910
880
  )
911
881
  )
912
-
913
-
914
- def _reset_slots_covered_by_exit_if(
915
- exit_conditions: List[str], tracker: DialogueStateTracker
916
- ) -> None:
917
- """Reset the slots covered by the exit_if condition."""
918
- reset_slot_names = get_slot_names_from_exit_conditions(exit_conditions)
919
- for slot_name in reset_slot_names:
920
- if tracker.slots.get(slot_name) is not None:
921
- tracker.update(SlotSet(slot_name, None))
922
-
923
-
924
- async def run_agent(
925
- initial_events: List[Event],
926
- stack: DialogueStack,
927
- step: CallFlowStep,
928
- tracker: DialogueStateTracker,
929
- slots: List[Slot],
930
- ) -> FlowStepResult:
931
- """Run an agent call step."""
932
- structlogger.debug(
933
- "flow.step.run_agent", agent_id=step.call, step_id=step.id, flow_id=step.flow_id
934
- )
935
-
936
- final_events = initial_events
937
- agent_stack_frame = tracker.stack.find_agent_stack_frame_by_agent(
938
- agent_id=step.call
939
- )
940
-
941
- if (
942
- agent_stack_frame
943
- and agent_stack_frame == stack.top()
944
- and agent_stack_frame.state == AgentState.INTERRUPTED
945
- ):
946
- structlogger.debug(
947
- "flow.step.run_agent.resume_interrupted_agent",
948
- agent_id=step.call,
949
- step_id=step.id,
950
- flow_id=step.flow_id,
951
- )
952
- # The agent was previously interrupted when waiting for user input.
953
- # Now we're back to the agent execution step and need to output the last message
954
- # from the agent (user input request) again and wait for user input
955
- cast(AgentStackFrame, stack.top()).state = AgentState.WAITING_FOR_INPUT
956
- tracker.update_stack(stack)
957
- utterance = (
958
- agent_stack_frame.metadata.get(AGENT_METADATA_AGENT_RESPONSE_KEY, "")
959
- if agent_stack_frame.metadata
960
- else ""
961
- )
962
- final_events.append(AgentResumed(agent_id=step.call, flow_id=step.flow_id))
963
- return PauseFlowReturnPrediction(
964
- _create_agent_request_user_input_prediction(utterance, final_events)
965
- )
966
-
967
- agent_input_metadata = (
968
- agent_stack_frame.metadata
969
- if agent_stack_frame and agent_stack_frame.metadata
970
- else {}
971
- )
972
- _update_agent_input_metadata_with_events(
973
- agent_input_metadata, step.call, step.flow_id, tracker
974
- )
975
- if step.exit_if:
976
- # TODO: this is a temporary fix to reset the slots covered by the exit_if
977
- if (
978
- agent_stack_frame
979
- and agent_stack_frame.frame_id == f"restart_agent_{step.call}"
980
- ):
981
- # when restarting an agent, we need to reset the slots covered by the
982
- # exit_if condition so that the agent can run again.
983
- _reset_slots_covered_by_exit_if(step.exit_if, tracker)
984
- agent_input_metadata[AGENT_METADATA_EXIT_IF_KEY] = step.exit_if
985
- agent_input = AgentInput(
986
- id=step.call,
987
- user_message=tracker.latest_message.text or ""
988
- if tracker.latest_message
989
- else "",
990
- slots=_prepare_slots_for_agent(tracker.current_slot_values(), slots),
991
- conversation_history=tracker_as_readable_transcript(tracker),
992
- events=tracker.current_state().get("events") or [],
993
- metadata=agent_input_metadata,
994
- )
995
-
996
- final_events.append(AgentStarted(step.call, step.flow_id))
997
-
998
- protocol_type = get_protocol_type(step, AvailableAgents.get_agent_config(step.call))
999
- # send the input to the agent and wait for a response
1000
- structlogger.debug(
1001
- "flow.step.run_agent.agent_input",
1002
- agent_name=step.call,
1003
- step_id=step.id,
1004
- flow_id=step.flow_id,
1005
- agent_input=agent_input,
1006
- )
1007
- output: AgentOutput = await _call_agent_with_retry(
1008
- agent_name=step.call,
1009
- protocol_type=protocol_type,
1010
- agent_input=agent_input,
1011
- max_retries=MAX_AGENT_RETRIES,
1012
- )
1013
- structlogger.debug(
1014
- "flow.step.run_agent.agent_response",
1015
- agent_name=step.call,
1016
- step_id=step.id,
1017
- flow_id=step.flow_id,
1018
- agent_response=output,
1019
- )
1020
-
1021
- # add the set slot events returned by the agent to the list of final events
1022
- if output.events:
1023
- final_events.extend(output.events)
1024
-
1025
- if output.status == AgentStatus.INPUT_REQUIRED:
1026
- output.metadata = output.metadata or {}
1027
- output.metadata[AGENT_METADATA_AGENT_RESPONSE_KEY] = (
1028
- output.response_message or ""
1029
- )
1030
- output.metadata[AGENT_METADATA_STRUCTURED_RESULTS_KEY] = (
1031
- output.structured_results or []
1032
- )
1033
- _update_agent_events(final_events, output.metadata)
1034
-
1035
- top_stack_frame = stack.top()
1036
- # update the agent stack frame if it is already on the stack
1037
- # otherwise push a new one
1038
- if isinstance(top_stack_frame, AgentStackFrame):
1039
- top_stack_frame.state = AgentState.WAITING_FOR_INPUT
1040
- top_stack_frame.metadata = output.metadata
1041
- top_stack_frame.step_id = step.id
1042
- top_stack_frame.agent_id = step.call
1043
- top_stack_frame.flow_id = step.flow_id
1044
- else:
1045
- stack.push(
1046
- AgentStackFrame(
1047
- flow_id=step.flow_id,
1048
- agent_id=step.call,
1049
- state=AgentState.WAITING_FOR_INPUT,
1050
- step_id=step.id,
1051
- metadata=output.metadata,
1052
- )
1053
- )
1054
-
1055
- action_prediction = _create_agent_request_user_input_prediction(
1056
- output.response_message, final_events
1057
- )
1058
- return PauseFlowReturnPrediction(action_prediction)
1059
- elif output.status == AgentStatus.COMPLETED:
1060
- output.metadata = output.metadata or {}
1061
- _update_agent_events(final_events, output.metadata)
1062
- structlogger.debug(
1063
- "flow.step.run_agent.completed",
1064
- agent_name=step.call,
1065
- step_id=step.id,
1066
- flow_id=step.flow_id,
1067
- )
1068
- remove_agent_stack_frame(stack, step.call)
1069
- agent_completed_event = AgentCompleted(agent_id=step.call, flow_id=step.flow_id)
1070
- final_events.append(agent_completed_event)
1071
- if output.response_message:
1072
- # for open-ended agents we want to utter the last agent message
1073
-
1074
- return PauseFlowReturnPrediction(
1075
- _create_send_text_prediction(output.response_message, final_events)
1076
- )
1077
- else:
1078
- return ContinueFlowWithNextStep(events=final_events)
1079
- elif output.status == AgentStatus.FATAL_ERROR:
1080
- output.metadata = output.metadata or {}
1081
- _update_agent_events(final_events, output.metadata)
1082
- # the agent failed, trigger pattern_internal_error
1083
- structlogger.error(
1084
- "flow.step.run_agent.fatal_error",
1085
- agent_name=step.call,
1086
- step_id=step.id,
1087
- flow_id=step.flow_id,
1088
- error_message=output.error_message,
1089
- )
1090
- remove_agent_stack_frame(stack, step.call)
1091
- final_events.append(
1092
- AgentCancelled(
1093
- agent_id=step.call, flow_id=step.flow_id, reason=output.error_message
1094
- )
1095
- )
1096
- stack.push(InternalErrorPatternFlowStackFrame())
1097
- return ContinueFlowWithNextStep(events=final_events)
1098
- else:
1099
- output.metadata = output.metadata or {}
1100
- _update_agent_events(final_events, output.metadata)
1101
- structlogger.error(
1102
- "flow.step.run_agent.unknown_status",
1103
- agent_name=step.call,
1104
- step_id=step.id,
1105
- flow_id=step.flow_id,
1106
- status=output.status,
1107
- )
1108
- remove_agent_stack_frame(stack, step.call)
1109
- final_events.append(AgentCancelled(agent_id=step.call, flow_id=step.flow_id))
1110
- stack.push(InternalErrorPatternFlowStackFrame())
1111
- return ContinueFlowWithNextStep(events=final_events)
1112
-
1113
-
1114
- def remove_agent_stack_frame(stack: DialogueStack, agent_id: str) -> None:
1115
- """Finishes the agentic loop by popping the agent stack frame from the
1116
- provided `stack`. The `tracker.stack` is NOT modified.
1117
- """
1118
- agent_stack_frame = stack.find_agent_stack_frame_by_agent(agent_id)
1119
- if not agent_stack_frame:
1120
- return
1121
-
1122
- while removed_frame := stack.pop():
1123
- structlogger.debug(
1124
- "flow_executor.remove_agent_stack_frame",
1125
- removed_frame=removed_frame,
1126
- )
1127
- if removed_frame == agent_stack_frame:
1128
- break
1129
-
1130
-
1131
- def _create_action_prediction(
1132
- action_name: str, message: Optional[str], events: Optional[List[Event]]
1133
- ) -> FlowActionPrediction:
1134
- """Create a prediction for an action with a text message."""
1135
- action_metadata = {
1136
- ACTION_METADATA_MESSAGE_KEY: {
1137
- ACTION_METADATA_TEXT_KEY: message,
1138
- }
1139
- }
1140
- return FlowActionPrediction(
1141
- action_name,
1142
- 1.0,
1143
- events=events if events else [],
1144
- metadata=action_metadata,
1145
- )
1146
-
1147
-
1148
- def _create_agent_request_user_input_prediction(
1149
- message: Optional[str], events: Optional[List[Event]]
1150
- ) -> FlowActionPrediction:
1151
- """Create a prediction for requesting user input from the agent
1152
- and waiting for it.
1153
- """
1154
- return _create_action_prediction(
1155
- ACTION_AGENT_REQUEST_USER_INPUT_NAME, message, events
1156
- )
1157
-
1158
-
1159
- def _create_send_text_prediction(
1160
- message: Optional[str], events: Optional[List[Event]]
1161
- ) -> FlowActionPrediction:
1162
- """Create a prediction for sending a text message to the user."""
1163
- return _create_action_prediction(ACTION_SEND_TEXT_NAME, message, events)
1164
-
1165
-
1166
- async def _call_agent_with_retry(
1167
- agent_name: str,
1168
- protocol_type: ProtocolType,
1169
- agent_input: AgentInput,
1170
- max_retries: int,
1171
- ) -> AgentOutput:
1172
- """Call an agent with retries in case of recoverable errors."""
1173
- for attempt in range(max_retries):
1174
- if attempt > 0:
1175
- structlogger.debug(
1176
- "flow_executor.call_agent_with_retry.retrying",
1177
- agent_name=agent_name,
1178
- attempt=attempt + 1,
1179
- num_retries=max_retries,
1180
- )
1181
- try:
1182
- agent_response: AgentOutput = await AgentManager().run_agent(
1183
- agent_name=agent_name, protocol_type=protocol_type, context=agent_input
1184
- )
1185
- except Exception as e:
1186
- # We don't have a vaild agent response at this time to act based
1187
- # on the agent status, so we return a fatal error.
1188
- structlogger.error(
1189
- "flow_executor.call_agent_with_retry.exception",
1190
- agent_name=agent_name,
1191
- error_message=str(e),
1192
- )
1193
- return AgentOutput(
1194
- id=agent_name,
1195
- status=AgentStatus.FATAL_ERROR,
1196
- error_message=str(e),
1197
- )
1198
-
1199
- if agent_response.status != AgentStatus.RECOVERABLE_ERROR:
1200
- return agent_response
1201
-
1202
- structlogger.warning(
1203
- "flow_executor.call_agent_with_retry.recoverable_error",
1204
- agent_name=agent_name,
1205
- attempt=attempt + 1,
1206
- num_retries=max_retries,
1207
- error_message=agent_response.error_message,
1208
- )
1209
- if attempt < max_retries - 1:
1210
- # exponential backoff - wait longer with each retry
1211
- # 1 second, 2 seconds, 4 seconds, etc.
1212
- await asyncio.sleep(min(2**attempt, MAX_AGENT_RETRY_DELAY_SECONDS))
1213
-
1214
- # we exhausted all retries, return fatal error
1215
- structlogger.warning(
1216
- "flow_executor.call_agent_with_retry.exhausted_retries",
1217
- agent_name=agent_name,
1218
- num_retries=max_retries,
1219
- )
1220
- return AgentOutput(
1221
- id=agent_name,
1222
- status=AgentStatus.FATAL_ERROR,
1223
- error_message="Exhausted all retries for agent call.",
1224
- )
1225
-
1226
-
1227
- def _prepare_slots_for_agent(
1228
- slot_values: Dict[str, Any], slot_definitions: List[Slot]
1229
- ) -> List[AgentInputSlot]:
1230
- """Prepare the slots for the agent.
1231
-
1232
- Filter out slots that should not be forwarded to agents.
1233
- Add the slot type and allowed values to the slot dictionary.
1234
-
1235
- Args:
1236
- slot_values: The full slot dictionary from the tracker.
1237
- slot_definitions: The slot definitions from the domain.
1238
-
1239
- Returns:
1240
- A list of slots containing the name, current value, type, and allowed values.
1241
- """
1242
-
1243
- def _get_slot_definition(slot_name: str) -> Optional[Slot]:
1244
- for slot in slot_definitions:
1245
- if slot.name == slot_name:
1246
- return slot
1247
- return None
1248
-
1249
- filtered_slots: List[AgentInputSlot] = []
1250
- for key, value in slot_values.items():
1251
- if key in SLOTS_EXCLUDED_FOR_AGENT:
1252
- continue
1253
- slot_definition = _get_slot_definition(key)
1254
- if slot_definition:
1255
- filtered_slots.append(
1256
- AgentInputSlot(
1257
- name=key,
1258
- value=value,
1259
- type=slot_definition.type_name if slot_definition else "any",
1260
- allowed_values=slot_definition.values
1261
- if isinstance(slot_definition, CategoricalSlot)
1262
- else None,
1263
- )
1264
- )
1265
-
1266
- return filtered_slots
1267
-
1268
-
1269
- def _update_agent_events(events: List[Event], metadata: Dict[str, Any]) -> None:
1270
- """Update the agent events based on the agent output metadata if needed."""
1271
- if A2A_AGENT_CONTEXT_ID_KEY in metadata:
1272
- # If the context ID is present, we need to store it in the AgentStarted
1273
- # event, so that it can be re-used later in case the agent is restarted.
1274
- for event in events:
1275
- if isinstance(event, AgentStarted):
1276
- event.context_id = metadata[A2A_AGENT_CONTEXT_ID_KEY]
1277
-
1278
-
1279
- def _update_agent_input_metadata_with_events(
1280
- metadata: Dict[str, Any], agent_id: str, flow_id: str, tracker: DialogueStateTracker
1281
- ) -> None:
1282
- """Update the agent input metadata with the events."""
1283
- agent_started_events = [
1284
- event
1285
- for event in tracker.events
1286
- if type(event) == AgentStarted
1287
- and event.agent_id == agent_id
1288
- and event.flow_id == flow_id
1289
- ]
1290
- if agent_started_events:
1291
- # If we have context ID from the previous agent run, we want to
1292
- # include it in the metadata so that the agent can continue the same
1293
- # context.
1294
- agent_started_event = agent_started_events[-1]
1295
- if agent_started_event.context_id:
1296
- metadata[A2A_AGENT_CONTEXT_ID_KEY] = agent_started_event.context_id
@@ -1,9 +1,8 @@
1
1
  import json
2
- import operator
3
- from functools import reduce
4
2
  from typing import Any, Dict, List, Optional
5
3
 
6
4
  import structlog
5
+ from jinja2.sandbox import SandboxedEnvironment
7
6
  from mcp.types import CallToolResult
8
7
 
9
8
  from rasa.core.available_endpoints import AvailableEndpoints
@@ -23,7 +22,7 @@ from rasa.utils.common import ensure_jsonified_iterable
23
22
 
24
23
  structlogger = structlog.get_logger()
25
24
 
26
- CONFIG_RESULT_KEY = "result_key"
25
+ CONFIG_VALUE = "value"
27
26
  CONFIG_SLOT = "slot"
28
27
 
29
28
 
@@ -41,6 +40,7 @@ async def call_mcp_tool(
41
40
  mapping=step.mapping,
42
41
  step_id=step.id,
43
42
  flow_id=step.flow_id,
43
+ json_formatting=["mapping"],
44
44
  )
45
45
 
46
46
  try:
@@ -126,6 +126,7 @@ async def _execute_mcp_tool_call(
126
126
  mcp_server=step.mcp_server,
127
127
  result_content=result.content,
128
128
  result_structured_content=result.structuredContent,
129
+ json_formatting=["result_content", "result_structured_content"],
129
130
  )
130
131
 
131
132
  # Process successful result
@@ -195,8 +196,9 @@ async def _connect_to_mcp_server(
195
196
  return None
196
197
 
197
198
  mcp_server_config = mcp_server_configs[0]
198
- mcp_server_connection = MCPServerConnection(
199
- mcp_server_config.name, mcp_server_config.url, mcp_server_config.type
199
+
200
+ mcp_server_connection = MCPServerConnection.from_config(
201
+ mcp_server_config.model_dump()
200
202
  )
201
203
 
202
204
  # Ensure the connection is established and return the connection object
@@ -222,31 +224,49 @@ def _jsonify_slot_value(value: Any) -> str | int | float | bool | None:
222
224
  return value
223
225
 
224
226
 
227
+ def _get_slot_value_from_jinja2_expression(
228
+ result_expression: str,
229
+ result_as_dict: Dict[str, Any],
230
+ ) -> Any:
231
+ """Get the slot value from the Jinja2 expression"""
232
+ # Create a sandboxed environment to evaluate the expression
233
+ _env = SandboxedEnvironment()
234
+
235
+ # Compile the expression
236
+ compiled_expr = _env.compile_expression(result_expression)
237
+
238
+ # Evaluate the expression
239
+ return compiled_expr(result_as_dict)
240
+
241
+
225
242
  def _process_tool_result(
226
243
  result: CallToolResult,
227
244
  output_mapping: List[Dict[str, str]],
228
245
  ) -> Optional[List[SlotSet]]:
229
- """Create a SetSlot event for the tool result."""
246
+ """Create a SetSlot event for the tool result using Jinja2 expressions"""
230
247
  try:
231
248
  _result_as_dict = {"result": result.model_dump()}
232
249
  slots = []
233
250
  for mapping in output_mapping:
234
251
  try:
235
- # Use reduce to navigate through nested keys in the result
236
- slot_value = reduce(
237
- operator.getitem,
238
- mapping[CONFIG_RESULT_KEY].split("."),
239
- _result_as_dict,
252
+ result_expression = mapping[CONFIG_VALUE]
253
+
254
+ # Get the slot value from the Jinja2 expression
255
+ slot_value = _get_slot_value_from_jinja2_expression(
256
+ result_expression, _result_as_dict
240
257
  )
258
+
241
259
  slots.append(
242
260
  SlotSet(mapping[CONFIG_SLOT], _jsonify_slot_value(slot_value))
243
261
  )
244
- except (KeyError, TypeError):
262
+ except Exception as e:
245
263
  structlogger.error(
246
- "call_mcp_tool.result_key_not_found_in_tool_result",
264
+ "call_mcp_tool.value_not_found_in_tool_result",
247
265
  slot=mapping[CONFIG_SLOT],
248
- result_key=mapping[CONFIG_RESULT_KEY],
266
+ value=mapping[CONFIG_VALUE],
249
267
  result=_result_as_dict,
268
+ error=str(e),
269
+ json_formatting=["result"],
250
270
  )
251
271
  return None
252
272
  return slots
@@ -255,6 +275,7 @@ def _process_tool_result(
255
275
  "call_mcp_tool.result_processing_failed",
256
276
  error=str(e),
257
277
  result=result,
278
+ json_formatting=["result"],
258
279
  )
259
280
  return None
260
281