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

افتح أدوات التعلم بالذكاء الاصطناعي

سجّل للوصول إلى أدوات قوية تساعدك على التعلم أسرع من كل فيديو.

شارح المشهد صائد العبارات مراجعة البطاقات تمرين المحاكاة الرد الصوتي
سجل مجاناً
الإنجليزية 18:19 Science & Tech

Avoid Messy Code: Design Patterns for AI Agents in Python

Late Night with Seth Meyers · 24,315 مشاهدات · أُضيف منذ شهر

الترجمة (462 مقاطع)

00:00

This video is brought to you by

00:01

Squarespace. If you're trying to build

00:03

something with large language models,

00:05

you know things can get messy pretty

00:07

quickly. You start with one prompt, then

00:10

you add a few tools, then you pass some

00:12

data to another model, and before long,

00:14

your logic is going to be scattered and

00:16

all over the place. So, the question is,

00:19

how do you structure AI systems the

00:21

right way? In this video, I'm going to

00:24

show you three design patterns that I've

00:27

adapted for LLMs and agents that are

00:30

going to help you build cleaner, more

00:32

modular AI systems. Let's go. The

00:35

example that I'm going to use in this

00:37

video is a travel agent. And this agent

00:40

can help you find hotels and flights,

00:43

etc., etc. Now, there is one prompt that

00:46

I'm going to start with, which is this.

00:49

I want a rainy city trip within Europe.

00:52

I love towers. I don't want to cross

00:54

water to get there. And this is Maria

00:56

who lives in Berlin. So, let's run this

00:59

particular example and see what happens.

01:01

The agent has decided that Maria needs

01:03

to go to Paris, France, which is wrong.

01:06

It should be Utre, the Netherlands.

01:08

Anyway, okay, Paris. Fine. So, then the

01:11

agent books a flight from Berlin to

01:13

Paris, which arrives at 6:00 p.m. It

01:17

looks for a hotel, which is the highest

01:19

regency in Paris. I don't know if this

01:21

is a good hotel or not. And then uh but

01:25

it is quite expensive so hopefully it

01:28

is. And then there are some activities

01:29

for early evening explorers. You can

01:32

visit the shopping mall, take an evening

01:35

walk, uh enjoy a dinner, etc., etc. So

01:39

the Asian has done like a bunch of

01:41

different things here. And that's

01:44

typically something that you're going to

01:45

encounter in AI application, right? It's

01:47

not just I send a prompt and I get back

01:50

a response. I mean, we can just use a

01:52

chat agent for that. We want something

01:54

that's a bit more uh involved. And of

01:57

course, in this particular situation,

01:58

you don't want to handle everything in

02:00

one massive prompt because that's simply

02:03

not going to work. You need to break it

02:05

down into separate agents and then each

02:08

is responsible for a single step. So we

02:10

have choosing a destination, we have

02:12

planning the flight, recommending a

02:14

hotel, and suggesting things to do. The

02:17

way I've built this is that I'm

02:19

implementing each of these steps as its

02:21

own function. And then you can execute

02:25

them in order by storing them in a list.

02:27

More about that in a minute. So how is

02:29

this code actually set up? I'm using

02:31

byic AI for the agents. So first I load

02:35

the environment variables. In this case,

02:37

there's just one which is the OpenAI API

02:39

key. Then we have some dependencies

02:43

which is we need to know the username.

02:45

We need to know the origin city and then

02:48

there is a context that's basically the

02:51

information that each of these agents is

02:53

going to need. So things like the

02:54

destination, the uh origin city, the

02:57

arrival time, the hotel name, etc. And

02:59

this going to be filled in step by step

03:01

by the agents. Then for each step I have

03:04

an agent. So in this case I have a

03:06

destination agent that helps users find

03:09

a ideal tra travel destination based on

03:12

their preferences.

03:14

Then I have a flight agent that can look

03:17

for flights for a particular trip. Then

03:21

I have a hotel recommendation agent that

03:26

suggests a good hotel near the airport

03:28

or city center. Then we have an activity

03:31

agent that suggests local activities. So

03:34

you have all these different agents that

03:35

can do each a specific thing that also

03:37

have their own system prompts that to

03:40

adapt them. And then the pattern that

03:41

I'm using to perform these tasks in

03:44

order is the chain of responsibility.

03:47

And what that pattern entails that you

03:49

have a bunch of different functions that

الترجمة الكاملة متاحة في مشغل الفيديو

تدرّب مع التمارين

أنشئ تمارين مفردات وقواعد وفهم من هذا الفيديو

المفردات والقواعد اختبار الفهم اختبار IELTS ممارسة الكتابة
سجل للممارسة
لا توجد تعليقات بعد. كن أول من يشارك أفكاره!

سجّل لفتح جميع الميزات

تابع تقدّمك، احفظ المفردات، وتمرّن على التمارين

ابدأ تعلم اللغات مجاناً