DEV Community

Cover image for I Built an Autonomous AI Agent with Google ADK + Gemini That Spots Trends and Drafts Dev.to Articles for Me

I Built an Autonomous AI Agent with Google ADK + Gemini That Spots Trends and Drafts Dev.to Articles for Me

Keeping up with trending technical topics and new tools on developer forums can be time-consuming. To save time, I wanted to automate the process of finding popular articles, reading the comments to understand community sentiment, and drafting a summary.

While I could write a standard Python script to scrape the dev.to API, simple scripts tend to be brittle. If an article doesn't have comments yet, a basic script will likely crash unless you write extensive error-handling logic.

Instead of a rigid script, I built an Agent—a program that can dynamically reason about errors and adjust its approach. If one task fails, it can figure out the next best step.

In this tutorial, I'll show you how to build a Trend-Spotting Agent using Python, the Google Agent Development Kit (ADK), and Gemini 2.5 Flash.

What We're Building

We are going to write a Python application that acts as an autonomous agent. We'll give it three abilities:

  1. Search the dev.to API for rising technical articles based on specific tags.
  2. Dynamically fetch the top comments of those articles to read real community sentiment.
  3. Automatically draft a newsletter-style article on your DEV.to account summarizing its findings.

Prerequisites

  • Python 3.9+ installed on your machine.
  • Google ADK. (Check out the Google ADK Docs if you need help installing).
  • A DEV API Key. Grab this from your DEV.to account settings under "Extensions" and throw it in a .env file.

Step 1: Giving the Agent its "Hands" (API Tools)

Large Language Models (LLMs) are incredibly smart, but out of the box, they can't actually do anything on your computer.

The coolest part about Google ADK is that we can write standard Python functions, hand them to the LLM as "tools", and let the AI decide how and when to use them.

Let's write our API functions.

Tool 1: Finding Rising Articles

Here is our function to fetch rising articles. Pay close attention to the docstring ("""Fetches the top..."""). We aren't writing this for other developers; the ADK actually passes this docstring directly to the LLM so it understands exactly what the tool does.

import os
import requests

DEV_API_KEY = os.getenv("DEV_API_KEY")

def get_rising_articles(tag: str, limit: int = 5) -> str:
    """
    Fetches the top rising articles for a specific tag on DEV.to.
    Returns a formatted string of the articles with their ID, title, and URL.
    """
    url = f"https://dev.to/api/articles?tag={tag}&state=rising&per_page={limit}"
    response = requests.get(url, timeout=10)

    if response.status_code == 200:
        articles = response.json()
        summary = f"Top {limit} rising articles for '{tag}':\n"
        for i, article in enumerate(articles):
            summary += f"{i+1}. {article['title']} (ID: {article['id']})\n"
        return summary
    else:
        return f"Error fetching articles: {response.status_code}"
Enter fullscreen mode Exit fullscreen mode

Tool 2: Fetching Community Comments

We don't just want our agent to read article titles; we want it to know what the community thinks. This function fetches the comments for a given article.

def fetch_comments(article_id: int) -> str:
    """
    Fetches the top comments for a specific DEV.to article by ID to gauge community sentiment.
    """
    url = f"https://dev.to/api/comments?a_id={article_id}"
    response = requests.get(url, timeout=10)
    comments = response.json()

    if not comments:
        return "No comments found on this article."

    summary_blocks = []
    # Grab up to the top 5 comments
    for i, c in enumerate(comments[:5]):
        user = c.get('user', {}).get('name', 'Anonymous')
        body = c.get('body_html', '').replace('<p>', '').replace('</p>', '').strip()
        summary_blocks.append(f"Comment {i+1} by {user}: {body}")

    return "Top Comments:\n" + "\n".join(summary_blocks)
Enter fullscreen mode Exit fullscreen mode

Tool 3: The Ghostwriter

Finally, we need a way for the agent to report back. This function takes the agent's research and POSTs it directly to your Dev.to dashboard as an unpublished draft.

