Back to Architecture
instantAIguruDocumentation

System Flows

System Flows Library

This document details the standard system flows provided in the flows/system.flows.json library. These flows handle common utility tasks such as authentication, error handling, and channel switching.

Table of Contents


AuthenticateUser

ID: authenticate-user
Description: Generic flow to authenticate user via OTP sent to cell or email.

This flow acts as the primary security gatekeeper. It orchestrates the complete authentication lifecycle by first checking existing verification status. If unverified, it delegates to GetCellOrEmail to capture contact details, determines the appropriate delivery channel (SMS vs Email), and dispatches a One-Time Password (OTP). It then hands off to GetAndValidateOtpCode for user input verification, setting the auth_result variable upon success.

Parameters

  • retry_flow (string): Flow to reboot if user wants to retry (default: authenticate-user)
  • cancel_flow (string): Flow to reboot if user cancels (default: cancel-process)

Variables

  • cell_or_email (string): User cell or email
  • cell_number (string): Customer cell phone number
  • email (string): Customer email address

Flowchart

cargo.otpVerified

Default

cell_number

email

Default

On Fail

On Fail

cargo.otpVerified

Default

Start

Check Already Verified

FLOW: NoActionNeeded

FLOW: GetCellOrEmail

Send OTP

TOOL: send-sms-otp

TOOL: send-email-otp

FLOW: RetryAuthenticateGeneric

SET
Var: cargo.otp_cell_number
Value: cell_number

FLOW: RetryAuthenticateGeneric

SET
Var: cargo.otp_email
Value: email

FLOW: RetryAuthenticateGeneric

FLOW: GetAndValidateOtpCode

Check Result

SET
Var: auth_result
Value: true

FLOW: RetryAuthenticateGeneric

End


GetCellOrEmail

ID: get-cell-or-email
Description: Prompt user to provide either their cell phone number or email address for account lookup.

This flow serves as a flexible input collector for contact information. It is designed to handle ambiguity, accepting inputs that could be phone numbers or email addresses. It includes logic to parse and normalize these inputs, stripping formatting characters and validating against regex patterns. It also supports "Caller ID" usage if available from the telephony provider, and handles exit or live agent requests gracefully.

Parameters

  • retry_flow (string): Flow to reboot if user wants to retry
  • cancel_flow (string): Flow to reboot if user cancels

Flowchart

!cell & !email & callerId

!cell & !email

Default

Valid Phone

Valid Email

Caller ID Request

Abort/Exit

Live Agent

Default

Start

Check Params

SAY-GET
Var: cell_or_email
Prompt: 'To authenticate using your caller id...'

SAY-GET
Var: cell_or_email
Prompt: 'Please enter the phone or email...'

SET
Var: cell_or_email
Value: cell_number OR email

SET
Var: prospective_cell_number
Value: replace non-digits

SET
Var: prospective_email

SET
Var: prospective_email2

SET
Var: prospective_email

SET
Var: cell_or_email

Validate Input

SET
Var: cell_number

SET
Var: email

SET
Var: cell_number
Value: callerId

FLOW: cancel_flow

FLOW: LiveAgentRequested

FLOW: GenericRetryWithOptions

End


GetAndValidateOtpCode

ID: get-and-validate-otp-code
Description: Get and validate OTP code from user.

This flow manages the user interaction for entering the verification code. It informs the user where the code was sent (masking the destination for privacy), handles the input prompt, and sanitizes the user's response (removing non-digits). It delegates the actual verification logic to ValidateOtpCode.

Flowchart

Start

SET
Var: otp_destination

SET
Var: formatted_otp_destination

SAY-GET
Var: otp_code
Prompt: 'Please enter the 6-digit verification code...'

SET
Var: user_choice

SET
Var: normalized_otp_code
Value: remove non-digits

FLOW: ValidateOtpCode

End


ValidateOtpCode

ID: validate-otp-code
Description: Validate OTP code entered by user - sets cargo.otpVerified on success.

This flow encapsulates the validation logic. It calls the system tool validate-otp and evaluates the result. If the code is incorrect, it manages retry attempts or loops back to the input phase. It sets the critical cargo.otpVerified flag upon success.

Flowchart

Length 6

Exit/Abort

Live Agent

Default

On Fail

Length 6

Default

Verified

Default

Verified

Default

Start

Check Format

TOOL: validate-otp

FLOW: ContactSupport

FLOW: LiveAgentRequested

SAY
Value: 'The code must be 6 digits...'

FLOW: GetAndValidateOtpCode

Check Format Retry

SET
Var: loop

FLOW: GetAndValidateOtpCode

Check Result

