Skip to main content
Agent Fallback automatically spawns an AI agent when deterministic script execution fails, providing intelligent error recovery without manual intervention.

Overview

When executing session actions, failures can occur due to:
  • Elements not found
  • Unexpected page changes
  • Timing issues
  • Dynamic content
Agent Fallback catches these failures and uses an agent to recover:
agent_fallback.py

How It Works

1. Normal Execution

Actions execute normally when they succeed:

2. Automatic Recovery

When an action fails, the agent spawns:

3. Continuation

After agent recovery, remaining actions are skipped:

Use Cases

1. Fragile Selectors

Handle pages with frequently changing selectors:

2. Dynamic Content

Handle dynamically loaded content:

3. A/B Testing

Handle pages with multiple variations:

4. Graceful Degradation

Start with fast scripts, fall back to AI when needed:

Configuration

Task Description

The task guides the agent when it’s invoked:

Agent Parameters

Pass agent configuration:

Vault and Persona

Provide credentials to the agent:

Fallback Properties

Access information about the fallback execution:

Success

Whether the task was completed successfully:

Agent Response

Details from the agent if it was invoked:
Access detailed information about each execution attempt:
This is useful for debugging which specific action triggered the agent fallback.

Best Practices

1. Use for Brittle Workflows

Ideal for pages that change frequently:

2. Be Specific in Tasks

Clear tasks help the agent understand what to do:

3. Try Fast Path First

Put cheap, fast actions inside the fallback:

4. Don’t Use for Complex Logic

Fallback is for single-goal recovery, not complex workflows:

5. Monitor Fallback Rate

Track how often agents are invoked:

Limitations

Not Supported

Agent Fallback does not support:
  • session.scrape() calls
  • raise_on_failure=True on actions
  • Multiple nested fallbacks

When Not to Use

Don’t use Agent Fallback for:
  • Tasks that always fail (fix the script instead)
  • Complex multi-step workflows (use full agent)
  • Scraping/data extraction (use session.scrape or agents)
  • When you need structured output (use agent with response_format)

Error Handling

Handle failures gracefully:
error_handling.py

Next Steps

Lifecycle

Understand agent execution modes

Configuration

Configure agent parameters

Session Actions

Learn about session actions

Best Practices

Build reliable automations