A production-ready web retrieval setup for Hugging Face smolagents that replaces VisitWebpageTool with a custom Zenrows fetch_page tool for retrieving webpage content as Markdown from JavaScript-rendered and protected sites.
- Replaces smolagents'
VisitWebpageToolwith a custom Zenrows fetch tool - Retrieves webpage content as clean Markdown
- Handles JavaScript-rendered and protected webpages
- Registers the custom
fetch_pagetool with a smolagentsCodeAgent - Uses Qwen through Hugging Face Inference Providers to power the CodeAgent
Before you start, make sure you have:
- Python 3.10 or higher
- A Zenrows account and API key
- A Hugging Face account and User Access Token
- Git
git clone https://github.com/Techwithpraisejames/smolagents-zenrows-tutorial.git
cd smolagents-zenrows-tutorial
python -m venv .venv
macOS/Linux
source .venv/bin/activate
Windows
.venv\Scripts\activate
pip install -r requirements.txt
Create a .env file in the project root and add your API credentials:
ZENROWS_API_KEY=your_zenrows_api_key
HF_TOKEN=your_hugging_face_token
The ZENROWS_API_KEY is used to retrieve webpage content through the Zenrows Fetch API. The HF_TOKEN is used by InferenceClientModel to access Qwen through Hugging Face Inference Providers.
Do not commit your .env file to version control.
.
├── .gitignore
├── README.md
├── agent.py
├── requirements.txt
└── zenrows_tool.py
agent.pyinitializes the Qwen model, registers thefetch_pagetool with theCodeAgent, and runs the web research task.zenrows_tool.pydefines the customfetch_pagetool.requirements.txtcontains the Python dependencies required to run the project..gitignorespecifies files and directories that Git should exclude from version control.README.mdcontains the project documentation.
The project replaces smolagents' default VisitWebpageTool with a custom Zenrows fetch_page tool.
User request
↓
CodeAgent
↓
fetch_page tool
↓
Zenrows Fetch API
↓
JavaScript-rendered or protected webpage
↓
Markdown content
↓
CodeAgent
↓
Structured response
The fetch_page function accepts a URL and sends it to the Zenrows Fetch API. The tool returns the webpage content as Markdown, which the CodeAgent can use for research, summarization, and analysis.
The @tool decorator makes fetch_page available to the CodeAgent. The agent uses Qwen through Hugging Face Inference Providers to plan the task and calls fetch_page when it needs webpage content.
Run the fetch tool directly:
python zenrows_tool.py
This tests the tool and prints a snippet of the returned Markdown content.
Run the research agent:
python agent.py
The agent retrieves the specified TechCrunch article through fetch_page, receives the webpage content as Markdown, and uses that content to complete the research task.
Running zenrows_tool.py returns webpage content as Markdown.
Running agent.py returns a structured analysis of the retrieved TechCrunch article, including:
- The company involved
- The main announcement
- The news category
- Why the announcement matters
The CodeAgent uses the content returned by Zenrows to complete the research task.
- Python
- smolagents
- Zenrows
- Hugging Face Inference Providers
- Qwen2.5-7B-Instruct
- Requests
- python-dotenv
This project is part of this blog:
Integrating Zenrows into smolagents for Production Web Access
[BLOG_URL]