Context
Critical operations with backup options.
Problem
Tool unavailability blocks the entire workflow.
Solution
Implement fallbacks:
- Primary tool: Preferred option
- Fallback tool: Alternative when primary fails
- Automatic: Switch transparently
- Or explicit: Return fallback suggestion
- Primary tool: Preferred option
- Fallback tool: Alternative when primary fails
- Automatic: Switch transparently
- Or explicit: Return fallback suggestion
Examples
Python
@tool
def send_notification(
user_id: str,
message: str,
preferred_channel: str = "slack"
) -> NotifyResult:
"""Send notification with automatic fallback.
Tries preferred channel first, falls back to alternatives
if unavailable.
"""
channels = get_fallback_order(preferred_channel)
# e.g., ["slack", "email", "sms"]
for channel in channels:
try:
result = send_via_channel(channel, user_id, message)
return NotifyResult(
success=True,
channel_used=channel,
was_fallback=channel != preferred_channel
)
except ChannelUnavailable:
continue
raise ToolError(
"All notification channels unavailable",
tried_channels=channels
) Considerations
- Document the fallback order
- Indicate when fallback was used
- Consider user preferences in fallback order