What is smolagents?
Hugging Face's lightweight framework for building AI agents. Minimal, code-first approach to agent development.
Searching Reddit Comments Tree with smolagents
This integration lets your smolagents agent search Reddit Comments Tree in real time via the Scavio API. The agent gets back structured JSON with comment text, authors, scores, depth -- ready for reasoning and decision-making.
Setup
pip install smolagents requestsCode Example
Here is a complete smolagents agent that searches Reddit Comments Tree using Scavio:
from smolagents import tool, CodeAgent, HfApiModel
import json
import os
import requests
# Comments are fetched per post: get a post_id from POST /api/v1/reddit/search, or resolve a URL with POST /api/v1/reddit/post. Deeper replies come from POST /api/v1/reddit/post/comments/replies using a row's reply_cursor.
@tool
def scavio_search(query: str) -> str:
"""Query Reddit Comments Tree through the Scavio API (POST /api/v1/reddit/post/comments).
Args:
query: What to look for.
"""
response = requests.post(
"https://api.scavio.dev/api/v1/reddit/post/comments",
headers={
"Authorization": "Bearer " + os.environ["SCAVIO_API_KEY"],
"Content-Type": "application/json",
},
json={"post_id": query, "sort": "TOP"},
timeout=60,
)
response.raise_for_status()
return json.dumps(response.json())
agent = CodeAgent(tools=[scavio_search], model=HfApiModel())
result = agent.run("t3_1u1143i")
print(result)Full Working Example
A production-ready example with error handling:
from smolagents import tool, CodeAgent, HfApiModel
import json
import os
import requests
# Comments are fetched per post: get a post_id from POST /api/v1/reddit/search, or resolve a URL with POST /api/v1/reddit/post. Deeper replies come from POST /api/v1/reddit/post/comments/replies using a row's reply_cursor.
@tool
def scavio_search(query: str) -> str:
"""Query Reddit Comments Tree through the Scavio API (POST /api/v1/reddit/post/comments).
Args:
query: What to look for.
"""
response = requests.post(
"https://api.scavio.dev/api/v1/reddit/post/comments",
headers={
"Authorization": "Bearer " + os.environ["SCAVIO_API_KEY"],
"Content-Type": "application/json",
},
json={"post_id": query, "sort": "TOP"},
timeout=60,
)
response.raise_for_status()
return json.dumps(response.json())
agent = CodeAgent(tools=[scavio_search], model=HfApiModel())
result = agent.run("t3_1u1143i")
print(result)Pricing
Scavio offers a free tier with 50 credits on signup (1 credit per search). No credit card required. This is enough to build and test your smolagents integration. Paid plans start at $30/month for higher volumes.