---
title: 'Build a Python AI Agent in 10 Minutes'
source: 'https://youtube.com/watch?v=gaGaPpnexxA'
video_id: 'gaGaPpnexxA'
date: 2026-07-28
duration_sec: 631
---

# Build a Python AI Agent in 10 Minutes

> Source: [Build a Python AI Agent in 10 Minutes](https://youtube.com/watch?v=gaGaPpnexxA)

## Summary

This tutorial demonstrates how to build an AI agent in Python using LangChain and LangGraph in under 10 minutes. The agent uses GPT-4-mini and custom tools to generate and save sample user data to JSON files.

### Key Points

- **Project Setup** [00:00] — Open a code editor (e.g., PyCharm), create a folder, and initialize the project with `uv init .`.
- **Install Dependencies** [00:54] — Install langchain, langgraph, python-dotenv, and langchain-openai using `uv add`.
- **Set Up OpenAI API Key** [01:24] — Create a .env file with OPENAI_API_KEY variable. Obtain key from platform.openai.com/api-keys.
- **Define Tools** [04:34] — Three tools: write_json, read_json, and generate_sample_users. Tools are Python functions decorated with @tool, with typed parameters and docstrings.
- **Create Agent** [06:38] — Combine LLM (GPT-4-mini), tools list, and system message using create_react_agent from langgraph.
- **Driver Code** [07:44] — Function to invoke agent with user input and history, limiting tool calls to 50.
- **Run Agent** [09:07] — Execute with `uv run main.py`. Test by generating users, saving to JSON, and querying data.

### Conclusion

You can build a functional AI agent in Python quickly using LangChain and LangGraph, with custom tools and any LLM. The code is available in the description.

## Transcript

Today I'm going to show you how to build
an AI agent in Python in less than 10
minutes. So let's get started. To begin
our project, we need to open up a folder
in some type of code editor. In my case,
I'm going to be using PyCharm, but you
can use anything that you want. I do
typically recommend PyCharm for large
Python projects because it is well
designed for Python and I have a
long-term partnership with them. So if
you want to try it out for free, you can
do that by clicking the link in the
description. Now I've made a project
here or made a folder called 10minute
agent. So open up some kind of folder.
We're then going to go to our terminal
and we're going to install the
dependencies that we need. Now to
install these, I recommend using uv and
by starting to do uv init and then dot.
Do this in the directory where you want
to create this project. So we're going
to initialize our project. If you don't
already have uv installed, I'll leave a
video on screen that shows you how it
works. From here, we're going to open up
main.py, delete everything inside of
there, and then start installing our
dependencies. So from our terminal,
we're going to type uvad. We're going to
add lang chain. We're going to add lang
graph. We're going to add python-
env. And we're going to add langchain-
open aai. Now, these are all the
dependencies that we need for making an
agent. There's multiple ways to do this.
We're going to use lang chain and
langraph, which is a really modern
approach that makes it very easy for us
to design agents in Python. So, go ahead
and press enter. Add all of those
packages and then we're good to start
writing some code. So, for this project,
I'm going to use GPT4 as my LLM, but you
can use any LLM that you want. Since I'm
using an LLM from OpenAI, I need to get
an OpenAI API key. So, I'm going to make
a new file here. I'm going to call this
env. And then inside of this file, I'm
going to make a variable that says
OpenAI_API_key.
And I'm going to fill this in with my
OpenAI key, which I'll get right now.
So, in order to get a key, you will need
an account with OpenAI. You can go to
this website right here,
platform.opai.com/api. openai.com/api
keys. You will need a credit card on
file, but this will cost you a fraction
of a few cents if you're just using it
for a demo example. So, here we're going
to go here, go ahead and press on create
secret key. We're then going to copy the
key, which we're not going to share with
anybody else, and we're going to paste
this inside of our environment variable
file. From here, we'll save, close, and
then we're ready to start building our
agent. Now, speaking of agents, today's
sponsor, Notion, just released theirs,
which is a complete gamecher. Now,
Notion's new AI agent doesn't just help.
It finishes the job for you. And as a
Notion power user, myself, this has been
absolutely amazing. Now, this thing
isn't a chatbot. It's an actual AI
teammate that lives inside of your
Notion workspace and can complete tasks
end to end. You give it a goal like
summarize last week's meeting notes into
a project update, and it figures out the
plan, pulls the info, and updates your
pages. It even notifies your teammates
as well. Now, it's mastered every Notion
building block. So, it can edit
databases, rewrite documents, audit
knowledge bases, or even draft an entire
launch plan, all exactly the way that
you would. And here's what makes it
pretty cool. Your agent actually learns
your style. You can tell it where to
file things, how to write, even what
tone to use. And over time, it builds
memories so it starts anticipating what
you need next. So, instead of you
spending your day buried in admin work,
your agent just handles it all for you.
Now, if you want to try it out, Notion
agents are available right now. Click
the link in the description and let
notion agent do your work for you.
Thanks to Notion. Now, let's get back
into it. So, because I'm trying to do
this in 10 minutes, I'm not going to
write every line of code out
individually. I'm going to copy in some
different chunks. And if you want all of
the code, I'll leave a link to it in the
description where you can download it
and mess with it from there. So, first
things first, we're going to bring in
our imports. Now, we're going to need to
import a few things from the standard
library for doing our typing. We're then
going to bring chat openai. We're going
to bring in a bunch of different
messages that we need. We're going to
import the tool and then we're going to
import the create react agent which
comes from langraph. Now we're also
going to do another import where we say
from.env
import and this is going to be load.env.
We're then going to call the load.env
function. And what this is going to do
is load our environment variables from
our environment variable file. We're
using a combination of langraph and lang
chain here in order to initialize our
agent and to get it to be able to call
tools. The thing that makes an agent an
agent is that it has access to something
outside of just a chat interface. So in
our case, we're going to provide to this
agent a series of tools that allows it
to generate kind of mock user data and
then save that data into JSON files.
Once you understand how to add one tool,
you can add as many of them as you want.
So let me copy in a few tools that our
agent is going to have access to. Then
we'll start initializing the agent and
start writing everything so we can
interact with it. So I've just added
three tools which really are just Python
functions to my file. Let's go through
them one by one so you can understand
the kind of composition of a tool. Now a
tool can simply be a Python function. So
in this case we have a tool called write
JSON. We take in some file path which is
the file that we want to write to and
then some data that we want to write and
this returns a string. Now we denote
that this is a tool by decorating it
with the at@ tool decorator which we
imported right here from langchain. Now
inside of this tool we can do anything
that we want. But we should make sure
that we return some kind of AI readable
information so that the AI understands
what this tool call actually achieved.
Now the thing that makes this a tool is
this tool decorator. But for any tool,
you need to make sure that you denote
the types of your parameters. So in this
case, we've denoted this is a string and
this is a dictionary and then the return
type of the function. This is
information that will be passed to our
LLM or our agent. So it knows which tool
to call and how to call that tool. It's
also important that you write a dock
string. That's something inside of these
three uh quotes right here that
describes what the function does or what
the tool does so the agent understands
which tools to call. So in this case we
have write a Python dictionary as JSON
to a file with pretty formatting. So now
the agent knows this is the tool that I
can use when I need to do that. Moving
on, we have our next tool which can read
a JSON file. Same thing we denote the
parameters and their types as well as
the return type of the function. And
then we have a dock string that
describes when to use this tool or this
function. Okay. And we return good error
messages explaining what's going on.
Lastly, we have another tool. This can
generate sample users. We take in a list
of first names, a list of last names, a
list of domains, and a minimum and
maximum age. And then we generate some
sample user data with all of this error
and validation checking and pass that
back to the LLM. You can have any tools
that you want. I'm just giving you three
here so you can see a bit of diversity
in terms of how they work. Okay, so now
that we have our tools, we need to
create an LLM and an agent and
essentially give these tools to our LLM.
So let's start by defining a list of
tools, which we can do with this
variable right here. Then let's define
our model. So the model that we're going
to use or the LLM is going to be GPT4
mini. You can use any LLM that you want
here, but this is the one that I'll use
for this video. Then we're going to
define what I call our system message or
our system prompt. Now that's not just
what I call it, that's what it's called.
But essentially, this tells the system
what it's supposed to be doing so that
it has some more context in terms of how
it should behave. You can read through
this if you want, but essentially I'm
telling it that this is a data generator
agent that's able to generate sample
data for an application and then save
that in a JSON file. Now, once we have a
list of tools, an LLM or a model, and
some system message, we can create our
agent. And that's because an agent is
made up of those three components. It
can also be made up of more, but in this
case, that's what we'll use. So, we can
say agent is equal to create react
agent. We pass the LLM, we pass the list
of tools, and then we pass the system
message. Now, in order to use our agent,
we need some kind of driver code. So,
we're going to bring in a function that
looks like this, where in order to run
the agent, we take in some user input,
we can take in a history, which is all
of the previous messages. So, we can
store that and have some previous
context, and then we return an AI
message. What we're able to do is invoke
the agent. So, we say agent.invoke.
We can pass all of the previous messages
plus the new message. And then what we
can say is that we have some limit in
terms of how many tool calls this can do
which is 50. And then we can return
whatever the last response is from this
agent. If there's an error then we can
return something like this. Now what
this is going to do is automatically
respond to the most recent message for
us. So we'll get the most recent
response and it will do any tool calls
as it needs to in this step. So when we
agent on.invoke invoke and we have
access to various tools. If the agent
needs to call a tool, it will go ahead
and just call it, use the tool and then
return to us whatever the response is
that it thinks that we want. That's how
we run the agent. Now, let's bring in a
little bit more driver code just to make
this application look a bit prettier and
we can test it out. So, what I'm doing
is I'm just putting some formatting. I'm
saying, okay, let's create a list of all
of the messages we've sent so far. Let's
ask the user for some user input. If
they want to quit, we can quit.
Otherwise, we can just run the agent and
then we can print out whatever the
response was, update the history and
keep going. Now, in order to run our
agent, what we can do is open up our
terminal. So, let's go here, type uv
run, and then the name of our file,
which is main. py. This will take a
second, and then what we're able to do
is start asking the agent questions. So,
we can say something like generate five
random users. And let's see what the
result is that we get. Okay. Okay. And
if we just bring this up a little bit
larger, you can see that we have five
random users generated. Now, let's take
one of the examples here. So, maybe make
users like this. Okay. So, make users
age 25 to 35 with company.com emails and
save three of them to users.json.
And let's see what we get. Okay. And if
we have a look here, we can see a
users.json file was just created. We
have three users inside of here. And
then lastly to test this we can say what
is the oldest user in users.json
and let's see if it's able to read that
and give us the result. Okay we found
the oldest user which is Bob Johnson
here at age 25. So that is the AI agent
in Python in approximately 10 minutes.
You can add any tools that you want. You
can change the LLM. You can change the
system prompt and quite quickly you can
make something very interesting. Again,
if you want the code, it will be
available from the link in the
description. And I look forward to
seeing you in another video.
[Music]
