The video owner has disabled playback on external websites.
This video is no longer available on YouTube.
This video cannot be played right now.
Watch on YouTube
ابزارهای یادگیری هوش مصنوعی را باز کنید
ثبتنام کنید تا به ابزارهای قدرتمندی دسترسی پیدا کنید که به شما کمک میکنند سریعتر از هر ویدیو یاد بگیرید.
Avoid Messy Code: Design Patterns for AI Agents in Python
زیرنویسها (462 بخشها)
This video is brought to you by
Squarespace. If you're trying to build
something with large language models,
you know things can get messy pretty
quickly. You start with one prompt, then
you add a few tools, then you pass some
data to another model, and before long,
your logic is going to be scattered and
all over the place. So, the question is,
how do you structure AI systems the
right way? In this video, I'm going to
show you three design patterns that I've
adapted for LLMs and agents that are
going to help you build cleaner, more
modular AI systems. Let's go. The
example that I'm going to use in this
video is a travel agent. And this agent
can help you find hotels and flights,
etc., etc. Now, there is one prompt that
I'm going to start with, which is this.
I want a rainy city trip within Europe.
I love towers. I don't want to cross
water to get there. And this is Maria
who lives in Berlin. So, let's run this
particular example and see what happens.
The agent has decided that Maria needs
to go to Paris, France, which is wrong.
It should be Utre, the Netherlands.
Anyway, okay, Paris. Fine. So, then the
agent books a flight from Berlin to
Paris, which arrives at 6:00 p.m. It
looks for a hotel, which is the highest
regency in Paris. I don't know if this
is a good hotel or not. And then uh but
it is quite expensive so hopefully it
is. And then there are some activities
for early evening explorers. You can
visit the shopping mall, take an evening
walk, uh enjoy a dinner, etc., etc. So
the Asian has done like a bunch of
different things here. And that's
typically something that you're going to
encounter in AI application, right? It's
not just I send a prompt and I get back
a response. I mean, we can just use a
chat agent for that. We want something
that's a bit more uh involved. And of
course, in this particular situation,
you don't want to handle everything in
one massive prompt because that's simply
not going to work. You need to break it
down into separate agents and then each
is responsible for a single step. So we
have choosing a destination, we have
planning the flight, recommending a
hotel, and suggesting things to do. The
way I've built this is that I'm
implementing each of these steps as its
own function. And then you can execute
them in order by storing them in a list.
More about that in a minute. So how is
this code actually set up? I'm using
byic AI for the agents. So first I load
the environment variables. In this case,
there's just one which is the OpenAI API
key. Then we have some dependencies
which is we need to know the username.
We need to know the origin city and then
there is a context that's basically the
information that each of these agents is
going to need. So things like the
destination, the uh origin city, the
arrival time, the hotel name, etc. And
this going to be filled in step by step
by the agents. Then for each step I have
an agent. So in this case I have a
destination agent that helps users find
a ideal tra travel destination based on
their preferences.
Then I have a flight agent that can look
for flights for a particular trip. Then
I have a hotel recommendation agent that
suggests a good hotel near the airport
or city center. Then we have an activity
agent that suggests local activities. So
you have all these different agents that
can do each a specific thing that also
have their own system prompts that to
adapt them. And then the pattern that
I'm using to perform these tasks in
order is the chain of responsibility.
And what that pattern entails that you
have a bunch of different functions that
زیرنویس کامل در پخشکننده ویدیو موجود است
با تمرینها یاد بگیرید
تمرینهای واژگان، گرامر و درک مطلب از این ویدیو بسازید
نظرات (0)
برای نظر دادن وارد شویدثبتنام کن و همه امکانات رو باز کن
پیشرفتت رو دنبال کن، واژگان رو ذخیره کن و تمرین کن
حالت تعاملی
آزمون
پاسخ صحیح:
ویدیوهای مرتبط
You Stopped Exercising. The Gains That Stuck Around Might Surprise You.
The Top 5 Problems of the Standard Model
Why Your Code Isn’t Pythonic (And How to Fix It)
I Tried Vibe Coding - Here Are My Thoughts
Stop Mixing FastAPI with Business Logic: Fix It with Ports & Adapters
Late Night with Seth Meyers
آزمون
پاسخ صحیح:
آزمونها هنگام تماشای ویدیو ظاهر میشوند
راهنمای حفظ
از این ویدیو
شروع رایگان یادگیری زبان