This document outlines the detailed step-by-step process for building an OpenAI Agents SDK agent that captures website screenshots and analyzes them using GPT-5 vision capabilities.
An OpenAI Agents SDK agent that:
- Calls a custom tool to open a URL in headless Chromium and capture a screenshot
- Sends that image to
gpt-5to visually analyze it - Replies in exactly two sentences about what's on the page
- Python 3.10+
openai-agentspackage- Headless browser stack (Chromium via Playwright)
- OpenAI API key (set
OPENAI_API_KEYenvironment variable)
pip install openai-agents
pip install playwright
playwright install chromium- Name:
capture_screenshot - Purpose: Launch Chromium headless, navigate to URL, capture PNG screenshot
url(string, required) - Target website URLfull_page(bool, defaulttrue) - Capture full page or viewport onlyviewport_width(int, default 1280) - Browser viewport widthviewport_height(int, default 800) - Browser viewport heightwait_until(enum, defaultdomcontentloaded) - Navigation wait conditionwait_for_selector(optional string) - CSS selector to wait for before captureconsent_click_selector(optional string) - Selector for cookie consent buttons
- Image payload suitable for vision analysis (file path or base64)
- Prefer file upload/URL over raw base64 for large images to keep prompts light
- Register Python function as Function Tool in Agents SDK
- SDK auto-derives JSON schema from function signature & docstring
- Add tool to Agent with
model="gpt-5" - Use Responses-model path for image input handling
- Model:
gpt-5(orgpt-5-minifor testing) - Tools: [capture_screenshot function]
- Response format: Support image inputs
When the `capture_screenshot` tool is available and the user asks about a website, **always** call it first.
Analyze the returned image and reply with **exactly two sentences** describing:
- The page's purpose and brand
- Prominent elements (hero, headline, primary CTA)
- Any obvious trust signals
If the screenshot fails, acknowledge the failure in exactly two sentences.
verbosity = low- Keep responses concisereasoning_effort = minimal- Fast, direct answersmax_turns = 2-3- Prevent infinite loops
- User input: "Summarize https://example.com in two sentences"
- Agent planning: Identifies need for screenshot tool
- Tool execution: Headless Chromium captures PNG screenshot
- Model analysis: GPT-5 analyzes image with vision capabilities
- Response generation: Exactly two sentences describing the page
- Output: Final answer delivered to user
- Viewport: 1280×800 pixels
- Wait condition:
networkidlefor full page load - Image format: Compressed PNG
- Quality: Balance between detail and cost
- Navigation timeouts: Return structured error message
- Cookie walls: Optional consent button clicking
- Failed screenshots: GPT-5 acknowledges failure in two sentences
- Image compression for cost control
- Timeout limits on browser operations
- Structured error responses
- First-class Function Tools integration
- Simple Runner loop management
- Built-in tracing capabilities
- Seamless OpenAI models & tools integration
- Strong tool-use reliability
- Precise control over verbosity and reasoning effort
- Excellent vision analysis capabilities
- Consistent two-sentence output formatting
- Agent consistently calls screenshot tool for URL requests
- Screenshots capture stable page content (no blocking overlays)
- Model output never exceeds two sentences
- Summaries focus on purpose + key CTAs, not boilerplate UI text
- News website homepage
- E-commerce product page
- SaaS company landing page
- Site with cookie consent banners
- Hosted Computer Tool: Use SDK's Computer Tool instead of custom Playwright
- WebSearch Fallback: Add WebSearchTool for blocked/failed screenshots
- Sessions: Implement persistent context for follow-up questions
- Multiple viewport sizes for responsive testing
- Element-specific screenshot targeting
- Performance metrics collection
- Batch URL processing
- Phase 1: Basic screenshot tool with Playwright
- Phase 2: Agents SDK integration and GPT-5 analysis
- Phase 3: Error handling and guardrails
- Phase 4: Testing and optimization
- Phase 5: Optional extensions and enhancements