acoustic-carpenter-78188
07/31/2026, 2:04 AMexamples/agents/lightpanda_browser_agent.py — an agent that browses the live web through Lightpanda, a headless browser engine written in Zig. It speaks CDP (so Playwright drives it unchanged) but ships as a single static binary with no rendering stack, which makes it light enough to install into the task image rather than run as a separate browser service.
What it shows
• Browser in the task image. with_apt_packages(...) + with_commands(...) install the Lightpanda binary at build time, so each browser tool is a durable @browser_env.task running in its own container, separate from the lightweight chat-UI app. Follows the existing flyte_agent/agent_chat_ui.py pattern (parent entrypoint task + passthrough_auth=True).
• Five tools: read_page, extract_links, extract_elements (CSS), evaluate_on_page (JS escape hatch), and read_pages — a concurrent multi-page read, since Lightpanda serves one page per CDP connection and parallelism comes from opening several.
• An A/B switch: LIGHTPANDA_MODE=cloud drives Lightpanda Cloud over wss:// instead of the in-container binary, no other code change. Every tool returns elapsed_ms and engine so the two are comparable.
• --check exercises the whole browser path locally against live sites, no cluster needed.
Verified
Deployed and run on a live cluster — the agent browsed lightpanda.io and reported real in-pod timings from `read_pages`: 1236 ms wall vs 1917 ms serial across two pages.
Two non-obvious runtime details are handled and commented, since neither is documented upstream:
• The page that arrives with a CDP connection cannot be navigated — it hangs until timeout. The context is reused (a second one is rejected) but the page must be freshly created.
• Entering async_playwright() per tool call spawns a Node driver and cost ~3 s/call; hoisting it to a per-container handle took calls from 3266 ms to 137 ms.
Also worth knowing for anyone copying the image recipe: ca-certificates is mandatory or every HTTPS navigation fails with PeerFailedVerification, and playwright install is not needed since we connect over CDP rather than launching a browser.
Caveats
Lightpanda has no renderer, so screenshots and PDFs are impossible — the agent's instructions tell it to say so rather than pretend. It is Beta software; the image pulls the nightly release asset, which you may want to pin for anything long-lived.
Docs-only change: new example file, no SDK code touched.
🤖 Generated with Claude Code
flyteorg/flyte-sdk