def create_article_draft(title: "str, body_markdown: str, tags: list[str]) -> str:"
    """
    Creates a new, unpublished article Draft on the user's DEV.to account.
    """
    url = "https://dev.to/api/articles"
    headers = {
        "api-key": DEV_API_KEY,
        "Content-Type": "application/json"
    }
    payload = {
        "article": {
            "title": title,
            "published": False,  # Keeps it as a safe draft!
            "body_markdown": body_markdown,
            "tags": tags[:4]
        }
    }

    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 201:
        data = response.json()
        return f"Successfully created draft! URL: {data.get('url')}"
    return "Failed to create draft."
Enter fullscreen mode Exit fullscreen mode

Step 2: Wiring up the Agent

With our tools ready, we just need to initialize the Google ADK Agent. We give it a persona, drop in our functions, and let it go to work.

from google.adk.agents import Agent
from google.genai import types

agent_instruction = """
You are a Trend-Spotting Research Agent.
Every morning, or when requested, you monitor specific tags on DEV (Forem) to find the most interesting emerging technologies or topics.

Your workflow:
1. Use the 'get_rising_articles' tool to fetch the top rising articles.
2. Use the 'fetch_comments' tool on the most popular articles to evaluate the community's sentiment.
3. Synthesize the articles and the sentiment into an insightful trend report.
4. Use the 'create_article_draft' tool to automatically generate an unpublished DEV.to article containing your full synthesized report.
"""

root_agent = Agent(
    model="gemini-2.5-flash",
    name="trend_spotting_agent",
    description="Spots rising trends on DEV community and automatically drafts digest articles.",
    instruction=agent_instruction,
    # Here is where we hand over our Python functions!
    tools=[get_rising_articles, fetch_comments, create_article_draft],

    # Optional: configure automatic HTTP retries just in case the API drops
    generate_content_config=types.GenerateContentConfig(
        http_options=types.HttpOptions(
            retry_options=types.HttpRetryOptions(initial_delay=10, attempts=3)
        )
    )
)
Enter fullscreen mode Exit fullscreen mode

And that is literally all the setup we need.


The "Aha!" Moment

To test this out, I spun up the ADK interface in my terminal (adk web) and gave the agent a fairly complex prompt:

"I need a complete trend analysis for the 'machinelearning' tag. Fetch the top 5 rising articles. Read the comments on the top article to gauge what the community actually thinks. Synthesize this research and draft a new DEV.to article for me titled 'The Community Pulse'."

I watched the terminal logs, and this is where the power of an Agentic workflow really clicked for me.

The agent easily retrieved the list of articles. It then grabbed the ID of the #1 article and called our fetch_comments(id) tool.

But there was a problem. Because it was a rapidly rising article, nobody had actually commented on it yet.

If this was a traditional scripted loop, the program would have just returned an empty array, moved on to the writing phase, and published a broken, empty newsletter.

But because this is an Agent, it analyzed the tool's response ("No comments found on this article.") and realized it couldn't complete my request. Without any prompting from me, the logs showed the agent dynamically pivoting:

"Okay, no comments on that one. Let's try the next most interesting one, 'Chapter 1: The Value Class'."
(Calls tool)
"Okay, no comments there either. Let's try 'Building a GPT From Scratch'."
(Calls tool)
"Still no comments. Last try, let's check 'Prove You're 18 Without Showing Who You Are'."

It iterated through the list, dynamically feeding the output of our tool back into its own reasoning loop until it successfully found a lively debate! It then analyzed the sentiment and proceeded to the final step.

With the research complete, the agent executed its final tool: create_article_draft().

When I opened my DEV.to dashboard, I had a fully formatted Markdown article sitting as an unpublished draft, ready for me to review.

Final Thoughts

Connecting normal REST APIs to the Google ADK framework completely changes how you think about automation. You don't need to write exhaustive edge-case logic or endless try/except blocks anymore.

You just build reliable, single-purpose tools, hand them over, and let the LLM figure out how to navigate the road bumps.

If you want to see the full source code for this project, you can check it out on my GitHub here: Link to Repo.

Let me know in the comments if you've built any interesting agents lately, and I'll see you in the next one!

Top comments (0)