Agentic AI 101: Starting Your Journey Building AI Agents

Learn the fundamentals of how to create AI Agents. The post Agentic AI 101: Starting Your Journey Building AI Agents appeared first on Towards Data Science.

May 2, 2025 - 07:59
 0
Agentic AI 101: Starting Your Journey Building AI Agents

Introduction

The Artificial Intelligence industry is moving fast. It is impressive and many times overwhelming.

I have been studying, learning, and building my foundations in this area of Data Science because I believe that the future of Data Science is strongly correlated with the development of Generative AI.

It was just the other day when I built my first Ai Agent, and then a couple of weeks after that, there were several Python packages to choose from, not to mention the no-code options that are doing very well, like n8n.

From “mere” models that could just chat with us to a tsunami of AI Agents that are everywhere, searching the Internet, handling files, and making whole Data Science projects (from EDA to modeling and evaluation), all of that happened in just a couple of years.

What?

Seeing all of that, my thought was: “I need to get on board as soon as possible”. After all, it’s better to surf the wave than be swallowed by it.

For that reason, I decided to start this series of posts where I plan to go from the fundamentals to build our first AI Agent, until more complex concepts.

Enough talk, let’s dive in.

The Basics of AI Agents

An AI Agent is created when we give the Llm the power to interact with tools and perform useful actions for us. So, instead of being just a chatbot, now it can schedule appointments, take care of our calendar, search the internet, write social media posts, and the list goes on…

AI Agents can do useful things, not just chat.

But how can we give that power to an LLM?

The simple answer is to use an API to interact with the LLM. There are several Python packages for that nowadays. If you follow my blog, you will see that I have already tried a couple of packages to build agents: Langchain, Agno (former PhiData), and CrewAI, for instance. For this series, I will stick with Agno [1].

First, set up a virtual environment using uv, Anaconda, or the environment handler of your preference. Next, install the packages.

# Agno AI
pip install agno

# module to interact with Gemini
pip install google-generativeai

# Install these other packages that will be needed throughout the tutorial
 pip install agno groq lancedb sentence-transformers tantivy youtube-transcript-api

Quick note before we continue. Don’t forget to get a Google Gemini API Key [2].

Creating a simple agent is very simple. All the packages are very similar. They have a class Agent or something similar that allows us to select a model and start interacting with the LLM of our choice. Here are the main components of this class:

  • model: the connection with the LLM. Here we will choose between OpenAI, Gemini, Llama, Deepseek etc.
  • description: This argument lets us describe the behavior of the agent. This is added to the system_message, which is a similar argument.
  • instructions: I like to think of an agent like an employee or an assistant that we’re managing. In order to have a task done, we must provide the instructions of what needs to be done. Here is where you can do that.
  • expected_output: Here we can give instructions about the expected output.
  • tools: This is what makes the LLM an Agent, enabling it to interact with the real world using these tools.

Now, let’s create a simple agent that has no tools, but will serve to build our intuition around the structure of the code.

# Imports
from agno.agent import Agent
from agno.models.google import Gemini
import os

# Create agent
agent = Agent(
    model= Gemini(id="gemini-1.5-flash",
                  api_key = os.environ.get("GEMINI_API_KEY")),
    description= "An assistant agent",
    instructions= ["Be sucint. Answer in a maximum of 2 sentences."],
    markdown= True
    )

# Run agent
response = agent.run("What's the weather like in NYC in May?")

# Print response
print(response.content)
########### OUTPUT ###############
Expect mild temperatures in NYC during May, typically ranging from the low 50s 
to the mid-70s Fahrenheit.  
There's a chance of rain, so packing layers and an umbrella is advisable.

That is great. We are using the Gemini 1.5 model. Notice how it responds based on the data it was trained on. If we ask it to tell us the weather today, we’ll see a response saying it can’t access the internet.

Let’s explore the instructions and expected_output arguments. We now want a table with the month, season and average temperature for NYC.

# Imports
from agno.agent import Agent
from agno.models.google import Gemini
import os

# Create agent
agent = Agent(
    model= Gemini(id="gemini-1.5-flash",
                  api_key = os.environ.get("GEMINI_API_KEY")),
    description= "An assistant agent",
    instructions= ["Be sucint. Return a markdown table"],
    expected_output= "A table with month, season and average temperature",	
    markdown= True
    )

# Run agent
response = agent.run("What's the weather like in NYC for each month of the year?")

# Print response
print(response.content)

And there’s the result.

MonthSeasonAverage Temperature (°F)
JanuaryWinter32
FebruaryWinter35
MarchSpring44
AprilSpring54
MaySpring63
JuneSummer72
JulySummer77
AugustSummer76
SeptemberAutumn70
OctoberAutumn58
NovemberAutumn48
DecemberWinter37

Tools

The previous responses are nice. But we naturally don’t want to use powerful models such as LLMs to play with a chatbot or tell us old news, right?

We want them to be a bridge to automation, productivity, and knowledge. So, the Tools will add capabilities to our AI Agents, building, therefore, the bridge with the real world. Common examples of tools for agents are: searching the web, running SQL, sending an email or calling APIs.

