File size: 38,844 Bytes
64fb1e7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | """
Workflow transition table β single source of truth for all tool-outcome routing.
Structure: STEP_TRANSITIONS[tool_name][fast_response_key] β StepTransition
Each StepTransition holds:
message β directive returned to the LLM wrapper (what to say / do next)
requires_consent β if True, wrapper must ask "shall I transfer you?" before escalating
escalation_team β team label passed to escalate_to_human reason
is_terminal β step cannot be retried; call flow must end or escalate
Coverage across payment industry workflows:
Identity verification β account lookup, multi-attempt lock
OTP authentication β expiry, wrong code, rate limits
Transaction status routing β all 12+ status states
Refund processing β all status pre-checks, idempotency
Account unlock β regular lock, fraud lock, compliance hold
Dispute filing β completed-txn disputes, duplicate, ineligible, high-value
Fraud reporting β unauthorized charges, already-reported, reversed
Payment status checks β pending, delayed, gateway error, post-debit failure
Cross-session signals β high frustration, repeated failures, legal queries
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Optional
@dataclass
class StepTransition:
message: str # directive returned to agent_tools wrapper
requires_consent: bool = False # if True, ask "shall I transfer?" before escalating
escalation_team: Optional[str] = None # label for escalate_to_human reason
is_terminal: bool = False # step cannot be retried after this outcome
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# STEP_TRANSITIONS
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
STEP_TRANSITIONS: dict[str, dict[str, StepTransition]] = {
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# IDENTITY VERIFICATION
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"verify_account": {
# First failed lookup β ask customer to confirm number
"not_found_1": StepTransition(
message=(
"Account not found. Tell the customer you couldn't find their account "
"and ask them to provide their registered phone number again. "
"As soon as they say any number, call verify_account with it immediately."
),
),
# Second failed lookup β offer specialist
"not_found_max": StepTransition(
message=(
"Account not found after two attempts. "
"Ask: 'I wasn't able to locate your account β would you like me to "
"connect you with a specialist who can help?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="account-specialist",
),
# Account exists but is suspended (compliance/legal)
"account_suspended": StepTransition(
message=(
"Account is suspended. This requires a manual review. "
"Ask: 'Your account is currently suspended β I need to connect you "
"with our compliance team to resolve this. Would you like me to "
"transfer you now?' Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="compliance-team",
is_terminal=True,
),
# Account frozen due to suspected security breach
"account_frozen": StepTransition(
message=(
"Account is frozen due to a security hold. "
"Ask: 'Your account has been temporarily frozen for your protection. "
"I need to connect you with our security team to assist you directly "
"β would you like me to transfer you now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="security-team",
is_terminal=True,
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# OTP AUTHENTICATION
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"send_otp": {
# Resend too soon β code already sent
"otp_cooldown": StepTransition(
message=(
"OTP just sent β cooldown active. Tell the customer: "
"'I sent that a moment ago β it can take a few seconds to arrive. "
"Please check your messages.' "
"Do NOT say you are resending. Do NOT call send_otp again."
),
),
# Total send limit for this session reached
"otp_resend_limit": StepTransition(
message=(
"OTP send limit reached for this session. "
"Ask: 'I've reached the OTP limit β would you like me to connect "
"you with a specialist who can verify your identity another way?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="identity-specialist",
),
},
"verify_otp": {
# Code expired after 5 minutes
"otp_expired": StepTransition(
message=(
"OTP has expired. Tell the customer: 'That code has expired β "
"I'll send you a fresh one now.' Then call send_otp immediately."
),
),
# Wrong code entered β attempts remaining
"otp_wrong": StepTransition(
message=(
"Wrong OTP code. Tell the customer how many attempts remain "
"and ask them to try again."
),
),
# 3 wrong attempts β locked, consent required before escalating
"otp_max_attempts": StepTransition(
message=(
"Three OTP attempts failed. "
"Ask: 'For your protection, I'd need to connect you with a specialist "
"who can verify your identity another way β would you like me to "
"transfer you now?' "
"Only call escalate_to_human if they say yes. "
"Do not attempt further OTP sends or verifications."
),
requires_consent=True,
escalation_team="identity-specialist",
is_terminal=True,
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# TRANSACTION STATUS ROUTING
# Status-based outcomes from lookup_transaction.
# The wrapper maps txn["status"] β "status_{status}" key.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"lookup_transaction": {
# Transaction not found on this account
"not_found": StepTransition(
message=(
"Transaction not found on this account. Ask the customer to confirm "
"the ID, or use search_transactions to find it by merchant, amount, or date."
),
),
# ββ In-flight states βββββββββββββββββββββββββββββββββββββββββββββββββ
"status_pending": StepTransition(
message=(
"Payment is currently being processed. Tell the customer: "
"'This payment is being processed by the gateway β it typically "
"takes 30 minutes to 2 hours. If it hasn't cleared by end of day, "
"call back and we can investigate further.'"
),
),
"status_processing": StepTransition(
message=(
"Payment is in the final settlement stage. Tell the customer: "
"'Your payment has been accepted and is in the final settlement "
"stage β funds should reach the merchant within the next hour.'"
),
),
# ββ Terminal states ββββββββββββββββββββββββββββββββββββββββββββββββββ
"status_failed": StepTransition(
message=(
"Transaction failed β amount may have been deducted but not credited. "
"Confirm the issue with the customer. "
"If they confirm the debit, proceed with OTP verification and "
"then call initiate_refund."
),
),
"status_completed": StepTransition(
message=(
"Transaction completed successfully. If the customer disputes this charge, "
"ask: 'Would you like me to file a dispute with our disputes team? "
"They can investigate whether you received the service.' "
"Only call raise_dispute if they say yes."
),
),
"status_cancelled": StepTransition(
message=(
"Transaction was cancelled before settlement. Tell the customer: "
"'This transaction was cancelled. If any amount was debited, "
"it will be automatically reversed within 3β5 business days. "
"If it was debited more than 5 days ago, let me know and I can "
"escalate for manual review.'"
),
),
"status_expired": StepTransition(
message=(
"Payment link or session expired before the transaction completed. "
"Tell the customer: 'This payment session expired before it could "
"complete. If any amount was debited, it will be reversed automatically "
"within 3β5 business days. Please initiate a fresh payment.'"
),
),
# ββ Refund lifecycle βββββββββββββββββββββββββββββββββββββββββββββββββ
"status_refund_initiated": StepTransition(
message=(
"Refund is already in progress. Tell the customer: "
"'Good news β a refund is already being processed for this transaction. "
"It typically takes 3β5 business days to appear in your account.'"
),
),
"status_refund_processing": StepTransition(
message=(
"Refund is currently being transferred back to the account. "
"Tell the customer: 'Your refund is being transferred right now β "
"it should reflect in your account within 1β2 business days.'"
),
),
"status_refund_completed": StepTransition(
message=(
"Refund has already been credited. Tell the customer: "
"'This refund was processed and credited. If you haven't seen it, "
"please check with your bank β it can take an extra day to reflect.'"
),
),
# ββ Hold / review states βββββββββββββββββββββββββββββββββββββββββββββ
"status_flagged": StepTransition(
message=(
"Transaction is flagged for fraud review. "
"Ask: 'This transaction is currently under our fraud review process β "
"I need to connect you with our fraud team to handle this safely. "
"Shall I transfer you now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="fraud-team",
is_terminal=True,
),
"status_kyc_hold": StepTransition(
message=(
"Transaction is on hold due to a pending KYC verification. "
"Ask: 'There's a KYC verification hold on your account that's "
"preventing this transaction from processing. I'd need to connect "
"you with our KYC specialist to resolve it β would you like me to "
"transfer you now?' Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="kyc-team",
),
"status_compliance_hold": StepTransition(
message=(
"Transaction is under a regulatory/compliance review. "
"Ask: 'This transaction is under a compliance review that requires "
"our compliance team to handle directly. Would you like me to "
"connect you with them now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="compliance-team",
is_terminal=True,
),
# ββ Dispute / chargeback states ββββββββββββββββββββββββββββββββββββββ
"status_disputed": StepTransition(
message=(
"A dispute is already open for this transaction. Tell the customer: "
"'A dispute case is already in progress for this transaction. "
"Our disputes team will contact you within 5β7 business days with "
"an update.'"
),
),
"status_chargeback_initiated": StepTransition(
message=(
"A chargeback has been initiated with the bank or card network. "
"Ask: 'A chargeback is currently in process for this transaction β "
"I'd need to connect you with our disputes team who is handling it. "
"Would you like me to transfer you?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="disputes-team",
),
"status_chargeback_won": StepTransition(
message=(
"Chargeback was resolved in the customer's favour. Tell the customer: "
"'Your chargeback was successful β the funds should have been credited "
"back to your account. If you haven't received them, please let me know.'"
),
),
"status_chargeback_lost": StepTransition(
message=(
"Chargeback was denied by the bank. "
"Ask: 'Unfortunately, the chargeback was not upheld. "
"I can connect you with our disputes team to discuss your options β "
"would you like me to transfer you?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="disputes-team",
),
# ββ Fraud states βββββββββββββββββββββββββββββββββββββββββββββββββββββ
"status_fraud_reported": StepTransition(
message=(
"A fraud report is already filed for this transaction. Tell the customer: "
"'A fraud investigation is already open for this transaction. "
"Our fraud team will contact you within 24 hours.'"
),
),
"status_fraud_confirmed": StepTransition(
message=(
"Fraud has been confirmed on this transaction. Tell the customer: "
"'Our fraud team has confirmed this as a fraudulent transaction. "
"The reversal process has been initiated β funds should be credited "
"within 5β7 business days.'"
),
),
"status_fraud_reversed": StepTransition(
message=(
"Fraudulent transaction has already been reversed. Tell the customer: "
"'This fraudulent charge has already been reversed and the funds "
"credited back. If you haven't seen them, please check with your bank.'"
),
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# REFUND PROCESSING
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"initiate_refund": {
# Refund already in progress
"refund_already_initiated": StepTransition(
message=(
"A refund is already underway for this transaction. "
"Tell the customer: 'Good news β a refund is already being processed. "
"It typically takes 3β5 business days to appear in your account.'"
),
),
# Refund already completed
"refund_already_completed": StepTransition(
message=(
"This refund has already been completed. "
"Tell the customer: 'This refund was already processed. "
"If you haven't seen it, please check with your bank β "
"it may take an extra day to reflect.'"
),
),
# Completed transaction β not auto-refundable
"refund_ineligible": StepTransition(
message=(
"Transaction completed successfully β not eligible for an automatic refund. "
"Tell the customer: 'This payment completed successfully on our end. "
"For disputes on completed transactions, our disputes team handles these.' "
"Ask: 'Would you like me to connect you with the disputes team now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="disputes-team",
),
# Flagged transaction β fraud team must clear first
"fraud_review_required": StepTransition(
message=(
"Transaction is under fraud review β cannot process refund until cleared. "
"Ask: 'This transaction is currently under fraud review. "
"I need to connect you with our fraud team to handle this safely. "
"Shall I transfer you now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="fraud-team",
is_terminal=True,
),
# KYC hold blocking refund
"kyc_escalation_required": StepTransition(
message=(
"Account has an active KYC hold β cannot process refund. "
"Ask: 'There is a KYC verification hold on this account. "
"Our KYC team needs to assist you directly before we can proceed. "
"Would you like me to transfer you now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="kyc-team",
is_terminal=True,
),
# Duplicate refund attempt in same session
"session_duplicate": StepTransition(
message=(
"A refund was already opened this session. "
"Tell the customer: 'I've already initiated a refund for this "
"transaction β it's being processed and should appear in 3β5 "
"business days.'"
),
),
# High-value transaction β needs manual approval
"high_value_review_required": StepTransition(
message=(
"This refund exceeds the automated processing limit and requires "
"manual approval. Ask: 'Refunds above our automated threshold need "
"a manual review by a senior specialist. Would you like me to "
"connect you with them now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="senior-support",
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# ACCOUNT UNLOCK
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"unlock_account": {
# Account is actually already active β might be a password issue
"already_unlocked": StepTransition(
message=(
"Account is already active and unlocked. Tell the customer: "
"'Your account is currently active. If you're having trouble "
"logging in, it may be a password issue β would you like me to "
"help with a password reset, or connect you with technical support?'"
),
),
# Account locked due to fraud investigation
"fraud_lock": StepTransition(
message=(
"Account is locked by the fraud team. This requires human review. "
"Ask: 'Your account has a security hold that requires our security "
"team to review directly β I cannot lift this through AI support. "
"Would you like me to connect you with them now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="security-team",
is_terminal=True,
),
# Account under compliance/AML hold
"compliance_hold": StepTransition(
message=(
"Account is under a compliance hold. "
"Ask: 'Your account has a regulatory hold that our compliance team "
"needs to handle directly. Shall I connect you with them now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="compliance-team",
is_terminal=True,
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# DISPUTE FILING
# For completed transactions the customer doesn't recognise or received
# no service for.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"raise_dispute": {
# Dispute successfully filed
"dispute_filed": StepTransition(
message=(
"Dispute has been filed. Tell the customer: "
"'Your dispute case has been opened. Our disputes team will "
"review it within 5β7 business days and contact you on your "
"registered email. Please note your dispute reference number "
"for follow-up.'"
),
),
# Dispute already filed for this transaction
"dispute_duplicate": StepTransition(
message=(
"A dispute is already open for this transaction. Tell the customer: "
"'A dispute case is already in progress. Our team will contact you "
"within 5β7 business days.'"
),
),
# Outside the 90-day dispute window
"dispute_window_expired": StepTransition(
message=(
"The dispute window for this transaction has expired. "
"Ask: 'Unfortunately the standard 90-day dispute window for this "
"transaction has passed. Our disputes team may have options for "
"exceptional cases β would you like me to connect you with them?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="disputes-team",
),
# Transaction type or status not eligible for dispute
"dispute_ineligible": StepTransition(
message=(
"This transaction is not eligible for a dispute through this channel. "
"Ask: 'I'd need to connect you with our disputes team who can explain "
"the specific reason and explore your options β would you like me to "
"transfer you?' Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="disputes-team",
),
# High-value dispute needs senior team
"high_value_manual_required": StepTransition(
message=(
"This dispute requires manual review due to the transaction amount. "
"Ask: 'Disputes above a certain value require review by our senior "
"disputes team for your protection β would you like me to connect "
"you with them now?' Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="senior-disputes",
),
# Fraud review in progress β dispute not appropriate yet
"fraud_review_required": StepTransition(
message=(
"Transaction is under active fraud review β a dispute cannot be filed "
"while fraud review is in progress. "
"Ask: 'This transaction is already being reviewed by our fraud team β "
"I need to connect you there for the right resolution. Shall I transfer you?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="fraud-team",
is_terminal=True,
),
# Refund already in progress β dispute not needed
"refund_already_initiated": StepTransition(
message=(
"A refund is already in progress for this transaction. Tell the customer: "
"'A refund is already being processed β it should appear within "
"3β5 business days. A separate dispute isn't needed.'"
),
),
# Refund already done β nothing to dispute
"refund_already_completed": StepTransition(
message=(
"Refund already completed for this transaction. Tell the customer: "
"'This transaction was already refunded. If you have a separate "
"concern, please let me know and I can help further.'"
),
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# FRAUD REPORTING
# For unauthorised transactions the customer didn't initiate.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"report_fraud": {
# Case successfully opened
"fraud_case_opened": StepTransition(
message=(
"Fraud report filed. Tell the customer: "
"'I've opened a fraud investigation for this transaction. "
"Our fraud team will review your account within 24 hours and "
"contact you if additional information is needed. "
"For your safety, consider changing your PIN and reviewing "
"recent transactions on your account.'"
),
),
# Already reported
"fraud_already_reported": StepTransition(
message=(
"This transaction has already been reported as fraud. Tell the customer: "
"'A fraud case is already open for this transaction. Our fraud team "
"will contact you within 24 hours.'"
),
),
# Already reversed β no action needed
"fraud_transaction_reversed": StepTransition(
message=(
"The fraudulent transaction has already been reversed. Tell the customer: "
"'Good news β this transaction has already been reversed and the funds "
"should be back in your account. If you don't see them yet, please "
"check with your bank as it may take an extra business day to reflect.'"
),
),
# Transaction not found
"transaction_not_found": StepTransition(
message=(
"Transaction not found on this account. Ask the customer to confirm "
"the transaction ID or provide the merchant name, amount, and date "
"so you can search for it."
),
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# PAYMENT STATUS CHECK
# Used when customer says "payment stuck", "money not credited", etc.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"check_payment_status": {
# Normal processing β within SLA window
"payment_processing": StepTransition(
message=(
"Payment is currently being processed. Tell the customer: "
"'Your payment is being processed by the payment gateway β "
"this typically takes 30 minutes to 2 hours. Please check again "
"after some time. If it still hasn't settled by end of day, "
"call back and we can investigate further.'"
),
),
# Processing but beyond normal SLA β needs investigation
"payment_processing_delayed": StepTransition(
message=(
"Payment has been processing longer than the standard SLA. "
"Ask: 'This payment has been processing longer than expected β "
"I'd need to connect you with our payments team to investigate "
"and ensure the funds are accounted for. Would you like me to "
"transfer you now?' Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="payments-team",
),
# Payment settled β merchant received funds
"payment_settled": StepTransition(
message=(
"Payment has settled successfully. Tell the customer: "
"'This payment was successfully settled β the merchant has received "
"the funds. If you haven't received the service or goods, I can "
"help you file a dispute.'"
),
),
# Amount debited but payment failed β refund eligible
"payment_failed_post_debit": StepTransition(
message=(
"Payment failed after the debit β amount was deducted but didn't "
"reach the merchant. This is refund-eligible. "
"Tell the customer: 'Your account was debited but the payment failed "
"before reaching the merchant β this qualifies for a refund. "
"Let me verify your identity and process that for you.' "
"Proceed with send_otp β verify_otp β initiate_refund."
),
),
# Amount returned β either cancelled, expired, or bank reversal
"payment_returned": StepTransition(
message=(
"Payment was returned or reversed. Tell the customer: "
"'This payment was returned β the funds should be back in your "
"account within 1β2 business days. If they're not reflected, "
"please call back and we can raise a manual reversal request.'"
),
),
# Gateway or technical error
"gateway_error": StepTransition(
message=(
"Payment encountered a technical/gateway error. "
"Ask: 'There was a technical error during this payment. "
"I'd like to connect you with our payments team to investigate "
"and ensure a refund is processed if the amount was deducted. "
"Would you like me to transfer you now?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="payments-team",
),
# Transaction ID not found
"transaction_not_found": StepTransition(
message=(
"Transaction not found on this account. Ask the customer to confirm "
"the ID, or use search_transactions to find it by merchant or amount."
),
),
},
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CROSS-SESSION SIGNALS
# Used by the agent when escalation is warranted by session state rather
# than a specific tool outcome.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"session": {
# Sentiment-based escalation β customer clearly frustrated
"high_frustration": StepTransition(
message=(
"Customer is showing high frustration. Acknowledge it before anything else. "
"Say: 'I completely understand how frustrating this is, and I'm sorry "
"you're going through this.' "
"Ask: 'Would you like me to connect you with a senior specialist who "
"can prioritise your case?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="senior-support",
),
# Multiple tool failures in same session
"repeated_tool_failure": StepTransition(
message=(
"Multiple tool failures detected in this session. "
"Ask: 'I'm running into a technical issue that's preventing me from "
"resolving this quickly. Would you like me to connect you with a "
"specialist who has direct system access?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="technical-support",
),
# Legal or regulatory question β out of scope for AI
"legal_or_regulatory_query": StepTransition(
message=(
"Query involves legal or regulatory matters outside AI support scope. "
"Ask: 'Questions about legal or regulatory matters need to be "
"handled by our compliance team. Would you like me to connect you "
"with them?' Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="compliance-team",
is_terminal=True,
),
# Unusually high-value transaction β enhanced security warranted
"high_value_transaction_query": StepTransition(
message=(
"High-value transaction query. For the customer's security, route to "
"senior support. Ask: 'Queries involving high-value transactions are "
"handled by our senior support team for enhanced security β would you "
"like me to connect you with them?' "
"Only call escalate_to_human if they say yes."
),
requires_consent=True,
escalation_team="senior-support",
),
# Customer explicitly requested a human agent
"customer_requested_human": StepTransition(
message=(
"Customer has explicitly asked to speak with a human agent. "
"Acknowledge and proceed: 'Of course β let me connect you with one "
"of our specialists right away.' Then call escalate_to_human immediately."
),
escalation_team="support-agent",
is_terminal=True,
),
},
}
|