A walkthrough shows how to build a browser-automation agent by combining Pydantic AI with the PlaywrightBrowser capability from pydantic-ai-harness. It covers connecting to Microsoft Foundry models via Entra ID authentication, configuring Playwright options (allowed domains, timeouts, content limits, headless mode), building an agent that performs manual QA passes on a website and writes Markdown reports, instrumenting the agent with OpenTelemetry traces exported to Pydantic Logfire and Azure App Insights, and handling authenticated websites via saved session storage state. Full sample code is available on GitHub.
Table of contents
Using Pydantic AI with Microsoft Foundry modelsIntegrating Playwright capabilityCreating the Pydantic AI agentInstrumenting OpenTelemetry for inspecting the browsing activityAccessing authenticated websitesNext stepsQuestions this post answers
How do I give a Pydantic AI agent the ability to browse and interact with a website?
Integrate the PlaywrightBrowser capability from pydantic-ai-harness into a Pydantic AI agent's capabilities list. Configure options like allowed_domains to restrict navigation, block_private_addresses to prevent access to local networks, max_content_tokens to control page text size, and action/navigation timeouts, then let the agent call Playwright tools automatically during a run. daily.dev surfaces practical guides like this for teams wiring browser automation into AI agents.
How can a Playwright-based agent access a website that requires login?
Pass a storage_state to the PlaywrightBrowser instance containing cookies and local storage captured from an authenticated session. Generate that state file by running the Playwright codegen command against the target site, logging in, and saving it with --save-storage, then load that JSON file when constructing the browser so the agent inherits the logged-in session. Developers building authenticated automation flows can track patterns like this via daily.dev.
How do you monitor what an AI agent did during a Playwright browsing session?
Instrument the agent with OpenTelemetry by configuring Logfire with instrument_openai and instrument_pydantic_ai calls, which export traces following the Generative AI semantic conventions. Traces can be sent simultaneously to Pydantic Logfire, a local JSONL file, and Azure Application Insights via additional span processors, revealing which pages were visited, which commands ran, and token usage. daily.dev helps engineers stay current on observability approaches for debugging AI agent behavior.