But more than that, we can create custom capabilities to our agents by using any Python function as a tool.

Tools are functions that an Agent can run to achieve tasks.

In terms of code, adding a tool to the Agent is just a matter of using the argument tools in the Agent class.

Imagine a solopreneur (one-person company) in the healthy living business who wants to automate their content generation. This person posts tips about healthy habits every day. I know for a fact that content generation is not as straightforward as it looks like. It demands creativity, research, and copywriting skills. So, if this could be automated, or at least part of it, that’s time saved.

So we write this code to create a very simple agent that can generate a simple Instagram post and save it to a markdown file for our review. We reduced the process from thinking > researching > writing > reviewing > posting to reviewing > posting.

# Imports
import os
from agno.agent import Agent
from agno.models.google import Gemini
from agno.tools.file import FileTools

# Create agent
agent = Agent(
    model= Gemini(id="gemini-1.5-flash",
                  api_key = os.environ.get("GEMINI_API_KEY")),
                  description= "You are a social media marketer specialized in creating engaging content.",
                  tools=[FileTools(
                      read_files=True, 
                      save_files=True
                      )],
                  show_tool_calls=True)


# Writing and saving a file
agent.print_response("""Write a short post for instagram with tips and tricks
                        that positions me as an authority in healthy eating 
                        and save it to a file named 'post.txt'.""",
                     markdown=True)

As a result, we have the following.

Unlock Your Best Self Through Healthy Eating:

1. Prioritize whole foods: Load up on fruits, vegetables, lean proteins, and whole
 grains.  They're packed with nutrients and keep you feeling full and energized.
2. Mindful eating:  Pay attention to your body's hunger and fullness cues. 
Avoid distractions while eating.
3. Hydrate, hydrate, hydrate: Water is crucial for digestion, energy levels, 
and overall health.
4. Don't deprive yourself:  Allow for occasional treats.  
Deprivation can lead to overeating later.  Enjoy everything in moderation!
5. Plan ahead:  Prep your meals or snacks in advance to avoid unhealthy 
impulse decisions.

#healthyeating #healthylifestyle #nutrition #foodie 
#wellbeing #healthytips #eatclean #weightloss #healthyrecipes 
#nutritiontips #instahealth #healthyfood #mindfuleating #wellnessjourney 
#healthcoach

Certainly, we could make it much more fancy by creating a crew with other agents to search a list of websites for content, a content checker and reviewer, and another one to generate an image for the post. But I believe you got the general idea of how to add a tool to an Agent.

Another type of tool we can add is the function tool. We can use a Python function to serve as a tool for the LLM. Just don’t forget to add the type hints like video_id:str, so the model knows what to use as the function’s input. Otherwise, you might see an error.

Let’s see briefly how that works.

We now want our Agent to be able to get a given YouTube video and summarize it. To perform such a task, we simply create a function that downloads the transcript of the video from YT and passes it to the model to summarize.

# Imports
import os
from agno.agent import Agent
from agno.models.google import Gemini
from youtube_transcript_api import YouTubeTranscriptApi

# Get YT transcript
def get_yt_transcript(video_id:str) -> str:
      
    """
    Use this function to get the transcript from a YouTube video using the video id.

    Parameters
    ----------
    video_id : str
        The id of the YouTube video.
    Returns
    -------
    str
        The transcript of the video.
    """

    # Instantiate
    ytt_api = YouTubeTranscriptApi()
    # Fetch
    yt = ytt_api.fetch(video_id)
    # Return
    return ''.join([line.text for line in yt])


# Create agent
agent = Agent(
    model= Gemini(id="gemini-1.5-flash",
                  api_key = os.environ.get("GEMINI_API_KEY")),
                  description= "You are an assistant that summarizes YouTube videos.",
                  tools=[get_yt_transcript],
                  expected_output= "A summary of the video with the 5 main points and 2 questions for me to test my understanding.",
                  markdown=True,
                  show_tool_calls=True)


# Run agent
agent.print_response("""Summarize the text of the video with the id 'hrZSfMly_Ck' """,
                     markdown=True)

And then you have a result.

Result of the summarization requested. Image by the author.

Agents with Reasoning

Another cool option from the Agno package is allowing us to easily create agents that can analyze the situation before answering a question. That’s the reasoning tool.

We will create a reasoning agent with Alibaba’s Qwen-qwq-32b model. Notice that the only difference here, besides the model, is that we’re adding the tool ReasoningTools().

The adding_instructions=True means providing detailed instructions to the agent, which enhances the reliability and accuracy of its tool usage, while setting this to False forces the agent to depend on its own reasoning, which can be more prone to errors.

# Imports
import os
from agno.agent import Agent
from agno.models.groq import Groq
from agno.tools.reasoning import ReasoningTools


# Create agent with reasoning
agent = Agent(
    model= Groq(id="qwen-qwq-32b",
                  api_key = os.environ.get("GROQ_API_KEY")),
                  description= "You are an experienced math teacher.",
                  tools=[ReasoningTools(add_instructions=True)],
                  show_tool_calls=True)