SET
Var: cargo.otpVerified
Value: true

SAY
Value: 'Sorry, that code was incorrect...'

Retry Logic

SET: skip

FLOW: GetAndValidateOtpCode

End


SwitchToText

ID: switch-to-text
Description: Handles switching the interaction from Voice to SMS. Checks if already text, sends welcome SMS, and confirms.

This flow manages the channel migration from Voice to SMS. It checks if the current session is voice-based. If so, it composes a welcome message (potentially including a WhatsApp link) and uses the switch-to-sms tool to send it to the caller's ID. It then confirms the action to the user. Should be called using the "reboot" call type.

Flowchart

Not Voice

Default

On Fail

Start

Check Mode

FLOW: NoActionNeeded

SET
Var: proceed_with_sms
Value: true

SET
Var: welcome_message
Value: 'Hi, I remember our phone conversation...'

TOOL: switch-to-sms
Var: sms_result
Args: accountSid, threadId...

SAY
Value: 'I\'ve sent you a text message...'

FLOW: ContactSupport

End


LiveAgentRequested

ID: live-agent-requested
Description: Interception flow when user requests live agent. Attempts to defect to AI, then transfers if insisted.

This flow implements a deflection strategy. When a user requests a human agent, the AI first attempts to offer immediate assistance for common tasks (deflection). If the user insists (by pressing 0 or confirming), it facilitates the transfer mechanics, or informs the user if no agents are configured. Should be called using the "reboot" call type.

Flowchart

Stay with AI

Transfer

Has Number

No Number

Start

SAY-GET
Var: user_choice
Prompt: 'Before I try to transfer you...'

SET
Var: user_choice

User Choice

SAY
Value: 'Great! I\'m glad to help...'

Check Number

RETURN
Value: 'Understood. Let me transfer you...'

FLOW: ContactSupport

End


ContactSupport

ID: contact-support
Description: Provide customer service contact information.

A terminal flow that provides the user with support contact details (phone/email) when the AI cannot resolve the request or an error occurs. It supports English and Spanish localization. Should be called using the "reboot" call type.

Flowchart

Start

SET: Info EN

SET: Info ES

SAY: Contact details

End


CancelProcess

ID: cancel-process
Description: Handle flow cancellation by user. Returns a localized cancellation message.

A simple utility flow to acknowledge a user's request to stop the current operation. It returns a localized confirmation message and ends the current flow stack. Should be called using the "reboot" call type.

Flowchart

Start

RETURN: Cancellation Msg

End


NoActionNeeded

ID: no-action-needed
Description: Passive flow when no action is required, or to delegate handling back to the host.

A "noop" (no operation) flow used as a logical placeholder in branching scenarios. By returning an empty string (''), this flow signals the engine to delegate handling of the user's input back to the host application (usually a Conversational AI). This is particularly useful when a specialized flow (like a product search) is triggered but yields no results; calling NoActionNeeded allows the host AI to respond to the original prompt conversationally instead of the flow failing silently or providing a rigid error message. Should be called using the "reboot" call type.

Flowchart

Start

RETURN: ''

End


GenericRetryWithOptions

ID: generic-retry-with-options
Description: Generic flow to offer retry, switch to text, or contact support.

A comprehensive error recovery flow. It standardizes how errors are presented to users, offering explicit options to Retry (loop back), Switch to Text, or Exit. It includes "Smart Capture" capabilities to detect if the user simply answered the original question instead of navigating the menu.

Flowchart

Captured

Default

Retry/Yes

Switch Text

Abort

Default

Start

SAY-GET: Error + Retry?

SET: normalizeAndFindCapture

Smart Capture

FLOW: retry_flow

SET

User Choice

FLOW: retry_flow

FLOW: SwitchToText

FLOW: ContactSupport

FLOW: ContactSupport

End


RetryAuthenticateGeneric

ID: retry-authenticate-generic
Description: Specialized retry loop for authentication failures.

A specialized version of the retry logic tailored for authentication. It allows the user to re-enter their OTP directly if the previous attempt failed, or restart the entire authentication flow (e.g., to correct a typo in their email/phone).

Flowchart

OTP Entry

Yes/Auth

Switch Text

Live Agent

Default/Abort

Valid

Invalid

Verified

Failed

Start

SET: Clear cell/email

SAY-GET: Retry Auth?

SET

Decision

SET: Extract OTP

FLOW: AuthenticateUser

FLOW: SwitchToText

FLOW: LiveAgentRequested

FLOW: ContactSupport

Check OTP

FLOW: ValidateOtpCode

Result

SET: auth_result=true

FLOW: RetryAuthenticateGeneric

End