Hey everyone, Emma here from agent101.net! Today, I want to talk about something that’s been buzzing in my brain for weeks: the surprisingly simple (and sometimes frustrating) journey of getting your very first AI agent to actually DO something useful. Forget the sci-fi movie stuff for a minute; we’re talking about practical, real-world mini-assistants.
A few months ago, I was deep into researching what makes an AI agent an AI agent. I mean, we’ve had chatbots for ages, right? And sophisticated scripts. But the ‘agent’ part always felt a bit… squishy. Then it clicked. It’s not just about responding; it’s about *acting* based on goals, adapting, and even learning a little bit. And my first attempt? Let’s just say it involved a lot of staring at a blank screen and questioning my life choices.
So, today’s post isn’t a deep dive into advanced agent architectures. Nope. This is for the absolute beginner, the curious tinkerer, the person who’s heard “AI agent” and thought, “Okay, but how do I actually *make* one do something cool without needing a Ph.D. in computer science?” We’re going to build a super simple, goal-oriented agent that can help you manage your digital reading list. Why reading lists? Because mine is a chaotic mess, and I figured if I can build an agent to help me, I can help you build one too!
From Idea to First Action: The Reading List Assistant
My personal struggle is this: I come across articles, blog posts, and research papers constantly. I save them, bookmark them, send them to myself – and then they just… sit there. I wanted an agent that could not only keep track of these links but also help me decide what to read next based on my interests. Ambitious for a first agent? Maybe. But let’s break it down.
What Makes an Agent, an Agent?
Before we jump into code, let’s quickly define what we’re aiming for. For our purposes, a simple AI agent needs a few key things:
- A Goal: What is it trying to achieve? (e.g., “organize my reading list,” “recommend articles”)
- Perception: How does it get information? (e.g., “I’ll give it links,” “it will read a file”)
- Action: What can it *do*? (e.g., “save to a specific list,” “summarize,” “suggest”)
- Decision-making: How does it choose its actions? (e.g., “if I see this keyword, do that”)
Our reading list agent will have the goal of helping us manage and prioritize articles. It will perceive new links, and its actions will involve categorizing and potentially summarizing them. Its decision-making will be based on simple rules we give it.
Choosing Our Tools: Keep It Simple, Stupid (KISS)
When I first thought about this, I immediately jumped to complex frameworks. Then I remembered my own advice: for beginners, start with what you know. For me, that’s Python. It’s readable, has a ton of libraries, and frankly, I can usually debug my own mistakes pretty quickly in it.
We’ll use a couple of simple Python libraries:
requests: For fetching content from URLs.BeautifulSoup(bs4): For parsing HTML and extracting text (crucial for getting article content).openai(or a similar LLM API): For summarizing and categorizing, which is where the “AI” really kicks in.
Don’t worry if you haven’t used these before. I’ll walk you through it.
Practical Example 1: The Core – Fetching and Extracting
Our agent needs to “read” an article. It can’t literally read like you or I do, but it can pull the text from a webpage. Let’s start with a function for that.
import requests
from bs4 import BeautifulSoup
def get_article_text(url):
try:
response = requests.get(url, timeout=10)
response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)
soup = BeautifulSoup(response.text, 'html.parser')
# Try to find common article content containers
# This is a bit of trial and error, but common patterns exist
article_content = soup.find('article') or soup.find('div', class_='entry-content') or soup.find('main')
if article_content:
paragraphs = article_content.find_all('p')
text = ' '.join([p.get_text() for p in paragraphs])
return text.strip()
else:
# Fallback: just get all visible text
return soup.get_text(separator=' ', strip=True)
except requests.exceptions.RequestException as e:
print(f"Error fetching URL {url}: {e}")
return None
except Exception as e:
print(f"An unexpected error occurred: {e}")
return None
# Let's test it! (replace with a real URL)
# example_url = "https://agent101.net/your-first-ai-agent-tutorial" # Use a real link for testing
# article_text = get_article_text(example_url)
# if article_text:
# print(article_text[:500] + "...") # Print first 500 characters
This function is the agent’s “eyes.” It takes a URL, fetches the page, and tries its best to pull out the main article content. Why the fallback? Because the web is messy, and not every site uses the same HTML structure for its articles. This is a common challenge when building agents that interact with external data sources – robustness is key!
Practical Example 2: The Brain – Summarizing and Categorizing with an LLM
Now for the “AI” part. We’ll use a large language model (LLM) to help us understand the article. For this, you’ll need an API key from a provider like OpenAI, Anthropic, or even Google’s Gemini. I’ll use OpenAI for this example, but the concepts are transferable.
First, make sure you have the `openai` library installed: `pip install openai`
from openai import OpenAI # Or your chosen LLM library
# Make sure to set your API key as an environment variable or load it securely
# For quick testing, you can put it here, but NOT for production!
# client = OpenAI(api_key="YOUR_OPENAI_API_KEY")
def analyze_article_with_llm(article_text, client):
if not article_text:
return "No content to analyze.", "unknown"
try:
# We'll ask the LLM to both summarize and suggest a category
response = client.chat.completions.create(
model="gpt-3.5-turbo", # Or gpt-4, or your preferred model
messages=[
{"role": "system", "content": "You are a helpful assistant that summarizes articles and suggests a single, concise category (e.g., 'AI', 'Programming', 'Marketing', 'Productivity')."},
{"role": "user", "content": f"Please summarize the following article in 3-4 sentences and suggest a single category for it. Format your response as 'Summary: [summary text]\nCategory: [category name]'.\n\nArticle: {article_text[:4000]}"} # Limit input for cost/token reasons
]
)
content = response.choices[0].message.content
summary_start = content.find("Summary:")
category_start = content.find("Category:")
summary = "N/A"
category = "Uncategorized"
if summary_start != -1 and category_start != -1:
summary = content[summary_start + len("Summary:"):category_start].strip()
category = content[category_start + len("Category:"):].strip()
elif summary_start != -1:
summary = content[summary_start + len("Summary:"):].strip()
return summary, category
except Exception as e:
print(f"Error calling LLM: {e}")
return "Failed .", "Error"
# Test with a dummy text (replace with real article_text from get_article_text)
# dummy_text = "This article discusses the latest advancements in neural networks and their application in natural language processing, specifically focusing on transformer architectures and their impact on large language models. The author also touches upon ethical considerations."
# summary, category = analyze_article_with_llm(dummy_text, client)
# print(f"Summary: {summary}\nCategory: {category}")
This is where the magic happens! We’re giving the LLM a job: read this text, summarize it, and tell me what it’s about. The `system` message is crucial here; it sets the persona and instructions for the LLM. The `user` message provides the actual article text and specifies the desired output format. This helps us parse the response reliably.
Putting It All Together: The Agent Loop (and a bit of persistence)
An agent needs to do more than just process one article. It needs to keep track of a list of articles. For our simple agent, we’ll store this in a JSON file. This gives us a basic form of “memory.”
import json
import os # For checking if file exists
READING_LIST_FILE = 'reading_list.json'
def load_reading_list():
if os.path.exists(READING_LIST_FILE):
with open(READING_LIST_FILE, 'r') as f:
return json.load(f)
return []
def save_reading_list(reading_list):
with open(READING_LIST_FILE, 'w') as f:
json.dump(reading_list, f, indent=4)
def add_article_to_list(url, title, summary, category, reading_list):
# Check if article already exists (simple check by URL)
if any(item['url'] == url for item in reading_list):
print(f"Article '{title}' already in list.")
return reading_list
article_entry = {
"url": url,
"title": title, # We'll need to extract this too!
"summary": summary,
"category": category,
"added_date": str(datetime.now().date()) # From datetime import datetime
}
reading_list.append(article_entry)
print(f"Added '{title}' to reading list under category '{category}'.")
return reading_list
# We need a way to get the title from the URL too
def get_page_title(url):
try:
response = requests.get(url, timeout=5)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
return soup.title.string if soup.title else "No Title Found"
except Exception as e:
print(f"Could not get title for {url}: {e}")
return "Unknown Title"
Okay, let’s combine it all into a basic agent “loop.”
from datetime import datetime
# Assuming get_article_text, analyze_article_with_llm,
# load_reading_list, save_reading_list, add_article_to_list,
# get_page_title functions are defined above.
# Initialize OpenAI client
# client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) # Best practice for API keys
def run_reading_list_agent(client):
reading_list = load_reading_list()
print(f"Loaded {len(reading_list)} articles from previous session.")
while True:
print("\n--- Reading List Agent ---")
print("1. Add new article")
print("2. View reading list (by category)")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1':
new_url = input("Enter the URL of the article: ")
print("Fetching article content...")
article_text = get_article_text(new_url)
if article_text:
print("Analyzing article with AI...")
summary, category = analyze_article_with_llm(article_text, client)
title = get_page_title(new_url)
# A simple check for quality
if "Failed " in summary or "Error" in category:
print("Could not process article effectively. Skipping addition.")
else:
reading_list = add_article_to_list(new_url, title, summary, category, reading_list)
save_reading_list(reading_list)
else:
print("Could not retrieve article content. Please check the URL.")
elif choice == '2':
if not reading_list:
print("Your reading list is empty!")
continue
# Group by category for better viewing
categorized_list = {}
for item in reading_list:
cat = item.get('category', 'Uncategorized')
if cat not in categorized_list:
categorized_list[cat] = []
categorized_list[cat].append(item)
for category, articles in categorized_list.items():
print(f"\n--- Category: {category} ---")
for article in articles:
print(f" Title: {article.get('title', 'N/A')}")
print(f" URL: {article['url']}")
print(f" Summary: {article.get('summary', 'N/A')[:100]}...") # Show truncated summary
print(f" Added: {article.get('added_date', 'N/A')}")
print("-" * 20)
elif choice == '3':
print("Exiting agent. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
# To run the agent:
# if __name__ == "__main__":
# # Ensure your API key is set as an environment variable or passed securely
# # For local testing, you might do:
# # import os
# # os.environ["OPENAI_API_KEY"] = "YOUR_KEY_HERE"
#
# # client needs to be instantiated if it's not global
# my_openai_client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
# run_reading_list_agent(my_openai_client)
This is a fully functional, albeit simple, AI agent! It has a goal (manage reading list), perceives (takes URLs), acts (fetches, summarizes, saves), and makes basic decisions (add, view, exit; and how to categorize). The LLM is its core “brain” for understanding content.
My own experience building this exact agent was eye-opening. The first time it correctly categorized a technical article about a niche topic I fed it, I actually did a little fist pump. It wasn’t perfect; sometimes the categories were a bit off, or the summary missed a key point, especially with very long articles. This taught me a lot about prompt engineering and the limitations of what I could expect from a free-tier LLM for complex tasks.
What I Learned (And What You Should Too!)
Building this little agent taught me a few crucial lessons for beginners:
- Start Small, Think Big: Don’t try to build Skynet on your first go. Pick a tiny, manageable problem you actually have. My reading list was perfect.
- Break It Down: An agent isn’t one monolithic block of code. It’s perception, decision, action. Separate those concerns.
- Expect Messy Data: The real world isn’t clean. Web scraping is a prime example. Your agent needs to be robust enough to handle errors or imperfect inputs.
- LLMs Are Tools, Not Magicians: They’re amazing, but they need clear instructions (prompt engineering!) and sometimes struggle with nuance or very long texts. Understand their strengths and weaknesses.
- Persistence is Key: My first attempts at `BeautifulSoup` were a disaster. My first LLM prompts gave me gibberish. Keep tweaking, keep trying.
- Memory is Crucial: Even simple agents need a way to remember past interactions or data. A JSON file is a great starting point.
Actionable Takeaways for Your First Agent
So, you’ve seen my journey. Now it’s your turn. Here’s what you should do next:
- Identify Your Own “Reading List” Problem: What’s a small, repetitive digital task you do that an agent could help with? Maybe it’s organizing downloaded files, tracking prices of items, or even just sending yourself reminders based on calendar events.
- Pick Your Language & Tools: Python is a fantastic choice for beginners. For LLMs, start with a free tier or an affordable API like OpenAI’s `gpt-3.5-turbo` or Google’s Gemini.
- Code Along: Don’t just read this. Copy the code, paste it, and try to run it. Get your API key set up (securely!). Replace my example URLs with ones you care about.
- Modify and Experiment: Once it’s running, try changing things. Can you make it ask *you* for a category if the LLM’s guess isn’t good enough? Can you add a feature to delete articles?
- Share Your Wins (and Fails!): Tell me about your first agent! What did you build? What challenges did you face? Drop a comment below or find me on social media. We’re all learning here.
Building your first AI agent isn’t about creating something that will change the world (yet!). It’s about understanding the mechanics, getting your hands dirty, and seeing the potential. It’s about that moment when your code, guided by a little bit of artificial intelligence, actually *does* something useful for you. And trust me, that feeling is pretty awesome.
Happy building!
Emma Walsh
agent101.net
🕒 Published: