Step by Step Guide to build an AI research assistant with hug face powers: Automation of web search and article summary using LLM-driven autonomous agents

Hugging Face’s Smolagents Framework provides an easy and effective way to build AI agents that utilize tools such as web search and code execution. In this tutorial, we demonstrate how to build an AI-driven research assistant who can autonomously search the web and summarize articles using smolagents. This implementation runs seamlessly and requires minimal setup and shows the power of AI agents to automate tasks in the real world, such as research, summary and collection of information.

!pip install smolagents beautifulsoup4

First, we install Smolagents Beautifulsoup4, which allows AI agents to use tools such as web search and code execution and Beautifulsoup4, a Python Library for Parsing of HTML and extract text from web pages.

import os
from getpass import getpass


# Securely input and store the Hugging Face API token
os.environ["HUGGINGFACEHUB_API_TOKEN"] = getpass("Enter your Hugging Face API token: ")

Now we are probably entering and storing the embracing face API token as an environmental variable. It uses GetPass () to get users to enter their token without showing it for security. The token is then saved in us.Nviron[“HUGGINGFACEHUB_API_TOKEN”]that allows approved access to embrace Face’s inference API to run AI models.

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel


# Initialize the model WITHOUT passing hf_token directly
model = HfApiModel()


# Define tools (DuckDuckGo for web search)
tools = [DuckDuckGoSearchTool()]


# Create the agent
agent = CodeAgent(tools=tools, model=model, additional_authorized_imports=["requests", "bs4"])

Now we initialize an AI-driven remedy using the Smolagents frame. It sets hfap model () to load a hug face API-based language model that automatically detects the hidden API token for approval. The agent is equipped with DuckduckGoSarchtool () to perform web searches. Codeagent () is also instantied with tool access and authorized imports, such as requests to make web requests and BS4 on Parsing of HTML content.

# Example query to the agent:
query = "Summarize the main points of the Wikipedia article on Hugging Face (the company)."


# Run the agent with the query
result = agent.run(query)


print("\nAgent's final answer:\n", result)

Finally, we send an inquiry to the AI ​​agent and ask it to summarize the main points of the Wikipedia article about hugging face. The Agent. Run (Inquiry) triggers the agent to perform a web search, retrieve relevant content and generate a summary using the language model. Finally, the Print () The Agent’s final response that briefly shows the requested item.

Example output

Following this tutorial, we have successfully built an AI-driven research assistant using Hugging Face Smolagents that can autonomously search the web and summarize articles. This implementation highlights the power of AI agents to automate research tasks, making it easier to retrieve and process large amounts of information effectively. In addition to web search and summary, smolagents can be expanded to various applications in the real world, including automated coding assistants, personal task administrators and AI-driven chatbots.


Here it is Colab notebook For the above project. Nor do not forget to follow us on Twitter and join in our Telegram Channel and LinkedIn GrOUP. Don’t forget to take part in our 80k+ ml subbreddit.

🚨 Recommended Reading AI Research Release Nexus: An Advanced System Integrating Agent AI system and Data Processing Standards To Tackle Legal Concerns In Ai Data Set


Asif Razzaq is CEO of Marketchpost Media Inc. His latest endeavor is the launch of an artificial intelligence media platform, market post that stands out for its in -depth coverage of machine learning and deep learning news that is both technically sound and easily understandable by a wide audience. The platform boasts over 2 million monthly views and illustrates its popularity among the audience.

🚨 Recommended Open Source AI platform: ‘Intellagent is an open source multi-agent framework for evaluating complex conversation-ai system’ (promoted)

Leave a Comment