This content originally appeared on Level Up Coding – Medium and was authored by Odunayo Babatope

Artificial Intelligence has been on the rise lately with AI Agents. Many companies have started building Agents and incorporating them into their businesses. The trend is moving so fast now that literally anything can be built as an agent. Anyone looking to break into this field has one common question: how can they get started? This guide will break it down in simple terms.
What is an AI Agent?
An AI agent is a software program that can perceive its environment, process information, and take actions to complete tasks. AI agents are designed to operate with a degree of autonomy, meaning they can make decisions and execute actions without constant human intervention. AI agents can be used in various domains such as healthcare, finance, robotics, e.t.c.
One of the key strengths of AI agents is their ability to enhance decision-making, automate repetitive tasks, and personalize user experiences. For instance, an AI agent can manage your calendar by scheduling meetings, sending reminders, and prioritizing events based on your preferences. Similarly, in customer service, AI agents can handle inquiries, provide recommendations, and resolve issues efficiently.
What are Tools?
In building Agents, tools are essential components we can use to extend the capabilities of our agent. These tools can be thought of as external resources or functions that allow the agent to solve problems and perform tasks more efficiently. For instance, we have tools like code interpreters, search engines, and databases.
Choose the Right Frameworks
The next step is selecting the appropriate frameworks for building our agent. The frameworks you can use are outlined below:
i) LangChain -LangChain provides essential tools for building AI agents. These agents are designed with the capability to reason, retrieve information, and interact with external environments.
ii) LangGraph — LangGraph is an extension of LangChain. It allows users to build stateful, multi-actor applications using large language models.
iii) CrewAI — CrewAI is a powerful framework for designing multi-agent AI systems where different AI agents collaborate to accomplish complex tasks.
iv) Smolagents — SmolAgents is a lightweight framework designed to create minimalist AI agents that can interact with APIs, databases, and external tools. It focuses on simplicity and efficiency, making it an excellent choice for small-scale, targeted AI automation tasks.
v) AutoGPT — Designed for fully autonomous AI agents that complete tasks with minimal human input.
I will be diving deeper later in my next article on each of these frameworks. These frameworks are some of the best you can use for building your Agents.
Now that we understand what an agent is, let’s demonstrate how to build one using LangGraph.
Build a Simple ReAct Agent
A ReAct Agent is an AI agent that combines Reasoning (Re) and Acting (Act) in an interactive loop to make decisions. When a ReAct Agent is created, the LLM first goes through a reasoning phase to determine which tools to use before generating the final response.
In this tutorial, we will build a ReAct Agent by covering the following key steps:
- Tool Setup: Integrating different tools, like creating a custom tool and using a web search tool.
- Creating the Agent: Learning how to implement and utilize the ReAct Agent within LangChain.
Tool Setup
i) Obtain API Credentials
- Create an account on the Live Score API platform.
- Retrieve your api_key and api_secret from your profile.
- Store these credentials securely in an .env file for authentication.
- Go to the Open AI platform and set up an API Key
- Add this key to your .env file as well.
ii) Integrate the API
We aim to build a custom tool that can retrieve all upcoming football matches for any country. To do this, we use the Live Score API and query the fixtures endpoint to fetch these matches.
The code below demonstrates how to query the API.
import requests
import os
from langchain.tools import tool
from dotenv import load_dotenv
load_dotenv() # Load API key from .env file
api_key = os.getenv("SPORT_api_key")
api_secret = os.getenv("SPORT_api_secret")
class FootballData:
"""
This is a class for retrieving football upcoming matches based on country name.
"""
def __init__(self):
self.BASE_URL = "https://livescore-api.com/api-client"
self.api_key = api_key
self.api_secret = api_secret
def get_country_id(self, country_name):
"""Fetch country ID by country name."""
url = f"{self.BASE_URL}/countries/list.json?key={self.api_key}&secret={self.api_secret}"
response = requests.get(url).json()
for country in response["data"]["country"]:
if country["name"].lower() == country_name.lower():
return country["id"]
return None
def get_competition_ids(self, country_id):
"""Fetch competition IDs for a given country ID."""
url = f"{self.BASE_URL}/competitions/list.json?key={self.api_key}&secret={self.api_secret}&country_id={country_id}"
response = requests.get(url).json()
return [comp["id"] for comp in response["data"]["competition"]]
def get_upcoming_fixtures(self, competition_ids):
"""Fetch upcoming matches for given competition IDs"""
fixtures = []
for comp_id in competition_ids:
url = f"{self.BASE_URL}/fixtures/matches.json?key={self.api_key}&secret={self.api_secret}&competition_id={comp_id}"
response = requests.get(url).json()
if "fixtures" in response["data"]:
fixtures.extend(response["data"]["fixtures"])
return fixtures
def get_upcoming_matches(self, country_name):
"""Get all upcoming matches and preprocess to take the information needed from result"""
country_id = self.get_country_id(country_name)
if not country_id:
return f"No country found with the name {country_name}"
competition_ids = self.get_competition_ids(country_id)
if not competition_ids:
return f"No competitions found for {country_name}"
fixtures = self.get_upcoming_fixtures(competition_ids)
if not fixtures:
return f"No upcoming fixtures found for {country_name}"
# Format the matches data
formatted_matches = []
for match in fixtures:
formatted_matches.append(
f"{match['home_name']} vs {match['away_name']} at {match['location']} - {match['date']}, {match['time']}"
)
return formatted_matches
iii)Define the Custom Tool
The FootballData class created above will be referenced in the code below. We can see that we’re calling the get_upcoming_matches method from our class, which is responsible for fetching all the matches. Also, in our code, we can see the @tool decorator on the function. This is how we create a custom tool — using the @tool decorator on any function turns it into an AI Agent tool that can be called dynamically within an AI framework.
@tool
def get_upcoming_matches(query: str):
"""Use this tool to get upcoming football matches for a given country. Provide the country name as input."""
sport_tool = FootballData()
return sport_tool.get_upcoming_matches(query)
iv)Tavily Search Tool
The next tool in our agent’s toolkit is the Tavily Search Tool. This tool is what our LLM will use to perform real-time web searches.
from langchain_community.tools.tavily_search import TavilySearchResults
web_search = TavilySearchResults()
Then, we combine all tools — custom tool “get_upcoming_matches“ and “Tavily Search Tool“.
tools = [get_upcoming_matches, web_search]
Now that the tools are ready, we can proceed to creating the agent, where they will be integrated to enable decision-making.
Creating the Agent
We will build a ReAct Agent, where we integrate the tools into LangChain and allow our LLM to decide which tools to use based on input provided by the user.
i)Memory and Model Configuration
We initialize the LLM by using the gpt-4o-mini from ChatOpenAI as the model and add a memory saver to retain interaction history.
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent
# Memory and model configuration
memory = MemorySaver()
model = ChatOpenAI(model_name="gpt-4o-mini")
ii)Create Agent
We create the agent with the “create_react_agent” function in langGraph by passing in our tools, model, and memory. Below is a visual representation of the agent’s decision-making process in graph form.
#create ReAct Agent
agent = create_react_agent(model, tools=tools, checkpointer=memory)
from IPython.display import Image, display
display (
Image(agent.get_graph().draw_mermaid_png())
)

Test your Agent
Now that our agent is ready, we’ll test it by sending a query and asking it to carry out some tasks. The config you see below is for message tracking.
config = {"configurable": {"thread_id": "1"}}
inputs = {
"messages": [
(
"human",
"Search for all upcoming matches in England",
)
]
}
result = agent.stream(inputs, config=config, stream_mode="values")
for result in result:
message = result["messages"][-1]
message.pretty_print()
This is the result of the query, “Search for all upcoming matches in England,” that we asked the agent. In the output, we can see that the agent called the correct tool (get_upcoming_matches) to retrieve all upcoming matches.

We can test further by asking a different question unrelated to football; let’s see how the agent would perform.
config = {"configurable": {"thread_id": "1"}}
inputs = {
"messages": [
(
"human",
"Search for top 10 italian cuisine",
)
]
}
result = agent.stream(inputs, config=config, stream_mode="values")
for result in result:
message = result["messages"][-1]
message.pretty_print()
In the result below, we asked the agent to search for the top 10 Italian cuisines, and it successfully completed the task using the Tavily Search tool.

Thanks for reading! See you in the next one.
How to Get Started with AI Agents: A Beginner’s Guide was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding – Medium and was authored by Odunayo Babatope