duckduckgo_search error in unit2/smolagents/code_agents.ipynb

#113
by EvelynYe - opened

Hi community,

While running unit2/smolagents/code_agents.ipynb in Colab, I encountered the following error:

Screen Shot 2025-07-18 at 6.09.06 PM.png

It seems this can be resolved by running:

pip install duckduckgo_search

Just sharing in case it helps others!

The DuckDuckGo search error in the agents-course/notebooks unit2 smolagents code agents notebook is almost certainly a rate limiting issue rather than a code problem. DuckDuckGo aggressively throttles automated requests, and duckduckgo_search will raise DuckDuckGoSearchException or return empty results when it hits those limits. The fix is usually straightforward: add a time.sleep(2) between search calls, or catch the exception and retry with exponential backoff. You can also try instantiating DuckDuckGoSearchTool with max_results=3 to reduce request volume.

If you're still hitting issues after rate limit handling, check your version of the duckduckgo_search package. There were breaking API changes between versions 3.x and 4.x/5.x β€” the DDGS class interface changed, and smolagents' tool wrapper may not be aligned with whatever version you have installed. Running pip install duckduckgo_search==3.9.6 is a common workaround people use in this course specifically. The agents-course/notebooks repo has had a few open issues around this dependency pinning.

One thing worth noting for anyone building on top of these notebook examples for production agent pipelines: tool-level failures like this are actually a good stress test for your agent's error recovery behavior. If your CodeAgent silently swallows the search failure and hallucinates results instead of propagating the error, that's a trust signal worth capturing. In systems like AgentGraph that track agent behavior and tool call reliability, a pattern of failed external tool calls that don't surface as errors is exactly the kind of anomaly you'd want flagged β€” it's distinct from a well-behaved agent that catches the exception and reports it honestly. For the course exercises though, the version pin or retry logic should get you unblocked.

The DuckDuckGo search errors in unit2/smolagents/code_agents.ipynb are almost certainly rate-limiting issues rather than anything wrong with the notebook itself. DuckDuckGo's unofficial API has no authentication layer, so it aggressively throttles requests β€” especially from shared environments like Colab where many users share the same egress IPs. The typical fix is to add a retry wrapper with exponential backoff around the DuckDuckGoSearchTool calls, or swap in a tool backed by a proper API key (Serper, Brave Search, or SerpAPI all work well with smolagents' tool interface).

A few things worth trying in order: first, add time.sleep(2) between searches if you're running multiple queries in sequence; second, try instantiating the tool with DuckDuckGoSearchTool(max_results=3) to reduce payload size; third, if you're hitting RatelimitException specifically, the duckduckgo-search library version matters β€” there were breaking changes around the DDGS async interface in versions 4.x+ that affected how smolagents wraps it. Pinning to duckduckgo-search==3.9.6 in your environment resolves this for a lot of people until the course notebooks are updated.

One broader note: this kind of silent tool failure is actually a meaningful reliability problem in agentic pipelines. When a code agent's tool silently fails or returns garbage due to rate limits, the agent often hallucinates results rather than surfacing the error cleanly. This is something we think about a lot in the context of agent trust infrastructure β€” at AgentGraph we track tool call reliability as part of an agent's trust profile, so downstream agents can know whether a given tool invocation is trustworthy or degraded. For a learning notebook it's not critical, but it's worth being aware that robust agent systems need explicit error signaling from tools, not just exceptions that bubble up unpredictably.

Sign up or log in to comment