Pathways.fallback()
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)