Overview
When executing session actions, failures can occur due to:- Elements not found
- Unexpected page changes
- Timing issues
- Dynamic content
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:Inspecting Individual Steps
Inspecting Individual Steps
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()callsraise_on_failure=Trueon 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)

