This video shows you how to turn the Hugging Face Smolagents library and a local Ollama-hosted open source LLM (such as Qwen 3, DeepSeek-R1-0528, or Gemma 3) into a web-connected AI research agent that outputs clean JSON structured outputs. It shows you how to install the AI tech stack, enable the new use_structured_outputs_internally feature, and write less than 20 lines of Python code to make the agent search the web, run inline calculations, and build a Pandas DataFrame.
This tutorial includes step-by-step environment setup as well as showing you how to leverage the CodeAgent, WebSearchTool, and LiteLLMModel modules of the Smolagents library to do live web search. This workflow shows you how to automate and create a full dataset based on a prompt and a list of subjects/topics and requested data fields. You can expand and customize it for your own purposes, and you can do this all on your laptop without any cloud API costs that you would need with OpenAI or Google Gemini.
ENVIRONMENT
CODE
# Web-Connected AI Research Agent (Smolagents + Ollama)
### Initial Setup
import pandas as pd
from smolagents import CodeAgent, WebSearchTool, LiteLLMModel
model = LiteLLMModel(model_id="ollama_chat/qwen3:8b")
agent = CodeAgent(
tools=[WebSearchTool()],
model=model,
use_structured_outputs_internally=True,
max_steps=4
)
### Do 1 Run
result = agent.run(
"Give one fun fact about the Great Barrier Reef as a JSON object with keys fact and word_count."
)
print(result)
### Build entire dataset
topics = [
("Great Barrier Reef", ["fact", "word_count"]),
("Mount Everest", ["fact", "word_count"]),
("Saturn", ["fact", "word_count"]),
]
rows = []
for subject, keys in topics:
prompt = (
f"Give one fun fact about {subject} as a JSON object "
f"with keys {keys[0]} and {keys[1]}."
)
out = agent.run(prompt)
if isinstance(out, dict):
out["subject"] = subject
rows.append(out)
else:
print("Skipping non-dict output:", out)
pd.DataFrame(rows)
Subscribe to the Deep Charts YouTube Channel for more informative AI and Machine Learning Tutorials.