# Writing and saving a file
agent.print_response("""Explain the concept of sin and cosine in simple terms.""",
                     stream=True,
                     show_full_reasoning=True,
                     markdown=True)

Follows the output.

Output of the reasoning model. Image by the author.

Agent with Knowledge

This tool is the easiest way for me to create a Retrieval Augmented Generation (RAG). With this feature, you can point the agent to a website or a list of websites, and it will add the content to a vector database. Then, it becomes searchable. Once asked, the agent can use the content as part of the answer.

In this simple example, I added one page of my website and asked the agent what books are listed there.

# Imports
import os
from agno.agent import Agent
from agno.models.google import Gemini
from agno.knowledge.url import UrlKnowledge
from agno.vectordb.lancedb import LanceDb, SearchType
from agno.embedder.sentence_transformer import SentenceTransformerEmbedder

# Load webpage to the knowledge base
agent_knowledge = UrlKnowledge(
    urls=["https://gustavorsantos.me/?page_id=47"],
    vector_db=LanceDb(
        uri="tmp/lancedb",
        table_name="projects",
        search_type=SearchType.hybrid,
        # Use Sentence Transformer for embeddings
        embedder=SentenceTransformerEmbedder(),
    ),
)

# Create agent
agent = Agent(
    model=Gemini(id="gemini-2.0-flash", api_key=os.environ.get("GEMINI_API_KEY")),
    instructions=[
        "Use tables to display data.",
        "Search your knowledge before answering the question.",
        "Only inlcude the content from the agent_knowledge base table 'projects'",
        "Only include the output in your response. No other text.",
    ],
    knowledge=agent_knowledge,
    add_datetime_to_instructions=True,
    markdown=True,
)

if __name__ == "__main__":
    # Load the knowledge base, you can comment out after first run
    # Set recreate to True to recreate the knowledge base if needed
    agent.knowledge.load(recreate=False)
    agent.print_response(
        "What are the two books listed in the 'agent_knowledge'",
        stream=True,
        show_full_reasoning=True,
        stream_intermediate_steps=True,
    )
Response from the agent after searching the knowledge base. Image by the author.

Agent with Memory

The last type we will go over in this post is the agent with memory.

This type of agent can store and retrieve information about users from previous interactions, allowing it to learn user preferences and personalize its responses.

Let’s see this example where I will tell a couple of things to the agent and ask for recommendations based on that interaction.

# imports
import os
from agno.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.google import Gemini
from rich.pretty import pprint

# User Name
user_id = "data_scientist"

# Creating a memory database
memory = Memory(
    db=SqliteMemoryDb(table_name="memory", 
                      db_file="tmp/memory.db"),
    model=Gemini(id="gemini-2.0-flash", 
                 api_key=os.environ.get("GEMINI_API_KEY"))
                 )

# Clear the memory before start
memory.clear()

# Create the agent
agent = Agent(
    model=Gemini(id="gemini-2.0-flash", api_key=os.environ.get("GEMINI_API_KEY")),
    user_id=user_id,
    memory=memory,
    # Enable the Agent to dynamically create and manage user memories
    enable_agentic_memory=True,
    add_datetime_to_instructions=True,
    markdown=True,
)


# Run the code
if __name__ == "__main__":
    agent.print_response("My name is Gustavo and I am a Data Scientist learning about AI Agents.")
    memories = memory.get_user_memories(user_id=user_id)
    print(f"Memories about {user_id}:")
    pprint(memories)
    agent.print_response("What topic should I study about?")
    agent.print_response("I write articles for Towards Data Science.")
    print(f"Memories about {user_id}:")
    pprint(memories)
    agent.print_response("Where should I post my next article?")
Example of AI Agent with memory. Image by the author.

And here we end this first post about AI Agents.

Before You Go

There’s a lot of content in this post. We climbed the first step in this ladder of learning about AI agents. I know, it is overwhelming. There is so much information out there that it becomes harder and harder to know where to start and what to study.

My suggestion is to take the same road I am taking. One step at a time, choosing just a couple of packages like Agno, CrewAI, and going deep on those, learning how to create more complex agents each time.

In this post, we started from scratch, learning how to simply interact with an LLM to creating agents with memory, or even creating a simple RAG for an AI Agent.

Obviously, there is much more you can do just with a single agent. Check out the Reference [4].

With these simple skills, be sure that you are ahead of a lot of people, and there is a lot you can do already. Just use the creativity and (why not?) ask for the help of an LLM to build something cool!

In the next post, we will learn more about agents and evaluation. Stay tuned!

GitHub Repository

https://github.com/gurezende/agno-ai-labs

Contact and Online Presence

If you liked this content, find more of my work and social media in my website:

https://gustavorsantos.me

References

[1] https://docs.agno.com/introduction

[2] https://ai.google.dev/gemini-api/docs

[3] https://pypi.org/project/youtube-transcript-api/

[4] https://github.com/agno-agi/agno/tree/main/cookbook

[5] https://docs.agno.com/introduction/agents#agent-with-knowledge

The post Agentic AI 101: Starting Your Journey Building AI Agents appeared first on Towards Data Science.