Skip to content

Teapot-Agency/agent_mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Website Analyzer Agent

An intelligent website analysis tool built with OpenAI Agents SDK and GPT-5 vision that captures website screenshots and provides concise two-sentence summaries of web pages.

Features

  • πŸ–ΌοΈ Automated Screenshot Capture: Uses Playwright with headless Chromium
  • πŸ€– GPT-5 Vision Analysis: Leverages OpenAI's latest vision model for intelligent page analysis
  • 🎯 Focused Output: Exactly two sentences summarizing page purpose and key elements
  • πŸ”§ Modular Architecture: Clean separation of tools, agents, and configuration
  • 🌐 Cookie Consent Handling: Optional automatic consent button clicking
  • βš™οΈ Configurable: Customizable viewport sizes, wait conditions, and timeouts

Project Structure

agent_tool/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   └── website_analyzer.py    # Main agent implementation
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   └── screenshot.py          # Playwright screenshot tool
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── settings.py           # Configuration management
β”‚   └── cli.py                    # CLI utilities
β”œβ”€β”€ tests/
β”œβ”€β”€ main.py                       # Entry point
β”œβ”€β”€ requirements.txt              # Dependencies
β”œβ”€β”€ .env.example                 # Environment template
└── .env                         # Your configuration

Setup

1. Clone and Install Dependencies

cd agent_tool
pip install -r requirements.txt

2. Install Playwright Browsers

playwright install chromium

3. Configure Environment

Copy the example environment file and add your OpenAI API key:

cp .env.example .env

Edit .env and set your OpenAI API key:

OPENAI_API_KEY=your_openai_api_key_here

4. Verify Setup

python main.py --validate-config

Usage

Interactive Mode (Default)

python main.py

Example interaction:

🌐 Website Analyzer Agent
========================================
Powered by OpenAI Agents SDK + GPT-5 Vision

Ready to analyze websites! πŸš€
Type 'help' for available commands.

You: Analyze https://stripe.com
πŸ” Analyzing...
πŸ“ Stripe is a financial technology platform that enables businesses to accept online payments with a clean, professional design featuring their iconic purple gradient and clear "Start now" call-to-action. The homepage emphasizes trust and simplicity with prominent customer logos, straightforward pricing information, and a streamlined navigation focused on getting started quickly.

Single Query Mode

python main.py --query "Analyze https://example.com"

Available Commands

  • help - Show available commands
  • config - Display current configuration
  • quit/exit - Exit the application

Configuration Options

Edit .env to customize behavior:

# OpenAI Configuration
OPENAI_API_KEY=your_key_here
MODEL_NAME=gpt-5

# Screenshot Settings
DEFAULT_VIEWPORT_WIDTH=1280
DEFAULT_VIEWPORT_HEIGHT=800
DEFAULT_WAIT_UNTIL=networkidle
SCREENSHOT_TIMEOUT=30000

# Agent Settings
MAX_TURNS=3
VERBOSITY=low
REASONING_EFFORT=minimal

Advanced Usage

Custom Screenshot Parameters

The agent automatically handles screenshot capture, but you can provide hints in your queries:

"Analyze https://example.com and wait for the main content to load"
"Take a full page screenshot of https://news-site.com"

Cookie Consent Handling

For sites with cookie banners, you can mention it in your query:

"Analyze https://eu-website.com and handle cookie consent"

API Usage

You can also use the components programmatically:

import asyncio
from src.agents.website_analyzer import WebsiteAnalyzerAgent

async def main():
    agent = WebsiteAnalyzerAgent()
    result = await agent.analyze_website("Analyze https://example.com")
    print(result)

asyncio.run(main())

Development

Running Tests

pytest tests/

Project Structure Explanation

  • src/tools/screenshot.py: Playwright-based screenshot capture with async/sync wrappers
  • src/agents/website_analyzer.py: OpenAI Agents SDK agent with GPT-5 and custom tools
  • src/config/settings.py: Environment-based configuration management
  • src/cli.py: Interactive command-line interface utilities
  • main.py: Application entry point with argument parsing

Key Design Decisions

  1. Modular Architecture: Separate tools, agents, and configuration for maintainability
  2. Async/Sync Bridge: Playwright is async, but Agents SDK requires sync functions
  3. Temporary Files: Screenshots saved to temp files for GPT-5 vision input
  4. Error Handling: Graceful failures with two-sentence error messages
  5. Configuration: Environment-based settings for easy deployment

Troubleshooting

Common Issues

  1. "Configuration error: OPENAI_API_KEY is required"

    • Set your API key in the .env file
  2. "Screenshot capture failed: Navigation timeout"

    • Increase SCREENSHOT_TIMEOUT in .env
    • Site may be blocking automated access
  3. "Failed to initialize agent"

    • Verify OpenAI API key has sufficient credits
    • Check if gpt-5 model is available in your region
  4. Playwright installation issues

    • Run playwright install chromium
    • On Linux: install additional dependencies with playwright install-deps

Debug Mode

Set environment variable for detailed logging:

export DEBUG=1
python main.py

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Credits

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages