The RIGHT WAY To Build AI Agents with CrewAI (BONUS: 100% Local)
Summary
TLDR在这个视频中,演讲者展示了如何使用Lightning AI来构建一个高效的Crew AI团队。Lightning AI不仅提供了一个基于云的代码编辑器,允许团队成员在云端协作编写代码,还可以利用开源模型来增强功能。视频中,演讲者首先创建了一个新的Lightning Studio,并在其中建立了一个名为“financial analyst crew”的代码框架。通过YAML文件定义了两个任务——“research company task”和“analyze company task”,以及两个相应的代理——“company researcher”和“company analyst”。接着,演讲者展示了如何使用LangChain和Gro模型来执行这些任务,并最终通过Lightning AI的GPU加速来提高处理速度。此外,还介绍了如何使用Lightning AI的Studio模板来快速启动一个项目,并利用API Builder插件将模型作为API服务暴露出来,从而实现与Crew AI的无缝集成。视频最后,演讲者鼓励观众如果喜欢这个视频就点赞和订阅。
Takeaways
- 🚀 介绍了如何使用Lightning AI搭建一个基于云的协作代码编辑器和开源模型的Crew AI团队。
- 📂 创建一个新的Studio和代码工作室,以便在云端进行项目管理和环境管理。
- 🔧 采用模块化的方式构建Crew AI代码框架,使用yaml定义代理和任务。
- 🛠️ 定义任务和代理,通过在配置文件中编写代码来明确它们的角色和目标。
- 🔄 通过迭代和复制任务定义,快速创建多个任务,每个任务对应一个代理。
- 📈 展示了如何为金融分析团队创建任务,例如研究特定公司和分析公司财务状况。
- 🤖 为每个任务创建代理,如金融研究员和金融分析师,并为它们设置详细的背景故事和目标。
- 📋 编写主文件main.py,将代理和任务组合在一起,创建Crew AI的运行流程。
- 🔗 介绍了如何使用Lang chain和Grock来连接和驱动Crew AI中的代理。
- 🛠️ 演示了如何使用Poetry来打包和管理项目依赖,为项目创建一个虚拟环境。
- 🔧 通过Lightning AI的API Builder插件,将Crew AI与OpenAI兼容的API端点连接。
- 🎉 强调了使用Lightning AI的GPU资源来加速大型模型的推理过程,并展示了实际操作过程。
Q & A
视频介绍了使用什么工具来搭建Crew AI团队?
-视频介绍了使用Lightning AI,这是一个云端代码编辑器,可以与他人协作编辑代码,并能够为开源模型提供动力。
Crew AI的代码库在未来将会是什么样子?
-Crew AI的代码库在未来将会是非常模块化的,拥有独立的工具区域,使用YAML定义代理和任务,并且所有内容都会汇集到一个简短的main.py文件中。
为什么要使用Lightning AI来管理Python环境?
-使用Lightning AI可以避免Python环境管理带来的头痛问题,因为它本质上是一个每次启动都是全新环境的云端代码编辑器。
在Crew AI中,如何定义任务和代理?
-在Crew AI中,任务和代理通过在config文件夹中创建相应的.yaml文件来定义,其中包括角色、目标、背景故事等信息。
视频提到了哪些金融分析中的重要指标?
-视频提到了盈利能力比率、流动性比率、偿债能力比率等金融分析中的重要指标。
如何使用Lightning AI的GPU来为开源模型提供动力?
-通过在Lightning AI的云端环境中配置模型,设置相应的GPU参数,并将模型通过API与Crew AI团队集成,从而使用Lightning AI的GPU为开源模型提供动力。
视频最后提到了哪些步骤来运行和测试Crew AI团队?
-视频最后提到了使用Poetry来整合项目、安装依赖、运行项目以及测试使用不同的模型(如Gro和Mixol)来驱动Crew AI团队的步骤。
如何将Crew AI团队的API端点暴露出来?
-通过使用Lightning AI的API Builder插件,设置端口和启用认证,然后获取基础URL,最后在Crew AI代码中使用这个URL来替换原来的模型配置。
视频提到了哪些工具来帮助分析公司的财务表现?
-视频提到了使用SEC工具来帮助分析公司的财务表现,这是一个已经存在于Crew AI示例库中的工具。
在视频中,为什么要在不同的任务中使用不同的模型?
-在不同的任务中使用不同的模型可以根据任务的具体需求选择最合适的模型,例如,某些任务可能需要更专业的财务分析模型,而其他任务可能只需要基本的信息检索功能。
视频提到了哪些步骤来确保Crew AI团队的结构正确?
-视频提到了创建源文件夹、定义任务和代理、创建主文件以及使用Poetry进行项目整合等步骤来确保Crew AI团队的结构正确。
Outlines
🚀 构建最优的Crew AI团队
本段介绍了如何使用Lightning AI这一云端代码编辑器来构建一个Crew AI团队。Lightning AI不仅支持代码协作,还能为开源模型提供动力。视频作者展示了如何创建一个新的工作室,并构建一个模块化的Crew AI代码框架。通过定义任务和代理,使用yaml文件来组织结构,并利用Lightning AI的自动环境管理功能,简化了Python环境配置的复杂性。
📋 定义任务和代理
在这一段中,视频作者详细阐述了如何定义任务和代理。通过创建不同的文件夹和文件,如config文件夹和agents.yaml、tasks.yaml文件,来明确任务和代理的结构。作者还解释了如何为每个任务和代理编写具体的描述和期望输出,以及如何为每个代理设置角色和背景故事。
🔧 编写主要的代码文件
视频作者在这一部分开始编写主要的代码文件,包括导入必要的库和创建crew AI项目的基础结构。通过定义agent和task的类,并将它们与之前定义的配置文件关联起来,作者展示了如何将任务和代理整合到一起。此外,还介绍了如何设置任务的处理顺序和详细输出。
🌟 运行Crew AI团队并测试
在最后一段中,作者运行了构建的Crew AI团队,并进行了测试。首先,使用Gro模型快速有效地完成了任务。然后,作者展示了如何使用Lightning AI的Studio模板来运行更大规模的开源模型,并将其API端点集成到Crew AI中。通过这些步骤,作者成功地展示了Crew AI的强大功能和灵活性。
Mindmap
Keywords
💡crew AI
💡Lightning AI
💡代码框架
💡任务
💡代理
💡配置文件
💡主程序文件
💡云环境
💡环境管理
💡开源模型
💡API
Highlights
介绍如何使用Lightning AI云编辑器建立一个Crew AI团队
Lightning AI不仅支持代码云端协作,还能为开源模型提供动力
创建一个新的Studio,简化Python环境管理
使用YAML定义代理和任务,模块化构建Crew AI代码框架
定义任务:研究特定公司的股票信息
定义任务:分析公司的财务状况
创建代理:公司研究员和公司分析师
编写main.py文件,将代理和任务整合在一起
使用Grock开源模型,通过Lightning AI GPU加速
展示如何使用Lightning AI的API构建器公开模型
使用Mistol和Lightning AI GPU运行Crew AI团队
演示了如何结构化Crew AI,使用Lightning AI和开源模型
通过Lightning Studio快速启动和运行项目
展示了如何将Crew AI与不同的模型和工具结合使用
使用Poetry管理项目依赖和运行Crew AI团队
通过Lightning AI的云环境避免了本地环境配置的麻烦
提供了一个完整的示例,从设置到运行Crew AI团队
Transcripts
in this video I'm going to show you the
optimal way to set up your crew AI team
this comes straight from the crew AI
founder and he has shown me the future
of what a crew AI codebase looks like
and we're going to be building all of
this using lightning AI which is not
only a cloud-based code editor which
allows you to collaborate with anybody
on your code in the cloud but you can
also power your open- Source models with
it which I'll also be showing you how to
do so we're going to build a Crea I team
and then we're going to swap out gp4 and
we're going to power it using mixol or
mistol we'll see and I want to thank
lightning. AI for sponsoring this video
I'm super excited to build this team on
lightning and I'm going to publish this
lightning studio in the description
below so you can get access to it you
can clone it and you can play around
with it yourself the first thing we're
going to be doing is building our crew
AI code framework and so the first thing
we need to do is create a new studio so
if you don't already have a lightning
account go ahead head and sign up
they'll give you some free credits to
get started click new studio right there
and we're going to create a code Studio
then we click Start and this entire
environment is in the cloud so it really
saves you a lot of headaches with python
environment management because it's
essentially a fresh environment every
single time and if you've been watching
my videos you know how frustrating
python environment management is all
right so the high level of how we're
going to structure our crew is now very
modular we're going to have a separate
area area for tools we're going to be
using yaml to Define our agents and
tasks and everything is going to pipe
into a very short main.py file so I just
spun up a new lightning studio and
that's really all we have to do we can
already get started so the first thing
we're going to do is create a source
folder so go ahead rightclick click new
folder and then type source and
everything should feel very familiar and
lightning because it is essentially vs
code in the class and the cool thing is
you don't actually need to set up your
environment you don't need to struggle
with your python environments with
dealing with all of these dependencies
it just works so we created our source
folder and then within the source folder
we're going to name our new crew so
we're going to actually create another
folder within that and I want to make a
financial analyst crew and so just like
that I name it financial analyst crew
hit enter then that creates another
folder all right then within that folder
we're going to create a another folder
config and all of this is just to
structure what we need to put everything
together so from here we're going to
write click we're going to create a new
folder we're going to call it config and
this is where we're going to put our
definitions of our tasks and our agents
and as I mentioned they're both going to
be Emo files so let's do that now right
click we're going to say new file and
we're going to call it
agents. for the first one and then we're
going to right click new file and we're
going to call it task. for the second
one and now this is where we're going to
Define our agents and tasks and the nice
thing about doing it this way so if you
start getting into the habit of
structuring your cruise just like this I
believe pretty soon crew AI is going to
give you the ability to actually expose
an endpoint to control your cruise based
on this structure so it'll automatically
be able to create you an API so that's
why it's good to follow the golden path
here so let's start writing our tasks
the first task is going to be
researching a specific company that I
want analyze so I'm going to call it
research company task and then we put a
colon after it and then we need two
parameters within that description and
expected output So within the
description this is where we're going to
describe the task at hand so what we're
going to say is use a Search tool and
we'll come back to this we'll actually
build the Search tool to look up this
Company's stock information and then I
put company name and the fact that I
have curly braces around the company
name now makes it a variable which we're
going to pass in later and this makes it
so that we can basically pass in any
company name the goal is to prepare
enough information to make an informed
analysis of the company's stock
performance the next thing we need is
the expected output and for the expected
output I say all of the relevant
Financial wh I spelled Financial wrong
financial information about the
company's stock performance okay so
that's the first task it's as simple as
that now I'm going to make a second task
so I'm just going to copy that first
task paste it again
and the second task is going to be
analyze company task so I'll delete the
descriptions from before and I'll delete
the expected output from before as well
and we'll put new ones in place so I
switched over to Claude 3 which by the
way is my new go-to model I no longer
prefer GPT 4 Cloud 3 has just been so
good and I asked what metrics should
someone include in a financial analysis
and it gave me a bunch of different
metrics and so I'm simply going to copy
paste these into the description of the
task I want so I say take company names
and again I pass in the variable
financial information analyze it and
provide a financial analysis including
profitability ratio liquidity ratio
solvency ratios and so on and for the
expected output I am going to say a
nicely formatted analysis including all
of the financial metrics necessary for a
thorough financial analysis of a company
and so let's stop there obviously I can
get much more sophisticated than this
but that's not the point I just want to
get something up and working and then I
want to show you powering it using an
open- Source model and powering that by
lightning AI gpus okay so we have two
tasks so research and then analyze and
then we need agents now so let's click
over to the agents. yl file so here is
the structure of an agent definition and
the name is going to be company
researcher the role I'm going to name it
Financial researcher the goal very
similar to the task now one quick thing
that I just added is I explicitly said
using search tools I don't know if I
actually have to do that but I like
explicitly saying it CU it doesn't hurt
and it makes me feel like okay it's
actually going to know to use those
tools okay backstory an expert Financial
researcher who spends all day and night
thinking about financial performance of
different companies now we're going to
set allow delegation to false because we
don't want this agent delegating this
task to anybody else and we're going to
set verose to true because I want to
actually see everything that this agent
is thinking so I'm going to copy that
and I'm going to paste it down here to
create our second agent now typically
what I do is I match every agent to an
individual task so if there are two
tasks there'll be two agents so let's
start changing this now so instead of
company researcher we're going to call
this the company analyst and instead of
financial researcher we'll call it
financial analyst and then we're going
to replace the goal so for the goal I'm
going to say take provided company
financial information and create a
thorough financial report about a given
company the backstory an expert
financial analyst who prides themselves
on creating clear and easily readable
Financial reports of different companies
again allow delegation false there's no
need for that and verbose true so now we
are done with agents now uh one quick
thing I want to mention is you don't
actually have to save any of the files
while you're working with lightning AI
it just saves it automatically as you're
going which is really nice I've
obviously gotten into the habit of
hitting command save all the time so it
doesn't hurt but you don't really have
to do that and you can shut this off you
can shut down the environment and come
back to it later and it's all just going
to be there working ready to go just
like you left it okay next we're going
to create our main file that puts all
the agents in task together so
rightclick on financial analyst crew and
we're going to create a new file and
let's call that crew. Pi so the first
thing we need to do is import all the
relevant libraries so we're going to say
from crew AI import agent crew process
and task and those are the four main
pillars of a crew AI project then we're
going to import crew base agent crew and
task from the crew ai. project and also
because grock is awesome we're going to
be using grock to power all of this and
we could do so through Lang chain so
make sure you have all of these
installed and we can pip install them if
we need to later but right now we just
need Lang chain grock import check Rock
now let's actually create the crew base
so enter enter and we'll say at crew
base and then we're going to create a
class financial analyst crew open PRS
close pars colon we're going to describe
what it is and then we're going to load
up the agents and tasks that we just
created then we need to set the grock
information so we're going to do def
init self none and then self. grock llm
and this is where we pull in the grock
chat information we're going to say
temperature zero model name and we're
going to be using mixol and we'll need
to set the token but we'll do that in a
minute now let's pull our agents and our
task into this file so at agent okay so
I wrote out the first agent definition
so we have at agent def company
researcher self and then we point it at
agent and we're going to be returning a
new agent object config and then we pull
in the config from the agents. yl file
and we pass in the grock L M as it's llm
and remember as I've said a lot of times
you can actually pass in a different
model from different sources into each
individual agent so if you want to use
gp4 for one clad for another Mixel for
another and then an open source model
powered by lightning as another you
could totally do that next let's copy
this and we're going to create our
second agent and this second agent is
company analyst okay so it's going to do
the same thing we're going to pass it as
an agent return the agent op object and
instead of company researcher we're
going to call it company analyst and
that's it th those are our definitions
for the two agents now we need to create
definitions for our tasks so just like
agent we say at task at the top we'll
say def company research task same as
before just like agents except instead
of agent we say task here new line then
we'll return a task object with
definitions config is equal to self.
task config and then we'll pull in the
relevant task and rather than passing in
an llm which wouldn't make sense for a
task we're going to pass in our agent
that we want to do this task so we say
self. compan researcher and that should
be good now let's copy it and create the
second task down here here we'll say def
analyze company task we'll create the
task return the task but we'll say
analyze company task here and we
actually want the company analyst as the
agent and I think we're done I think
this looks good ah no we need one more
thing so we actually have to Define our
crew which puts it all together all the
agents and all the tasks so we say at
crew def crew and we pass it itself make
a new crew object so here we're going to
return a crew and now we need to pass it
all the information to actually create
that crew so we'll do agents is equal to
self. agents and the self. Agents is
automatically created by these
decorators right here just a heads up on
that so that's all we got to do then for
task we do the same thing self. task
then we need to set a process so we're
going to do process. sequential because
we just want it happening one after
another and then verbose is equal to two
because we want it to Output everything
now I think we're done all right now we
need to actually create our main.py so
we already have one right here so let's
go ahead and move that into the
financial analyst crew okay main.py and
all it does is print hello lightning
world so so we're going to import OS and
we're going to import the rest of what
we need to basically use a m file so
Fromm import load. MV load. M then we're
going to import our financial analyst
crew so it's as simple as from
financialist analy financialanalyst
crew. crew import and then import the
financial analyst crew so now we have
everything we need all right and this is
the entire main file so we're going to
Define run we're going to pass in the
inputs and the only input we have is
company name Tesla and the nice thing is
crew automatically interpolates all of
that for us then we're going to say
financial analyst crew. crew kickoff
we'll pass in the inputs and then we put
this kind of main portion down at the
bottom now let's create our n file and
we're almost done so on the very outside
of this entire folder we're going to
rightclick new file and we're going to
call ITV and we're going to pass a grock
API key right there so I grabbed a new
grock API key and yes I am going to
revoke this key before publishing the
video so that's it grock API key and
then pass it in just like that okay so I
am going to create some tools now and
we're not actually going to create them
from scratch we're just going to use
tools that are currently in the crew aai
examples Library already for us so we
have an SEC tools which is kind of
exactly what we need so let's go ahead
and we're just going to copy the whole
file we'll switch back and then in the
financial analyst crew we're going to
right click and we're going to create a
new folder and we're going to call it
tools then we're going to create a new
file in there and we're going to call it
SEC tools. py and we're going to paste
in all that code so all of this
hopefully will just work out of the box
all right now we're going to use poetry
to put it all together and to actually
run the project so to do that we're
going to first do pip install poetry
then we're going to create a new file
and we're going to call it Pi project.
TL and you don't really have to know how
much of this works and to be honest I
don't really know how much of this works
uh I'm just not super familiar with
poetry but this is the way crew is going
to be done going forward so we're going
to paste in all this stuff and it
basically just sets up poetry for us and
the only thing that we're going to need
to customize is the financial analyst
crew name right there next we're going
to lock the dependencies so poetry lock
all right should be done and there it is
the poetry. loock file perfect then
we're going to do poetry install Okay so
this is installing all the dependencies
now all right there it's done now we
should be able to run it from here so
poetry run financial analyst crew hit
enter uh I missed one thing so I forgot
to actually rename it to what we need so
financial analyst crew right there now
that it's there we should be able to run
it properly so I'm going to do poetry
install one more time just in case all
right now we got no warning so now it
should work poetry run financial analyst
crew all right so I got another module
not found issu so let's do pip install
linkchain grock and I'm not sure why we
have to do do that again but let's try
it hopefully this works okay so let's
run it again all right it looks like we
got it working wonderful wow look how
lightning fast that was okay so let's
see what it did so here we go entering
the chain Final Answer Tesla's ticker
symbol current stock price market cap
getting all this great information about
Tesla and recent news as well then it
passes it on to the financial analyst
and it's doing a bunch of different
calculations okay all perfect and then
we have the ratios and the different
metrics that we asked for and then the
final output perfect look at this
beautiful so it all worked and it was
lightning fast so now we have our crew
set up but it's using Gro which is
fantastic but we want to try running it
with an open- Source model powered by
lightning AI so you can plug in any
model that you want so leave this tab
open all right then we're going to go to
the studio templates page within
lightning. so it's lightning. a/ Studios
and this basically comes with a bunch of
preconfigured Studios that are ready to
go and they have a bunch of them a bunch
of really cool ones from running olama
fine-tuning you can build diffusion
models they just have a bunch of them
all right and it already has this run
mistal mixture of experts and all we
need to do is Click open template right
there so we select select what team
space then click open and this takes a
little while to load up because it's
doing a lot in the background but it
sets up everything for us and then I'm
going to show you how to then expose the
API from oama and then we're going to
take that API endpoint and then power
our model with it all right so it's done
now if we look up in the top right and
we hover over this button we can
actually see that we're using a GPU an
a1g and if we click on it then click
into the gpus we can see we have a bunch
available all the way through A1 100s
h100s and yeah they do cost a lot of
money to run but you don't need these
beefy gpus for all the models but we
will likely need something very powerful
for mixol and now they have L4 support
so you can just get another beastly GPU
running your models but I'll just show
you that we get it working I'm not
actually going to let it do all the
inference because that's not the point
let's continue so once we have that
we're going to come down here and we're
going to click this plus button for the
plugins we're going to go down to
serving and then we're going to do API
Builder and click install once that's
done we exit out of here on the right
side we now have this tab API Builder go
ahead and click that now this is one
that's just by default and you can
actually just go ahead and right click
on it and delete this like that and
we're going to do a new API okay so
we'll keep the name the same and for the
port it's 11434 and that is just o
llama's Port we don't need any
authentication although if we're going
to make this into a production
environment yes you definitely want
authentication then let's enable it then
we're going to click on the name and
we're going to grab this base URL right
there so now this is the endpoint that
is exposed with our open AI compatible
API so now I switch back to our code so
now to do it I'll leave the old code in
there but what we need to do is right
here from Lang chain. llms we're going
to import oama and then we're going to
on a new line create a new llm olama
mixol then we're going to call olama
we're going to pass in the model mixol
and then for this base URL we're going
to enter the URL that we copied earlier
so just like that so then we'll copy
this we're going to comment out this
line and we'll do self. I'll call it
grock llm just to save some time but
we'll call it olama mixol just like that
and it should all work now I believe
there might be one more thing we have to
do but let's give it a try and so poetry
run financial analyst all right and
there it goes so it's probably going to
be pretty slow because it is a very big
model Mixr and we're not using a super
beefy GPU but I just want to show you
getting it working and if we switch back
to the oama studio we can actually see
the GPU going bur right there so you can
see it's it's working right now and
there it goes look at that all right so
if I stop it has a bunch of good
information right there go back look at
the GPU and now it goes down to zero
again so we've confirmed it actually
works so now you know how to structure a
crew and do so in the most modern way
you know how to spin up an open- Source
model with lightning Ai and power it
with their gpus and you know how to
expose the endpoint and plug it into
your crew if you liked this video please
consider giving a like And subscribe and
I'll see you in the next one
استعرض المزيد من الفيديوهات ذات الصلة
![](https://i.ytimg.com/vi/RO-jiWj0VK8/hq720.jpg)
Robocorp Beginners Tutorial - Getting Started with Robocorp RPA
![](https://i.ytimg.com/vi/JLmI0GJuGlY/hq720.jpg?sqp=-oaymwEmCIAKENAF8quKqQMa8AEB-AH-CYAC0AWKAgwIABABGGUgUihPMA8=&rs=AOn4CLDMU6k8dBTOIKV-VhORCAgtRf9cZA)
Python Advanced AI Agent Tutorial - LlamaIndex, Ollama and Multi-LLM!
![](https://i.ytimg.com/vi/X05ORyy7ZW4/hq720.jpg)
GPT-4o AI Agents: Easily Create Medical Research Agents (Praison AI)
![](https://i.ytimg.com/vi/EPdivac0kwE/hq720.jpg)
Create a List of Todo items in SwiftUI | Todo List #1
![](https://i.ytimg.com/vi/LbW9dsKpJO4/hq720.jpg)
Multi-Agent Conversation using CrewAI
![](https://i.ytimg.com/vi/xWDEdkiRA98/hq720.jpg?sqp=-oaymwEmCIAKENAF8quKqQMa8AEB-AH-CYAC0AWKAgwIABABGFEgXChlMA8=&rs=AOn4CLDhcNNcM_W4GgsNUvKicofsoMAADw)
Build an AI code generator w/ RAG to write working LangChain
5.0 / 5 (0 votes)