Skip to main content
*This notebook has been sourced and adapted from the original Meta notebook “Building an Intelligent Browser Agent with Llama 4 Scout”** . (Authors_: _**Miguel Gonzalez, Dimitry Khorzov)

Notebook Tutorial

Blog and Demo Video

Architecture: The Planning and Execution Framework

System Components

Our browser agent combines four core technologies: Llama 4 Scout is a vision-language model from Meta that provides multi-modal understanding. Unlike traditional LLMs that only process text, Llama 4 Scout analyzes both screenshots and textual descriptions simultaneously. The model reasons about page structure, identifies interactive elements, and makes decisions about how to navigate and interact with web interfaces. Playwright is our browser automation framework. Playwright executes actions like clicking buttons, filling forms, and navigating to URLs. Critically, it also extracts the accessibility tree—a browser-native representation of page elements designed for assistive technologies. Together AI hosts our Llama model, providing fast and reliable API access. Together AI supports multi-modal inputs (text + images), making it ideal for our real-time agent interactions where we need to send both accessibility tree text and screenshot images to the model with each decision. Arize captures distributed traces showing the hierarchical relationship between planning, execution, and individual actions. This visibility is crucial for debugging multi-step workflows, understanding failure points, and optimizing performance in production.

Two-Phase Agent Design

Phase 1: The Planning Agent

The planning agent receives a natural language task and decomposes it into high-level actionable steps. This plan serves as a roadmap, providing context about the overall goal while leaving flexibility in execution. These steps are fed to the execution agent to execute the plan.

Phase 2: The Execution Agent

The executor translates high-level plans into concrete browser actions through an iterative loop:
  1. Context Gathering: At each step, capture the current browser state including a screenshot of the visible page and the accessibility tree. The screenshot provides visual context about layout and content positioning, while the accessibility tree offers a machine-readable map of interactive elements (buttons, text fields, links).
  2. Decision Making: Feed the multi-modal context (screenshot + accessibility tree + task + previous actions) to Llama 4 Scout. The model analyzes this information and decides the next action, returning a structured JSON response with explicit reasoning about its current state and why a particular action is appropriate.
  3. Action Execution: Based on the LLM’s decision, execute the corresponding browser command. This might be navigating to a URL, clicking an element using role-based selectors (e.g., “button=Search”), or filling a text field.
  4. Validation: After executing an action, verify success and capture any errors. Failed actions (selector not found, timeout) are logged with context and included in the next decision cycle, allowing the model to learn from mistakes and try alternative approaches.
  5. State Update: Results are logged to Arize AX traces, and the agent updates its context with what just happened.
The execution loop continues until the task completes (action type “finished”) or reaches a maximum iteration limit.

Arize AX Observability

All traces from the browser agent will be captured and viewable in Arize AX. Below are screenshots of Arize Agent Graph and Sankey visualizations that capture the Planning agent and Execution agent workflows. Agent Graph View alt text Sankey View alt text

Code Walkthrough

Import Libraries + Set up Instrumentation

Helper Functions

Agent uses an accessibility tree to understand the web page components and interact with it

Define prompts

Define a Task

Execute Planning Agent

Create Browser Environment and Run Executor Agent

To create robust observability and agent visualization, we apply custom opentelemetry instrumentation.
Resources:
  1. Project repository
  2. Watch the demo video