Getting smolagents to handle protected and JS-rendered pages without a browser stack

Reddit r/ArtificialInteligence Tools

Summary

The author describes replacing smolagents' built-in VisitWebpageTool with a custom fetch tool using services like ZenRows to handle protected and JS-rendered web pages, improving web data access for AI agents without requiring a browser stack.

I have been building small research agents with Hugging Face smolagents, and the built-in VisitWebpageTool works fine on static HTML, but breaks on protected or JavaScript-heavy pages. On a Walmart product page, it returned the bot-check text ("Robot or human?") instead of product data, and the agent still reasoned over that as if it were real content. That is a problem when the whole workflow depends on live web data. The fix I implemented was to replace VisitWebpageTool with a custom fetch tool that can handle anti-bot measures and JS rendering, and then plug it directly into the CodeAgent. In my case, I used ZenRows as the fetch layer, but the pattern would work with any trusted retrieval backend. Here was my idea: Define a fetch_page(url: str) -> str function with the tool decorator. In the docstring, describe what the tool does and when to use it, because smolagents builds the tool description the model sees from the function signature and docstring at runtime. Register this tool in the CodeAgent's tools list alongside the model and any other tools you need. In the agent prompt, ask it to use fetch_page for any URL retrieval instead of relying on built-in browsing. This gives the agent full Markdown support from dynamic and protected pages without requiring you to maintain your own browser or proxy stack, and without changing the overall CodeAgent workflow. How do you folks handle web access in smolagents or similar frameworks: custom fetch tools, MCP servers, or your own Playwright setup?
Original Article

Similar Articles