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.
- rasa/__main__.py +15 -3
- rasa/agents/agent_factory.py +2 -2
- rasa/agents/agent_manager.py +50 -2
- rasa/agents/constants.py +3 -0
- rasa/agents/core/types.py +11 -0
- rasa/agents/protocol/a2a/a2a_agent.py +76 -17
- rasa/agents/protocol/mcp/mcp_base_agent.py +29 -5
- rasa/agents/protocol/mcp/mcp_open_agent.py +27 -13
- rasa/agents/protocol/mcp/mcp_task_agent.py +46 -31
- rasa/agents/schemas/__init__.py +2 -1
- rasa/agents/schemas/agent_tool_result.py +0 -2
- rasa/agents/schemas/agent_tool_schema.py +55 -3
- rasa/agents/templates/mcp_open_agent_prompt_template.jinja2 +6 -1
- rasa/agents/templates/mcp_task_agent_prompt_template.jinja2 +5 -0
- rasa/agents/utils.py +42 -3
- rasa/agents/validation.py +4 -4
- rasa/builder/copilot/telemetry.py +35 -19
- rasa/builder/main.py +5 -14
- rasa/builder/project_generator.py +1 -1
- rasa/builder/service.py +5 -0
- rasa/builder/template_cache.py +9 -184
- rasa/cli/project_templates/basic/data/data.md +5 -6
- rasa/cli/project_templates/basic/domain/domain.md +5 -2
- rasa/cli/project_templates/finance/README.md +8 -7
- rasa/cli/project_templates/finance/actions/__init__.py +0 -46
- rasa/cli/project_templates/finance/actions/accounts/check_balance.py +18 -0
- rasa/cli/project_templates/finance/actions/{transfers/action_process_immediate_payment.py → cards/check_that_card_exists.py} +6 -3
- rasa/cli/project_templates/finance/actions/cards/list_cards.py +22 -0
- rasa/cli/project_templates/finance/actions/contacts/__init__.py +0 -0
- rasa/cli/project_templates/finance/actions/contacts/add_contact.py +30 -0
- rasa/cli/project_templates/finance/actions/contacts/list_contacts.py +22 -0
- rasa/cli/project_templates/finance/actions/contacts/remove_contact.py +35 -0
- rasa/cli/project_templates/finance/actions/db.py +117 -0
- rasa/cli/project_templates/finance/actions/transfers/check_transfer_funds.py +27 -0
- rasa/cli/project_templates/finance/actions/transfers/check_transfer_limit.py +36 -0
- rasa/cli/project_templates/finance/actions/transfers/execute_recurrent_payment.py +20 -0
- rasa/cli/project_templates/finance/actions/transfers/execute_transfer.py +45 -0
- rasa/cli/project_templates/finance/actions/transfers/list_transactions.py +32 -0
- rasa/cli/project_templates/finance/config.yml +6 -0
- rasa/cli/project_templates/finance/credentials.yml +7 -6
- rasa/cli/project_templates/finance/data/accounts/check_balance.yml +3 -4
- rasa/cli/project_templates/finance/data/accounts/download_statements.yml +26 -0
- rasa/cli/project_templates/finance/data/bills/bill_pay_reminder.yml +25 -0
- rasa/cli/project_templates/finance/data/cards/activate_card.yml +35 -0
- rasa/cli/project_templates/finance/data/cards/block_card.yml +37 -58
- rasa/cli/project_templates/finance/data/cards/list_cards.yml +14 -0
- rasa/cli/project_templates/finance/data/cards/replace_card.yml +16 -0
- rasa/cli/project_templates/finance/data/cards/replace_eligible_card.yml +29 -0
- rasa/cli/project_templates/finance/data/contacts/add_contact.yml +33 -0
- rasa/cli/project_templates/finance/data/contacts/list_contacts.yml +14 -0
- rasa/cli/project_templates/finance/data/contacts/remove_contact.yml +31 -0
- rasa/cli/project_templates/finance/data/data.md +6 -3
- rasa/cli/project_templates/finance/data/general/agent_details.yml +6 -0
- rasa/cli/project_templates/finance/data/general/hello.yml +1 -2
- rasa/cli/project_templates/finance/data/general/human_handoff.yml +1 -1
- rasa/cli/project_templates/finance/data/transfers/check_transfer_limit.yml +18 -0
- rasa/cli/project_templates/finance/data/transfers/list_transactions.yml +46 -0
- rasa/cli/project_templates/finance/data/transfers/move_money_between_accounts.yml +51 -0
- rasa/cli/project_templates/finance/data/transfers/transfer_money.yml +29 -62
- rasa/cli/project_templates/finance/data/transfers/transfer_money_to_a_third_party.yml +175 -0
- rasa/cli/project_templates/finance/db/cards.json +18 -0
- rasa/cli/project_templates/finance/db/contacts.json +10 -0
- rasa/cli/project_templates/finance/db/my_account.json +6 -0
- rasa/cli/project_templates/finance/db/transactions.json +22 -0
- rasa/cli/project_templates/finance/docs/docs.md +8 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/account_features/budgeting_analytics.txt +22 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/account_features/multi_currency_accounts.txt +19 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/account_features/premium_benefits.txt +19 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/card_management/contactless_limits.txt +16 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/card_management/freeze_unfreeze_card.txt +16 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/card_management/lost_stolen_card.txt +19 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/money_transfers/instant_payments.txt +19 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/money_transfers/international_transfers.txt +19 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/security_fraud/fraud_protection.txt +22 -0
- rasa/cli/project_templates/finance/docs/fenlo_banking_faq/security_fraud/secure_payments.txt +22 -0
- rasa/cli/project_templates/finance/domain/_system/patterns/pattern_session_start.yml +11 -0
- rasa/cli/project_templates/finance/domain/accounts/check_balance.yml +9 -5
- rasa/cli/project_templates/finance/domain/accounts/download_statements.yml +40 -0
- rasa/cli/project_templates/finance/domain/bills/bill_pay_reminder.yml +49 -0
- rasa/cli/project_templates/finance/domain/cards/activate_card.yml +24 -0
- rasa/cli/project_templates/finance/domain/cards/block_card.yml +33 -90
- rasa/cli/project_templates/finance/domain/cards/list_cards.yml +16 -0
- rasa/cli/project_templates/finance/domain/cards/replace_card.yml +43 -0
- rasa/cli/project_templates/finance/domain/cards/shared.yml +15 -0
- rasa/cli/project_templates/finance/domain/contacts/add_contact.yml +37 -0
- rasa/cli/project_templates/finance/domain/contacts/list_contacts.yml +16 -0
- rasa/cli/project_templates/finance/domain/contacts/remove_contact.yml +32 -0
- rasa/cli/project_templates/finance/domain/domain.md +9 -1
- rasa/cli/project_templates/finance/domain/general/_shared.yml +53 -0
- rasa/cli/project_templates/finance/domain/general/agent_details.yml +19 -0
- rasa/cli/project_templates/finance/domain/general/cannot_handle.yml +5 -2
- rasa/cli/project_templates/finance/domain/general/feedback.yml +0 -3
- rasa/cli/project_templates/finance/domain/general/human_handoff.yml +7 -3
- rasa/cli/project_templates/finance/domain/general/welcome.yml +5 -2
- rasa/cli/project_templates/finance/domain/transfers/check_transfer_limit.yml +32 -0
- rasa/cli/project_templates/finance/domain/transfers/list_transactions.yml +44 -0
- rasa/cli/project_templates/finance/domain/transfers/shared.yml +17 -0
- rasa/cli/project_templates/finance/domain/transfers/transfer_money.yml +203 -61
- rasa/cli/project_templates/finance/endpoints.yml +3 -2
- rasa/cli/project_templates/finance/prompts/rephraser_demo_personality_prompt.jinja2 +31 -12
- rasa/cli/project_templates/telco/data/data.md +1 -1
- rasa/cli/project_templates/telco/docs/docs.md +3 -0
- rasa/cli/project_templates/telco/domain/domain.md +1 -2
- rasa/constants.py +1 -1
- rasa/core/actions/direct_custom_actions_executor.py +9 -2
- rasa/core/agent.py +2 -3
- rasa/core/available_agents.py +8 -6
- rasa/core/brokers/broker.py +1 -1
- rasa/core/brokers/kafka.py +52 -8
- rasa/core/channels/__init__.py +82 -35
- rasa/core/channels/inspector/README.md +1 -1
- rasa/core/channels/telegram.py +4 -9
- rasa/core/channels/voice_stream/twilio_media_streams.py +5 -1
- rasa/core/concurrent_lock_store.py +66 -16
- rasa/core/iam_credentials_providers/aws_iam_credentials_providers.py +76 -1
- rasa/core/iam_credentials_providers/credentials_provider_protocol.py +1 -1
- rasa/core/lock_store.py +41 -7
- rasa/core/policies/flows/agent_executor.py +632 -0
- rasa/core/policies/flows/flow_executor.py +3 -418
- rasa/core/policies/flows/mcp_tool_executor.py +35 -14
- rasa/core/processor.py +49 -28
- rasa/core/run.py +22 -0
- rasa/dialogue_understanding/commands/cancel_flow_command.py +1 -1
- rasa/dialogue_understanding/commands/chit_chat_answer_command.py +11 -3
- rasa/dialogue_understanding/commands/clarify_command.py +11 -3
- rasa/dialogue_understanding/commands/knowledge_answer_command.py +11 -3
- rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_claude_3_5_sonnet_20240620_template.jinja2 +3 -3
- rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_gpt_4o_2024_11_20_template.jinja2 +3 -3
- rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_claude_3_5_sonnet_20240620_template.jinja2 +3 -3
- rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +3 -3
- rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +2 -0
- rasa/dialogue_understanding/processor/command_processor.py +70 -0
- rasa/dialogue_understanding/stack/dialogue_stack.py +0 -25
- rasa/engine/loader.py +12 -0
- rasa/engine/recipes/default_components.py +111 -82
- rasa/engine/recipes/default_recipe.py +79 -22
- rasa/engine/runner/dask.py +8 -5
- rasa/graph_components/validators/default_recipe_validator.py +59 -19
- rasa/model_manager/warm_rasa_process.py +13 -3
- rasa/model_training.py +0 -14
- rasa/nlu/classifiers/logistic_regression_classifier.py +1 -22
- rasa/nlu/classifiers/mitie_intent_classifier.py +3 -0
- rasa/nlu/classifiers/sklearn_intent_classifier.py +1 -3
- rasa/nlu/extractors/crf_entity_extractor.py +9 -10
- rasa/nlu/extractors/mitie_entity_extractor.py +3 -0
- rasa/nlu/extractors/spacy_entity_extractor.py +3 -0
- rasa/nlu/featurizers/dense_featurizer/mitie_featurizer.py +2 -0
- rasa/nlu/featurizers/dense_featurizer/spacy_featurizer.py +3 -0
- rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +4 -2
- rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +4 -0
- rasa/nlu/tokenizers/jieba_tokenizer.py +3 -4
- rasa/nlu/tokenizers/mitie_tokenizer.py +3 -2
- rasa/nlu/tokenizers/spacy_tokenizer.py +3 -2
- rasa/nlu/utils/mitie_utils.py +3 -0
- rasa/nlu/utils/spacy_utils.py +3 -2
- rasa/shared/agents/auth/agent_auth_manager.py +6 -3
- rasa/shared/agents/auth/auth_strategy/oauth2_auth_strategy.py +13 -5
- rasa/shared/core/constants.py +5 -1
- rasa/shared/utils/mcp/server_connection.py +1 -1
- rasa/telemetry.py +63 -0
- rasa/utils/log_utils.py +95 -4
- rasa/utils/tensorflow/__init__.py +0 -22
- rasa/utils/tensorflow/callback.py +17 -7
- rasa/utils/tensorflow/layers.py +10 -7
- rasa/utils/tensorflow/rasa_layers.py +1 -1
- rasa/version.py +1 -1
- {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/METADATA +99 -89
- {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/RECORD +171 -242
- rasa/cli/project_templates/finance/actions/accounts/action_ask_account.py +0 -47
- rasa/cli/project_templates/finance/actions/accounts/action_check_balance.py +0 -40
- rasa/cli/project_templates/finance/actions/action_session_start.py +0 -74
- rasa/cli/project_templates/finance/actions/cards/action_ask_card.py +0 -48
- rasa/cli/project_templates/finance/actions/cards/action_check_card_existence.py +0 -36
- rasa/cli/project_templates/finance/actions/cards/action_update_card_status.py +0 -54
- rasa/cli/project_templates/finance/actions/database.py +0 -277
- rasa/cli/project_templates/finance/actions/transfers/action_add_payee.py +0 -52
- rasa/cli/project_templates/finance/actions/transfers/action_ask_account_from.py +0 -51
- rasa/cli/project_templates/finance/actions/transfers/action_check_payee_existence.py +0 -40
- rasa/cli/project_templates/finance/actions/transfers/action_check_sufficient_funds.py +0 -40
- rasa/cli/project_templates/finance/actions/transfers/action_list_payees.py +0 -46
- rasa/cli/project_templates/finance/actions/transfers/action_remove_payee.py +0 -49
- rasa/cli/project_templates/finance/actions/transfers/action_schedule_payment.py +0 -19
- rasa/cli/project_templates/finance/actions/transfers/action_validate_payment_date.py +0 -36
- rasa/cli/project_templates/finance/csvs/accounts.csv +0 -8
- rasa/cli/project_templates/finance/csvs/advisors.csv +0 -7
- rasa/cli/project_templates/finance/csvs/appointments.csv +0 -211
- rasa/cli/project_templates/finance/csvs/branches.csv +0 -10
- rasa/cli/project_templates/finance/csvs/cards.csv +0 -11
- rasa/cli/project_templates/finance/csvs/payees.csv +0 -11
- rasa/cli/project_templates/finance/csvs/transactions.csv +0 -71
- rasa/cli/project_templates/finance/csvs/users.csv +0 -4
- rasa/cli/project_templates/finance/data/cards/select_card.yml +0 -12
- rasa/cli/project_templates/finance/data/general/bot_identity.yml +0 -6
- rasa/cli/project_templates/finance/data/system/patterns/pattern_chitchat.yml +0 -5
- rasa/cli/project_templates/finance/data/system/source/accounts.json +0 -51
- rasa/cli/project_templates/finance/data/system/source/advisors.json +0 -44
- rasa/cli/project_templates/finance/data/system/source/appointments.json +0 -1474
- rasa/cli/project_templates/finance/data/system/source/branches.json +0 -47
- rasa/cli/project_templates/finance/data/system/source/cards.json +0 -72
- rasa/cli/project_templates/finance/data/system/source/payees.json +0 -74
- rasa/cli/project_templates/finance/data/system/source/transactions.json +0 -492
- rasa/cli/project_templates/finance/data/system/source/users.json +0 -29
- rasa/cli/project_templates/finance/data/transfers/add_payee.yml +0 -29
- rasa/cli/project_templates/finance/data/transfers/list_payees.yml +0 -5
- rasa/cli/project_templates/finance/data/transfers/remove_payee.yml +0 -21
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/consequences_of_blocking_card.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/reasons_to_block_card.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/recovering_from_card_fraud.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/tips_for_card_security.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/what_to_do_if_card_is_lost.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/account_balance_security.txt +0 -7
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/common_balance_inquiries.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/methods_to_check_balance.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/understanding_balance_updates.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/what_to_do_if_balance_is_incorrect.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/benefits_of_authorised_payees.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/common_issues_with_payees.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/general_payee_information.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/payee_management_tips.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/understanding_payee_types.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/common_transfer_errors.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/fees_for_transfers.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/general_transfer_information.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/security_tips_for_transfers.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/transfer_processing_times.txt +0 -8
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part1.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part10.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part11.txt +0 -48
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part12.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part13.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part14.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part15.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part16.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part17.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part18.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part19.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part2.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part20.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part21.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part22.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part23.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part24.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part25.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part26.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part27.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part28.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part29.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part3.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part30.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part31.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part32.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part33.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part34.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part35.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part36.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part37.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part38.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part39.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part4.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part40.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part41.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part42.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part43.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part44.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part45.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part46.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part47.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part48.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part49.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part5.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part50.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part51.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part52.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part53.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part54.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part55.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part56.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part57.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part58.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part59.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part6.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part60.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part61.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part7.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part8.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part9.txt +0 -47
- rasa/cli/project_templates/finance/domain/cards/select_card.yml +0 -12
- rasa/cli/project_templates/finance/domain/general/bot_identity.yml +0 -5
- rasa/cli/project_templates/finance/domain/general/defaults.yml +0 -24
- rasa/cli/project_templates/finance/domain/general/goodbye.yml +0 -7
- rasa/cli/project_templates/finance/domain/general/help.yml +0 -5
- rasa/cli/project_templates/finance/domain/general/utils.yml +0 -13
- rasa/cli/project_templates/finance/domain/transfers/add_payee.yml +0 -47
- rasa/cli/project_templates/finance/domain/transfers/list_payees.yml +0 -4
- rasa/cli/project_templates/finance/domain/transfers/remove_payee.yml +0 -16
- {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/NOTICE +0 -0
- {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/WHEEL +0 -0
- {rasa_pro-3.14.0.dev9.dist-info → rasa_pro-3.14.0.dev11.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import Any, Dict, List, Optional, cast
|
|
5
|
+
|
|
6
|
+
import structlog
|
|
7
|
+
|
|
8
|
+
from rasa.agents.agent_manager import AgentManager
|
|
9
|
+
from rasa.agents.constants import (
|
|
10
|
+
A2A_AGENT_CONTEXT_ID_KEY,
|
|
11
|
+
AGENT_METADATA_AGENT_RESPONSE_KEY,
|
|
12
|
+
AGENT_METADATA_EXIT_IF_KEY,
|
|
13
|
+
AGENT_METADATA_STRUCTURED_RESULTS_KEY,
|
|
14
|
+
MAX_AGENT_RETRY_DELAY_SECONDS,
|
|
15
|
+
)
|
|
16
|
+
from rasa.agents.core.types import AgentStatus, ProtocolType
|
|
17
|
+
from rasa.agents.schemas import AgentInput, AgentOutput
|
|
18
|
+
from rasa.agents.schemas.agent_input import AgentInputSlot
|
|
19
|
+
from rasa.core.available_agents import AvailableAgents
|
|
20
|
+
from rasa.core.policies.flows.flow_step_result import (
|
|
21
|
+
ContinueFlowWithNextStep,
|
|
22
|
+
FlowActionPrediction,
|
|
23
|
+
FlowStepResult,
|
|
24
|
+
PauseFlowReturnPrediction,
|
|
25
|
+
)
|
|
26
|
+
from rasa.core.utils import get_slot_names_from_exit_conditions
|
|
27
|
+
from rasa.dialogue_understanding.patterns.internal_error import (
|
|
28
|
+
InternalErrorPatternFlowStackFrame,
|
|
29
|
+
)
|
|
30
|
+
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack
|
|
31
|
+
from rasa.dialogue_understanding.stack.frames.flow_stack_frame import (
|
|
32
|
+
AgentStackFrame,
|
|
33
|
+
AgentState,
|
|
34
|
+
)
|
|
35
|
+
from rasa.shared.agents.utils import get_protocol_type
|
|
36
|
+
from rasa.shared.core.constants import (
|
|
37
|
+
ACTION_AGENT_REQUEST_USER_INPUT_NAME,
|
|
38
|
+
ACTION_METADATA_MESSAGE_KEY,
|
|
39
|
+
ACTION_METADATA_TEXT_KEY,
|
|
40
|
+
ACTION_SEND_TEXT_NAME,
|
|
41
|
+
SLOTS_EXCLUDED_FOR_AGENT,
|
|
42
|
+
)
|
|
43
|
+
from rasa.shared.core.events import (
|
|
44
|
+
AgentCancelled,
|
|
45
|
+
AgentCompleted,
|
|
46
|
+
AgentResumed,
|
|
47
|
+
AgentStarted,
|
|
48
|
+
Event,
|
|
49
|
+
SlotSet,
|
|
50
|
+
)
|
|
51
|
+
from rasa.shared.core.flows.steps import (
|
|
52
|
+
CallFlowStep,
|
|
53
|
+
)
|
|
54
|
+
from rasa.shared.core.slots import CategoricalSlot, Slot
|
|
55
|
+
from rasa.shared.core.trackers import DialogueStateTracker
|
|
56
|
+
from rasa.shared.utils.llm import tracker_as_readable_transcript
|
|
57
|
+
|
|
58
|
+
structlogger = structlog.get_logger()
|
|
59
|
+
|
|
60
|
+
MAX_AGENT_RETRIES = 3
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def remove_agent_stack_frame(stack: DialogueStack, agent_id: str) -> None:
|
|
64
|
+
"""Finishes the agentic loop by popping the agent stack frame from the
|
|
65
|
+
provided `stack`. The `tracker.stack` is NOT modified.
|
|
66
|
+
"""
|
|
67
|
+
agent_stack_frame = stack.find_agent_stack_frame_by_agent(agent_id)
|
|
68
|
+
if not agent_stack_frame:
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
while removed_frame := stack.pop():
|
|
72
|
+
structlogger.debug(
|
|
73
|
+
"flow_executor.remove_agent_stack_frame",
|
|
74
|
+
removed_frame=removed_frame,
|
|
75
|
+
)
|
|
76
|
+
if removed_frame == agent_stack_frame:
|
|
77
|
+
break
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async def run_agent(
|
|
81
|
+
initial_events: List[Event],
|
|
82
|
+
stack: DialogueStack,
|
|
83
|
+
step: CallFlowStep,
|
|
84
|
+
tracker: DialogueStateTracker,
|
|
85
|
+
slots: List[Slot],
|
|
86
|
+
) -> FlowStepResult:
|
|
87
|
+
"""Run an agent call step."""
|
|
88
|
+
structlogger.debug(
|
|
89
|
+
"flow.step.run_agent",
|
|
90
|
+
agent_id=step.call,
|
|
91
|
+
step_id=step.id,
|
|
92
|
+
flow_id=step.flow_id,
|
|
93
|
+
event_info=f"Agent {step.call} started",
|
|
94
|
+
highlight=True,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
final_events = initial_events
|
|
98
|
+
agent_stack_frame = tracker.stack.find_agent_stack_frame_by_agent(
|
|
99
|
+
agent_id=step.call
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
agent_stack_frame
|
|
104
|
+
and agent_stack_frame == stack.top()
|
|
105
|
+
and agent_stack_frame.state == AgentState.INTERRUPTED
|
|
106
|
+
):
|
|
107
|
+
# if an agent is interrupted, repeat the last message from the
|
|
108
|
+
# agent and wait for user input
|
|
109
|
+
return _handle_resume_interrupted_agent(
|
|
110
|
+
agent_stack_frame, final_events, stack, step, tracker
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Reset the slots covered by the exit_if
|
|
114
|
+
# Code smell: this is a temporary fix and will be addressed in ENG-2148
|
|
115
|
+
if (
|
|
116
|
+
step.exit_if
|
|
117
|
+
and agent_stack_frame
|
|
118
|
+
and agent_stack_frame.frame_id == f"restart_agent_{step.call}"
|
|
119
|
+
):
|
|
120
|
+
# when restarting an agent, we need to reset the slots covered by the
|
|
121
|
+
# exit_if condition so that the agent can run again.
|
|
122
|
+
_reset_slots_covered_by_exit_if(step.exit_if, tracker)
|
|
123
|
+
|
|
124
|
+
# generate the agent input
|
|
125
|
+
agent_input = _prepare_agent_input(agent_stack_frame, step, tracker, slots)
|
|
126
|
+
structlogger.debug(
|
|
127
|
+
"flow.step.run_agent.agent_input",
|
|
128
|
+
agent_name=step.call,
|
|
129
|
+
step_id=step.id,
|
|
130
|
+
flow_id=step.flow_id,
|
|
131
|
+
agent_input=agent_input.model_dump(),
|
|
132
|
+
json_formatting=["agent_input"],
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# add the AgentStarted event to the list of final events
|
|
136
|
+
final_events.append(AgentStarted(step.call, step.flow_id))
|
|
137
|
+
|
|
138
|
+
# send the input to the agent and wait for a response
|
|
139
|
+
protocol_type = get_protocol_type(step, AvailableAgents.get_agent_config(step.call))
|
|
140
|
+
output: AgentOutput = await _call_agent_with_retry(
|
|
141
|
+
agent_name=step.call,
|
|
142
|
+
protocol_type=protocol_type,
|
|
143
|
+
agent_input=agent_input,
|
|
144
|
+
max_retries=MAX_AGENT_RETRIES,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
structlogger.debug(
|
|
148
|
+
"flow.step.run_agent.agent_response",
|
|
149
|
+
agent_name=step.call,
|
|
150
|
+
step_id=step.id,
|
|
151
|
+
flow_id=step.flow_id,
|
|
152
|
+
agent_response=output.model_dump(),
|
|
153
|
+
json_formatting=["agent_response"],
|
|
154
|
+
event_info="Agent Output",
|
|
155
|
+
)
|
|
156
|
+
structlogger.debug(
|
|
157
|
+
"flow.step.run_agent.agent_finished",
|
|
158
|
+
agent_name=step.call,
|
|
159
|
+
flow_id=step.flow_id,
|
|
160
|
+
agent_state=str(output.status),
|
|
161
|
+
agent_response_message=output.response_message,
|
|
162
|
+
highlight=True,
|
|
163
|
+
event_info=f"Agent {step.call} finished",
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
# add the set slot events returned by the agent to the list of final events
|
|
167
|
+
if output.events:
|
|
168
|
+
final_events.extend(output.events)
|
|
169
|
+
|
|
170
|
+
# handle the agent output based on the agent status
|
|
171
|
+
if output.status == AgentStatus.INPUT_REQUIRED:
|
|
172
|
+
return _handle_agent_input_required(output, final_events, stack, step)
|
|
173
|
+
elif output.status == AgentStatus.COMPLETED:
|
|
174
|
+
return _handle_agent_completed(output, final_events, stack, step)
|
|
175
|
+
elif output.status == AgentStatus.FATAL_ERROR:
|
|
176
|
+
return _handle_agent_fatal_error(output, final_events, stack, step)
|
|
177
|
+
else:
|
|
178
|
+
return _handle_agent_unknown_status(output, final_events, stack, step)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def _call_agent_with_retry(
|
|
182
|
+
agent_name: str,
|
|
183
|
+
protocol_type: ProtocolType,
|
|
184
|
+
agent_input: AgentInput,
|
|
185
|
+
max_retries: int,
|
|
186
|
+
) -> AgentOutput:
|
|
187
|
+
"""Call an agent with retries in case of recoverable errors."""
|
|
188
|
+
for attempt in range(max_retries):
|
|
189
|
+
if attempt > 0:
|
|
190
|
+
structlogger.debug(
|
|
191
|
+
"flow_executor.call_agent_with_retry.retrying",
|
|
192
|
+
agent_name=agent_name,
|
|
193
|
+
attempt=attempt + 1,
|
|
194
|
+
num_retries=max_retries,
|
|
195
|
+
)
|
|
196
|
+
try:
|
|
197
|
+
agent_response: AgentOutput = await AgentManager().run_agent(
|
|
198
|
+
agent_name=agent_name, protocol_type=protocol_type, context=agent_input
|
|
199
|
+
)
|
|
200
|
+
except Exception as e:
|
|
201
|
+
# We don't have a vaild agent response at this time to act based
|
|
202
|
+
# on the agent status, so we return a fatal error.
|
|
203
|
+
structlogger.error(
|
|
204
|
+
"flow_executor.call_agent_with_retry.exception",
|
|
205
|
+
agent_name=agent_name,
|
|
206
|
+
error_message=str(e),
|
|
207
|
+
)
|
|
208
|
+
return AgentOutput(
|
|
209
|
+
id=agent_name,
|
|
210
|
+
status=AgentStatus.FATAL_ERROR,
|
|
211
|
+
error_message=str(e),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
if agent_response.status != AgentStatus.RECOVERABLE_ERROR:
|
|
215
|
+
return agent_response
|
|
216
|
+
|
|
217
|
+
structlogger.warning(
|
|
218
|
+
"flow_executor.call_agent_with_retry.recoverable_error",
|
|
219
|
+
agent_name=agent_name,
|
|
220
|
+
attempt=attempt + 1,
|
|
221
|
+
num_retries=max_retries,
|
|
222
|
+
error_message=agent_response.error_message,
|
|
223
|
+
)
|
|
224
|
+
if attempt < max_retries - 1:
|
|
225
|
+
# exponential backoff - wait longer with each retry
|
|
226
|
+
# 1 second, 2 seconds, 4 seconds, etc.
|
|
227
|
+
await asyncio.sleep(min(2**attempt, MAX_AGENT_RETRY_DELAY_SECONDS))
|
|
228
|
+
|
|
229
|
+
# we exhausted all retries, return fatal error
|
|
230
|
+
structlogger.warning(
|
|
231
|
+
"flow_executor.call_agent_with_retry.exhausted_retries",
|
|
232
|
+
agent_name=agent_name,
|
|
233
|
+
num_retries=max_retries,
|
|
234
|
+
)
|
|
235
|
+
return AgentOutput(
|
|
236
|
+
id=agent_name,
|
|
237
|
+
status=AgentStatus.FATAL_ERROR,
|
|
238
|
+
error_message="Exhausted all retries for agent call.",
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
################################################################################
|
|
243
|
+
# Handle resume interrupted agent
|
|
244
|
+
################################################################################
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _handle_resume_interrupted_agent(
|
|
248
|
+
agent_stack_frame: AgentStackFrame,
|
|
249
|
+
final_events: List[Event],
|
|
250
|
+
stack: DialogueStack,
|
|
251
|
+
step: CallFlowStep,
|
|
252
|
+
tracker: DialogueStateTracker,
|
|
253
|
+
) -> FlowStepResult:
|
|
254
|
+
"""Handle resuming an interrupted agent.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
agent_stack_frame: The interrupted agent stack frame
|
|
258
|
+
final_events: List of events to be added to the final result
|
|
259
|
+
stack: The dialogue stack
|
|
260
|
+
step: The flow step that called the agent
|
|
261
|
+
tracker: The dialogue state tracker
|
|
262
|
+
|
|
263
|
+
Returns:
|
|
264
|
+
FlowStepResult indicating to pause for user input
|
|
265
|
+
"""
|
|
266
|
+
structlogger.debug(
|
|
267
|
+
"flow.step.run_agent.resume_interrupted_agent",
|
|
268
|
+
agent_id=step.call,
|
|
269
|
+
step_id=step.id,
|
|
270
|
+
flow_id=step.flow_id,
|
|
271
|
+
)
|
|
272
|
+
# The agent was previously interrupted when waiting for user input.
|
|
273
|
+
# Now we're back to the agent execution step and need to output the last message
|
|
274
|
+
# from the agent (user input request) again and wait for user input
|
|
275
|
+
cast(AgentStackFrame, stack.top()).state = AgentState.WAITING_FOR_INPUT
|
|
276
|
+
tracker.update_stack(stack)
|
|
277
|
+
utterance = (
|
|
278
|
+
agent_stack_frame.metadata.get(AGENT_METADATA_AGENT_RESPONSE_KEY, "")
|
|
279
|
+
if agent_stack_frame.metadata
|
|
280
|
+
else ""
|
|
281
|
+
)
|
|
282
|
+
final_events.append(AgentResumed(agent_id=step.call, flow_id=step.flow_id))
|
|
283
|
+
return PauseFlowReturnPrediction(
|
|
284
|
+
_create_agent_request_user_input_prediction(utterance, final_events)
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
################################################################################
|
|
289
|
+
# Handle agent output
|
|
290
|
+
################################################################################
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _handle_agent_unknown_status(
|
|
294
|
+
output: AgentOutput,
|
|
295
|
+
final_events: List[Event],
|
|
296
|
+
stack: DialogueStack,
|
|
297
|
+
step: CallFlowStep,
|
|
298
|
+
) -> FlowStepResult:
|
|
299
|
+
"""Handle unknown agent status.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
output: The agent output with unknown status
|
|
303
|
+
final_events: List of events to be added to the final result
|
|
304
|
+
stack: The dialogue stack
|
|
305
|
+
step: The flow step that called the agent
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
FlowStepResult indicating to continue with internal error pattern
|
|
309
|
+
"""
|
|
310
|
+
output.metadata = output.metadata or {}
|
|
311
|
+
_update_agent_events(final_events, output.metadata)
|
|
312
|
+
structlogger.error(
|
|
313
|
+
"flow.step.run_agent.unknown_status",
|
|
314
|
+
agent_name=step.call,
|
|
315
|
+
step_id=step.id,
|
|
316
|
+
flow_id=step.flow_id,
|
|
317
|
+
status=output.status,
|
|
318
|
+
)
|
|
319
|
+
remove_agent_stack_frame(stack, step.call)
|
|
320
|
+
final_events.append(AgentCancelled(agent_id=step.call, flow_id=step.flow_id))
|
|
321
|
+
stack.push(InternalErrorPatternFlowStackFrame())
|
|
322
|
+
return ContinueFlowWithNextStep(events=final_events)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def _handle_agent_input_required(
|
|
326
|
+
output: AgentOutput,
|
|
327
|
+
final_events: List[Event],
|
|
328
|
+
stack: DialogueStack,
|
|
329
|
+
step: CallFlowStep,
|
|
330
|
+
) -> FlowStepResult:
|
|
331
|
+
"""Handle agent that requires user input.
|
|
332
|
+
|
|
333
|
+
Args:
|
|
334
|
+
output: The agent output containing input request information
|
|
335
|
+
final_events: List of events to be added to the final result
|
|
336
|
+
stack: The dialogue stack
|
|
337
|
+
step: The flow step that called the agent
|
|
338
|
+
|
|
339
|
+
Returns:
|
|
340
|
+
FlowStepResult indicating to pause for user input
|
|
341
|
+
"""
|
|
342
|
+
output.metadata = output.metadata or {}
|
|
343
|
+
output.metadata[AGENT_METADATA_AGENT_RESPONSE_KEY] = output.response_message or ""
|
|
344
|
+
output.metadata[AGENT_METADATA_STRUCTURED_RESULTS_KEY] = (
|
|
345
|
+
output.structured_results or []
|
|
346
|
+
)
|
|
347
|
+
_update_agent_events(final_events, output.metadata)
|
|
348
|
+
|
|
349
|
+
top_stack_frame = stack.top()
|
|
350
|
+
# update the agent stack frame if it is already on the stack
|
|
351
|
+
# otherwise push a new one
|
|
352
|
+
if isinstance(top_stack_frame, AgentStackFrame):
|
|
353
|
+
top_stack_frame.state = AgentState.WAITING_FOR_INPUT
|
|
354
|
+
top_stack_frame.metadata = output.metadata
|
|
355
|
+
top_stack_frame.step_id = step.id
|
|
356
|
+
top_stack_frame.agent_id = step.call
|
|
357
|
+
top_stack_frame.flow_id = step.flow_id
|
|
358
|
+
else:
|
|
359
|
+
stack.push(
|
|
360
|
+
AgentStackFrame(
|
|
361
|
+
flow_id=step.flow_id,
|
|
362
|
+
agent_id=step.call,
|
|
363
|
+
state=AgentState.WAITING_FOR_INPUT,
|
|
364
|
+
step_id=step.id,
|
|
365
|
+
metadata=output.metadata,
|
|
366
|
+
)
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
action_prediction = _create_agent_request_user_input_prediction(
|
|
370
|
+
output.response_message, final_events
|
|
371
|
+
)
|
|
372
|
+
return PauseFlowReturnPrediction(action_prediction)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def _handle_agent_completed(
|
|
376
|
+
output: AgentOutput,
|
|
377
|
+
final_events: List[Event],
|
|
378
|
+
stack: DialogueStack,
|
|
379
|
+
step: CallFlowStep,
|
|
380
|
+
) -> FlowStepResult:
|
|
381
|
+
"""Handle completed agent execution.
|
|
382
|
+
|
|
383
|
+
Args:
|
|
384
|
+
output: The agent output containing completion information
|
|
385
|
+
final_events: List of events to be added to the final result
|
|
386
|
+
stack: The dialogue stack
|
|
387
|
+
step: The flow step that called the agent
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
FlowStepResult indicating to continue with next step or pause for response
|
|
391
|
+
"""
|
|
392
|
+
output.metadata = output.metadata or {}
|
|
393
|
+
_update_agent_events(final_events, output.metadata)
|
|
394
|
+
structlogger.debug(
|
|
395
|
+
"flow.step.run_agent.completed",
|
|
396
|
+
agent_name=step.call,
|
|
397
|
+
step_id=step.id,
|
|
398
|
+
flow_id=step.flow_id,
|
|
399
|
+
)
|
|
400
|
+
remove_agent_stack_frame(stack, step.call)
|
|
401
|
+
agent_completed_event = AgentCompleted(agent_id=step.call, flow_id=step.flow_id)
|
|
402
|
+
final_events.append(agent_completed_event)
|
|
403
|
+
if output.response_message:
|
|
404
|
+
# for open-ended agents we want to utter the last agent message
|
|
405
|
+
return PauseFlowReturnPrediction(
|
|
406
|
+
_create_send_text_prediction(output.response_message, final_events)
|
|
407
|
+
)
|
|
408
|
+
else:
|
|
409
|
+
return ContinueFlowWithNextStep(events=final_events)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _handle_agent_fatal_error(
|
|
413
|
+
output: AgentOutput,
|
|
414
|
+
final_events: List[Event],
|
|
415
|
+
stack: DialogueStack,
|
|
416
|
+
step: CallFlowStep,
|
|
417
|
+
) -> FlowStepResult:
|
|
418
|
+
"""Handle fatal error from agent execution.
|
|
419
|
+
|
|
420
|
+
Args:
|
|
421
|
+
output: The agent output containing error information
|
|
422
|
+
final_events: List of events to be added to the final result
|
|
423
|
+
stack: The dialogue stack
|
|
424
|
+
step: The flow step that called the agent
|
|
425
|
+
|
|
426
|
+
Returns:
|
|
427
|
+
FlowStepResult indicating to continue with internal error pattern
|
|
428
|
+
"""
|
|
429
|
+
output.metadata = output.metadata or {}
|
|
430
|
+
_update_agent_events(final_events, output.metadata)
|
|
431
|
+
# the agent failed, trigger pattern_internal_error
|
|
432
|
+
structlogger.error(
|
|
433
|
+
"flow.step.run_agent.fatal_error",
|
|
434
|
+
agent_name=step.call,
|
|
435
|
+
step_id=step.id,
|
|
436
|
+
flow_id=step.flow_id,
|
|
437
|
+
error_message=output.error_message,
|
|
438
|
+
)
|
|
439
|
+
remove_agent_stack_frame(stack, step.call)
|
|
440
|
+
final_events.append(
|
|
441
|
+
AgentCancelled(
|
|
442
|
+
agent_id=step.call, flow_id=step.flow_id, reason=output.error_message
|
|
443
|
+
)
|
|
444
|
+
)
|
|
445
|
+
stack.push(InternalErrorPatternFlowStackFrame())
|
|
446
|
+
return ContinueFlowWithNextStep(events=final_events)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
################################################################################
|
|
450
|
+
# Create predictions
|
|
451
|
+
################################################################################
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def _create_action_prediction(
|
|
455
|
+
action_name: str, message: Optional[str], events: Optional[List[Event]]
|
|
456
|
+
) -> FlowActionPrediction:
|
|
457
|
+
"""Create a prediction for an action with a text message."""
|
|
458
|
+
action_metadata = {
|
|
459
|
+
ACTION_METADATA_MESSAGE_KEY: {
|
|
460
|
+
ACTION_METADATA_TEXT_KEY: message,
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return FlowActionPrediction(
|
|
464
|
+
action_name,
|
|
465
|
+
1.0,
|
|
466
|
+
events=events if events else [],
|
|
467
|
+
metadata=action_metadata,
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def _create_agent_request_user_input_prediction(
|
|
472
|
+
message: Optional[str], events: Optional[List[Event]]
|
|
473
|
+
) -> FlowActionPrediction:
|
|
474
|
+
"""Create a prediction for requesting user input from the agent
|
|
475
|
+
and waiting for it.
|
|
476
|
+
"""
|
|
477
|
+
return _create_action_prediction(
|
|
478
|
+
ACTION_AGENT_REQUEST_USER_INPUT_NAME, message, events
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def _create_send_text_prediction(
|
|
483
|
+
message: Optional[str], events: Optional[List[Event]]
|
|
484
|
+
) -> FlowActionPrediction:
|
|
485
|
+
"""Create a prediction for sending a text message to the user."""
|
|
486
|
+
return _create_action_prediction(ACTION_SEND_TEXT_NAME, message, events)
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
################################################################################
|
|
490
|
+
# Prepare agent input
|
|
491
|
+
################################################################################
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def _prepare_agent_input(
|
|
495
|
+
agent_stack_frame: Optional[AgentStackFrame],
|
|
496
|
+
step: CallFlowStep,
|
|
497
|
+
tracker: DialogueStateTracker,
|
|
498
|
+
slots: List[Slot],
|
|
499
|
+
) -> AgentInput:
|
|
500
|
+
"""Prepare the agent input data.
|
|
501
|
+
|
|
502
|
+
Args:
|
|
503
|
+
agent_stack_frame: The agent stack frame if it exists
|
|
504
|
+
step: The flow step that called the agent
|
|
505
|
+
tracker: The dialogue state tracker
|
|
506
|
+
slots: List of slot definitions
|
|
507
|
+
|
|
508
|
+
Returns:
|
|
509
|
+
AgentInput object ready for agent execution
|
|
510
|
+
"""
|
|
511
|
+
agent_input_metadata = (
|
|
512
|
+
agent_stack_frame.metadata
|
|
513
|
+
if agent_stack_frame and agent_stack_frame.metadata
|
|
514
|
+
else {}
|
|
515
|
+
)
|
|
516
|
+
_update_agent_input_metadata_with_events(
|
|
517
|
+
agent_input_metadata, step.call, step.flow_id, tracker
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
if step.exit_if:
|
|
521
|
+
agent_input_metadata[AGENT_METADATA_EXIT_IF_KEY] = step.exit_if
|
|
522
|
+
|
|
523
|
+
return AgentInput(
|
|
524
|
+
id=step.call,
|
|
525
|
+
user_message=tracker.latest_message.text or ""
|
|
526
|
+
if tracker.latest_message
|
|
527
|
+
else "",
|
|
528
|
+
slots=_prepare_slots_for_agent(
|
|
529
|
+
tracker.current_slot_values(), slots, step.exit_if
|
|
530
|
+
),
|
|
531
|
+
conversation_history=tracker_as_readable_transcript(tracker),
|
|
532
|
+
events=tracker.current_state().get("events") or [],
|
|
533
|
+
metadata=agent_input_metadata,
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
def _prepare_slots_for_agent(
|
|
538
|
+
slot_values: Dict[str, Any],
|
|
539
|
+
slot_definitions: List[Slot],
|
|
540
|
+
exit_if: Optional[List[str]],
|
|
541
|
+
) -> List[AgentInputSlot]:
|
|
542
|
+
"""Prepare the slots for the agent.
|
|
543
|
+
|
|
544
|
+
Filter out slots that should not be forwarded to agents.
|
|
545
|
+
Add the slot type and allowed values to the slot dictionary.
|
|
546
|
+
|
|
547
|
+
Filter out slots that are None.
|
|
548
|
+
Keep slots that are part of the exit_if conditions.
|
|
549
|
+
|
|
550
|
+
Args:
|
|
551
|
+
slot_values: The full slot dictionary from the tracker.
|
|
552
|
+
slot_definitions: The slot definitions from the domain.
|
|
553
|
+
|
|
554
|
+
Returns:
|
|
555
|
+
A list of slots containing the name, current value, type, and allowed values.
|
|
556
|
+
"""
|
|
557
|
+
|
|
558
|
+
def _get_slot_definition(slot_name: str) -> Optional[Slot]:
|
|
559
|
+
for slot in slot_definitions:
|
|
560
|
+
if slot.name == slot_name:
|
|
561
|
+
return slot
|
|
562
|
+
return None
|
|
563
|
+
|
|
564
|
+
exit_if_slot_names = []
|
|
565
|
+
if exit_if:
|
|
566
|
+
exit_if_slot_names = get_slot_names_from_exit_conditions(exit_if)
|
|
567
|
+
|
|
568
|
+
filtered_slots: List[AgentInputSlot] = []
|
|
569
|
+
for key, value in slot_values.items():
|
|
570
|
+
if key in SLOTS_EXCLUDED_FOR_AGENT:
|
|
571
|
+
continue
|
|
572
|
+
if value is None and key not in exit_if_slot_names:
|
|
573
|
+
continue
|
|
574
|
+
slot_definition = _get_slot_definition(key)
|
|
575
|
+
if slot_definition:
|
|
576
|
+
filtered_slots.append(
|
|
577
|
+
AgentInputSlot(
|
|
578
|
+
name=key,
|
|
579
|
+
value=value,
|
|
580
|
+
type=slot_definition.type_name if slot_definition else "any",
|
|
581
|
+
allowed_values=slot_definition.values
|
|
582
|
+
if isinstance(slot_definition, CategoricalSlot)
|
|
583
|
+
else None,
|
|
584
|
+
)
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
return filtered_slots
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def _update_agent_input_metadata_with_events(
|
|
591
|
+
metadata: Dict[str, Any], agent_id: str, flow_id: str, tracker: DialogueStateTracker
|
|
592
|
+
) -> None:
|
|
593
|
+
"""Update the agent input metadata with the events."""
|
|
594
|
+
agent_started_events = [
|
|
595
|
+
event
|
|
596
|
+
for event in tracker.events
|
|
597
|
+
if type(event) == AgentStarted
|
|
598
|
+
and event.agent_id == agent_id
|
|
599
|
+
and event.flow_id == flow_id
|
|
600
|
+
]
|
|
601
|
+
if agent_started_events:
|
|
602
|
+
# If we have context ID from the previous agent run, we want to
|
|
603
|
+
# include it in the metadata so that the agent can continue the same
|
|
604
|
+
# context.
|
|
605
|
+
agent_started_event = agent_started_events[-1]
|
|
606
|
+
if agent_started_event.context_id:
|
|
607
|
+
metadata[A2A_AGENT_CONTEXT_ID_KEY] = agent_started_event.context_id
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
################################################################################
|
|
611
|
+
# Other helper methods
|
|
612
|
+
################################################################################
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def _update_agent_events(events: List[Event], metadata: Dict[str, Any]) -> None:
|
|
616
|
+
"""Update the agent events based on the agent output metadata if needed."""
|
|
617
|
+
if A2A_AGENT_CONTEXT_ID_KEY in metadata:
|
|
618
|
+
# If the context ID is present, we need to store it in the AgentStarted
|
|
619
|
+
# event, so that it can be re-used later in case the agent is restarted.
|
|
620
|
+
for event in events:
|
|
621
|
+
if isinstance(event, AgentStarted):
|
|
622
|
+
event.context_id = metadata[A2A_AGENT_CONTEXT_ID_KEY]
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def _reset_slots_covered_by_exit_if(
|
|
626
|
+
exit_conditions: List[str], tracker: DialogueStateTracker
|
|
627
|
+
) -> None:
|
|
628
|
+
"""Reset the slots covered by the exit_if condition."""
|
|
629
|
+
reset_slot_names = get_slot_names_from_exit_conditions(exit_conditions)
|
|
630
|
+
for slot_name in reset_slot_names:
|
|
631
|
+
if tracker.slots.get(slot_name) is not None:
|
|
632
|
+
tracker.update(SlotSet(slot_name, None))
|