Use this file to discover all available pages before exploring further.
Agent Fallback automatically spawns an AI agent when deterministic script execution fails, providing intelligent error recovery without manual intervention.
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
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Add item to cart") as fb: # Try deterministic actions session.execute(type="click", selector="#add-to-cart") session.execute(type="click", selector="#checkout") # If any action fails, agent takes over automatically if fb.success: print("Task completed!") if fb.agent_invoked: print("Agent helped recover from failure")
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Submit form") as fb: session.execute(type="fill", selector="input[name='email']", value="user@example.com") session.execute(type="click", selector="button[type='submit']") # No agent spawned if all actions succeed print(f"Agent invoked: {fb.agent_invoked}") # False
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Add to cart") as fb: # This selector is wrong - action will fail session.execute(type="click", selector="#wrong-selector") # Agent automatically: # 1. Sees the failure # 2. Understands the task ("Add to cart") # 3. Finds the correct button # 4. Completes the action print(f"Agent invoked: {fb.agent_invoked}") # True print(f"Success: {fb.success}") # True (agent recovered)
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Click the submit button") as fb: # Try specific selector first (fast and cheap) session.execute(type="click", selector="button#submit-btn") # If selector changed, agent finds the button (slower but works)
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Click the popup close button") as fb: # Try clicking without waiting session.execute(type="click", selector=".popup-close") # If popup not loaded yet, agent waits and retries
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Click continue button") as fb: # Try variant A session.execute(type="click", selector="#continue-a") # If user got variant B, agent adapts
Start with fast scripts, fall back to AI when needed:
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Navigate to pricing") as fb: # Fast path - direct navigation session.execute(type="click", selector="nav a[href='/pricing']") # Slow path - agent finds the pricing link if layout changed
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Clear task description helps agent understand goal with client.AgentFallback(session, task="Add the first product to cart") as fb: session.execute(type="click", selector=".add-to-cart")
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Task") as fb: session.execute(type="click", selector="#button") if fb.success: print("Task completed successfully!") else: print("Task failed even after agent intervention")
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Extract data") as fb: session.execute(type="click", selector="#button") if fb.agent_invoked and fb.agent_response: print(f"Agent answer: {fb.agent_response.answer}") print(f"Agent steps: {len(fb.agent_response.steps)}")
Inspecting Individual Steps
Access detailed information about each execution attempt:
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Task") as fb: session.execute(type="click", selector="#btn1") session.execute(type="click", selector="#btn2") # Fails for step in fb.steps: print(f"Action: {step.action}") # The action type and parameters print(f"Success: {step.success}") # Whether this step succeeded if not step.success: print(f"Error: {step.message}") # Error message if failed
This is useful for debugging which specific action triggered the agent fallback.
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Good use case - page layout changes often with client.AgentFallback(session, task="Click pricing link") as fb: session.execute(type="click", selector="a[href='/pricing']")
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Good - specific task with client.AgentFallback(session, task="Add the blue XL t-shirt to cart") as fb: session.execute(type="click", selector="#add-to-cart") # Less clear - vague task with client.AgentFallback(session, task="Do something") as fb: session.execute(type="click", selector="#button")
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: with client.AgentFallback(session, task="Navigate to dashboard") as fb: # Fast path - direct click session.execute(type="click", selector="a[href='/dashboard']") # Agent only invoked if fast path fails
Fallback is for single-goal recovery, not complex workflows:
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Bad - too complex for fallback with client.AgentFallback(session, task="Complete entire checkout process") as fb: session.execute(type="click", selector="#cart") session.execute(type="click", selector="#checkout") session.execute(type="fill", selector="#address", value="123 Main St") # ... many more steps # Better - break into smaller fallbacks with client.AgentFallback(session, task="Click cart") as fb: session.execute(type="click", selector="#cart") with client.AgentFallback(session, task="Proceed to checkout") as fb: session.execute(type="click", selector="#checkout")
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # This will raise an error with client.AgentFallback(session, task="Task") as fb: data = session.scrape() # Not allowed # This will raise an error with client.AgentFallback(session, task="Task") as fb: session.execute(type="click", selector="#btn", raise_on_failure=True) # Not allowed
def alert_failure(message: str) -> None: logger.error(message)try: with client.Session() as session: with client.AgentFallback(session, task="Critical task") as fb: session.execute(type="click", selector="#button") if not fb.success: # Even agent couldn't complete the task alert_failure(f"Task failed: {fb.steps[-1].message}")