Showing posts with label selenium automation tool. Show all posts
Showing posts with label selenium automation tool. Show all posts

Sunday, May 25, 2025

How to Use AI Agents with SmolAgents in Python for Web Automation and Search Tasks

Build a Python AI Agent to Control Browser Using SmolAgents

In this tutorial, we'll show how to build an AI agent in Python that uses SmolAgents to perform intelligent tasks like searching the web or controlling browsers using automation tools. We'll also walk you through a working example that uses DuckDuckGo to fetch a coupon code.

๐Ÿงฐ Prerequisites

  1. Install Python (3.11 or 3.12):
    Download from python.org and make sure to check the box "Add Python to PATH" before clicking "Install Now".
  2. Install Visual Studio Code (VS Code):
    Download and install from https://code.visualstudio.com/.
  3. Install SmolAgents Library:
    Open your terminal or command prompt and run:
    python -m pip install "smolagents[openai]"
  4. Optional - Install Browser Automation Tools:
    For browser interaction using Playwright:
    pip install browseruse
    And then install Playwright browsers:
    python -m playwright install
    Also install MCP server if required, based on the browser automation setup.

๐Ÿ’ก What Are SmolAgents?

SmolAgents is a lightweight, open-source Python library created by Hugging Face that allows you to build autonomous AI agents with tools such as search engines, code execution, and browser automation.

๐Ÿงช Sample Code: Use SmolAgents to Get a Coupon Code

This example sets up a basic agent with a search tool to look for a coupon code on the website akrabtravel.com.

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
agent = CodeAgent(
    tools=[DuckDuckGoSearchTool()],
    model=HfApiModel()
)
agent.run("Get me the coupon code for flight booking on akrabtravel.com")

๐Ÿ” Explanation:

  • CodeAgent: This is the main agent type that coordinates tools and models to perform a task.
  • DuckDuckGoSearchTool: A tool that uses the DuckDuckGo search engine to fetch information from the internet.
  • HfApiModel: This uses Hugging Face's hosted models as the reasoning engine for the agent.
  • agent.run(): Executes the instruction provided and returns the result.

๐Ÿ“Œ Output

When run, the agent will intelligently search for available coupon codes related to the instruction provided and return a summary. This process is entirely autonomous and powered by AI.

๐Ÿš€ Next Steps

  • Try integrating browser automation tools like browseruse or Playwright.
  • Connect with APIs to fetch and interact with real-time content.
  • Build more complex multi-step agents using SmolAgents tools like memory or planner agents.

๐Ÿ”— Resources

Conclusion: AI agents are changing the way we interact with data, browsers, and the web. SmolAgents provides a minimal, open-source approach for building smart tools with Python. Explore it further and build your own personal AI assistant today! Also read the content understanding-AI-agents

Thursday, September 6, 2012

Selenium Testing


Selenium is automating web applications for testing purposes. Nearly all of the software applications today are written as web-based applications to be run in an Internet browser. Now a day’s many organizations are using some form of Agile methodology, test automation is frequently becoming a requirement for software projects. Test automation means using a software tool to run repeatable tests against the application to be tested.
Advantages of the automation tools are repeatability of the tests and the speed at which the tests can be executed. Selenium is possibly the most widely-used open source solution. It support for several languages (Java, JavaScript, Ruby, PHP, Python, Perl and C#) and support for almost every browser out there.

Selenium IDE - Continue Reading