Pathways.fallback()method

Define fallback transition when normal state progression fails.

USAGE

Pathways.fallback(condition, state_name)

Use when you need to handle error conditions, user confusion, or when expected outcomes don’t occur. Provides graceful recovery paths instead of getting stuck in a state.

Parameters

condition : str

Specific condition that triggers the fallback. Usually describes a failure or unexpected situation.

state_name : str

State to transition to when fallback condition occurs.

Returns

Pathways

Self for method chaining, allowing combination with other pathway building methods to create comprehensive conversation flows.

Integration Notes

  • Error Handling: use for error handling and recovery from unexpected situations
  • Graceful Degradation: provides graceful degradation instead of getting stuck
  • Failure Scenarios: condition should describe failure scenarios clearly
  • Combined Usage: can be used alongside .next_state() or .branch_on()
  • Stuck Prevention: ensures conversations don’t get stuck when expected outcomes don’t occur
  • Recovery Paths: provides alternative paths for complex scenarios and edge cases

The .fallback() method ensures conversations don’t get stuck when expected outcomes don’t occur, providing alternative paths for complex scenarios and edge cases.

Examples


Complete pathway showing .fallback() providing graceful error recovery:

import talk_box as tb

# Creating a complex problem-solving pathway with fallbacks
pathway = (
    tb.Pathways(
        title="Technical Problem Resolution",
        desc="systematic approach to solving technical issues",
        activation="user encounters a technical problem"
    )
    # === STATE: problem_analysis ===
    .state("problem analysis: understand the problem details")
    .required(["problem description", "system context", "error details"])
    .success_condition("problem is clearly defined")
    .next_state("solution_attempt")
    # === STATE: solution_attempt ===
    .state("solution attempt: apply standard solution")
    .required(["solution is implemented", "results are verified"])
    .success_condition("problem is resolved")

    # .fallback() handles situations where standard solutions don't work ---
    .fallback("solution doesn't resolve the issue", "advanced_troubleshooting")

    .next_state("completion")
    # === STATE: advanced_troubleshooting ===
    .state("advanced troubleshooting: advanced diagnostic procedures")
    .tools(["system_diagnostics", "log_analyzer", "network_tracer"])
    .required("root cause is identified")
    .success_condition("advanced solution is implemented")

    # .fallback() provides escalation when even advanced methods fail -----
    .fallback("issue remains unresolved after advanced diagnostics", "expert_escalation")

    .next_state("completion")

    # === STATE: expert_escalation ===
    .state("expert escalation: escalate to specialist support")
    .required(["detailed case summary", "expert is contacted"])
    .success_condition("case is transferred to appropriate specialist")
    .next_state("completion")
    # === STATE: completion ===
    .state("completion: confirm resolution and document")
    .required(["resolution is confirmed", "case is documented"])
    .success_condition("issue fully resolved and documented")
)

# See how fallbacks provide multiple recovery paths
print(pathway)
**Technical Problem Resolution**
Purpose: systematic approach to solving technical issues
Activate when:
- user encounters a technical problem
Flow guidance:
- PROBLEM_ANALYSIS (collect): problem analysis: understand the problem details
  Required: (1) problem description, (2) system context, (3) error details
  Success: problem is clearly defined
- SOLUTION_ATTEMPT (collect): solution attempt: apply standard solution
  Required: (1) solution is implemented, (2) results are verified
  Success: problem is resolved
- COMPLETION (collect): completion: confirm resolution and document
  Required: (1) resolution is confirmed, (2) case is documented
  Success: issue fully resolved and documented
Follow as flexible guidance, adapting to user conversation patterns while ensuring key objectives
are addressed.
/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/talk_box/pathways.py:561: UserWarning: State 'advanced_troubleshooting' was inferred as 'tool' but method suggests 'collect'. Keeping first inference 'tool'.
  warnings.warn(