Ready to lead an AI revolution? Watch and learn how to build your own CrewAI from the ground up using the latest CrewAI features, and get set to deploy an army of AI agents at your command. This video is your ultimate guide to creating a powerful digital workforce, enhancing your projects with intelligent automation and streamlined workflows. Discover the secrets to customizing AI agents, setting them on tasks, and managing a smooth operation with CrewAI. It’s time to amplify your tech capabilities, and after this tutorial, you'll be equipped to engineer an AI crew that transforms any complex challenge into a simple task. Start your journey to AI mastery with CrewAI today!
Timestamps: 00:00 Introduction 00:59 4 Major CrewAI Updates 06:28 Setup Project & Dependencies 09:53 Setup Agents in Crew 12:59 Setup Tasks in Crew 17:51 Setup Main.py with Agents and Tasks 24:00 Setup Tools 28:47 Setup Callback to Save Newsletter to Markdown File 30:43 Run Crew 33:21 Showcase Crew Results - Final Newsletter 34:27 Outro
Hey guys, welcome to this updated Crew AI tutorial where you're going to learn how to use Crew AI's
brand new features to build an AI newsletter from scratch. And what I think you're going to love
about this tutorial is that we're going to build a crew which searches the internet to find the
latest AI articles to condense everything into one great looking newsletter that looks just like
this. And what's super cool about the newsletter you'll be building is that it follows the same
format and style that a bunch of famous Twitter accounts have used to generate followings of
hundreds of thousands of users. So all around, if you're looking to learn more about Crew AI and
its latest features, and to see how this technology works in the real world, this is the video for you.
And before we get started, I just want to mention that you can grab all the source code for this
video completely for free. All you have to do is just hit that link down in the description below.
And if you want to see more content just like this in the future, be sure to hit that like and
subscribe button. But enough of that, let's go ahead and dive into the four major updates of
Crew AI and then get on to building out our Crew AI newsletter. So the reason I'm making this video
for you guys today is because the creator of Crew AI just posted on X that he released a new version
of Crew AI that's more reliable and comes with a lot more features for us to use. And the main
features that we're going to be focusing on in this update is the fact that we can now make things
hierarchical, we can also start using asynchronous task, we can start working with expected outputs
and callbacks. Now, I know these might not make sense now. So let's go ahead diving into each one
of these new features covering what it is and how it works. So the first major update for Crew AI
is that it now supports hierarchical processes. And basically, in simple terms, that means our
crews now have a chain of command, where we have a manager agent who coordinates the rest of the
crew and delegates tasks to each one of the agents and validates the outcomes that each one of the
agents produces. And from what I've seen in my own experience, this new hierarchical process
produces much better results and much more consistent results than the previous process,
which was sequential. And in the sequential workflow, basically task and the crew were
executed one after another in a very linear fashion. And like I said, sometimes things just
got lost in context and just the order didn't make sense. So like I said, this new approach
and process works much better and produces much better results. And the great part is that it's
super easy to implement. All you need to do in your code to make this change is you need to
update your crew to update the process to now say that things are hierarchical instead of saying
that they're sequential. And the other thing is you need to set up a manager LLM. And this manager
LLM is basically going to be the brains behind orchestrating all the different agents in your
crew. So like I said, just set up manager LLM and you can use OpenAI or whatever LLM you'd like to
use. So enough of this new process, let's go ahead and move on to our new feature, which is going to
be asynchronous task. So the next major update for crew AI is that it allows us to use a synchronous
task execution. And the best way I like to describe this update is pretending that you and I are
writing an AI research paper. So in the old way, what we would do is hire a research student to go
off and research the history of AI. A few minutes would pass, they'd give us some updates and we'd
go, great. Now go research the ethics of AI. Great. Okay. Well now find us some of the thought
leaders of AI. And each one of those tasks takes a few minutes to operate. So all in all, maybe 10
minutes for everything. Well, what we could do now with a synchronous task execution is that we could
go ahead and find our five research tasks that we want to execute in parallel. So, you know, go find
the great thinkers, go find the history, the ethics, the new tools, and we could run all those jobs in
parallel where each job, you know, might take two minutes and because they're running in parallel,
the whole job will now take two minutes instead of 10 minutes. So this really speeds up the way
we're able to run our crews and gets us results much faster. And it's also super easy to use this
new asynchronous feature. All you have to do on your task is to say, if you want to use it
asynchronously is you just set async execution to be true. And what's cool is let's pretend that
you want to then, you know, aggregate all of your asynchronous tasks and look at their outputs.
Well, all you need to do on another task is say, I need to set context of these five asynchronous
tasks that I just triggered off. And this will make a lot more example. Once we start building
out our code example later on, but I just want you to know that this is the basics of working
with our new asynchronous task. So let's go ahead and move on to our next feature, which is going
to be expected outputs. So like I just mentioned, the next major update for crew AI is that it
allows us to add in expected outputs for our task. Now, this is a super simple feature,
but it really improves the quality and reliability of our task. So let me just give you a concrete
example real fast. Let's pretend we had a list ideas task. Well, what we could do is say, Hey,
my expected output for this task would be five bullet points with five ideas for an article.
That way there's no confusion on what this task needs to output. And what I've also found
really helpful is to go ahead and give an example output in the expected output. This really makes
sure that there's no confusion on what the task needs to be producing. And you'll see a lot later
when we're building out our AI newsletter, we're going to be making a lot of use of this new
expected output feature. Okay. So let's go ahead and move on to the fourth and final new feature,
which is going to be callbacks. And the final feature that we're going to be focusing on
our callbacks and callbacks are super simple. Just think of them as functions that get called
whenever one of our tasks finished running. So let me give you a concrete example. Let's
pretend that we had an idea generation task that generated five ideas about AI. Well,
what we could do is set up a callback to either print out the results of our newly founded ideas,
or we could maybe set up a callback to send out emails to people to share those newly generated
ideas. Or in our case, what we're going to be doing later is we're actually going to be saving
those newly generated ideas to a CSV file. So you'll see this actually in practice later on
in this tutorial, but those are the four major features that we're going to be focusing on for
this crew AI task. And if you would like to see more information about working with crew AI in
general, I actually made a complete crash course for beginners. So you can go ahead and click the
card in the upper hand corner of the video, and you can go watch the entire crash course.
If you want to understand the basics and fundamentals of crew AI, but for this tutorial,
we're mostly going to be focusing on these brand new features so that you can see how everything
works in action. So let's go ahead and start building out our new crew AI newsletter from
scratch. I'm super excited. Let's go ahead and dive in. All right, guys. So now we're onto the
fun stuff where we're going to go ahead and actually start diving into the code. And just
to paint a roadmap of where we're about to do next, I'm first going to create a new folder,
then we're going to set up all of our dependencies for our project. And then we're going to dive into
the fun stuff where we're going to create our agents, our tasks, and our tools using all the
features we've covered so far. So let's go ahead and dive into the first step where we're going to
make our folder. So we're going to do is just say, make dir, and I'm just going to call it crew AI
new feature tutorial. Let's go and make this folder. And then what I'm going to do is head
over to visual studio code, and I'm actually going to go open up that project real fast.
So let's see. Yep. Here's our new folder. Fantastic. So now that we've opened this up,
what I'm going to do is go ahead and make the few files and folders that we need to make our
lives easier. And the first thing I'm going to do is go ahead and make a pie project.toml file.
Now, this might be a little weird if you haven't seen it before, and I'm not going to go into too
much detail on this one, just because I covered a lot of this in my previous video where I do a
complete crash course on crew AI, but I'm just going to go ahead and paste it so that you guys
can actually like see, see what's happening. And at a high level, what we're trying to do is just
go ahead and actually define all of the dependencies that you and I need to run this
project. And the most important ones are going to be, obviously we need to have Python to run our
project. Then we're going to use crew AI. Most importantly, we're going to be using the new
version of crew AI. This is super important that you get version 0.11 or anything greater. And then,
you know, we're just going to make sure we get our environment variables and so forth and so
forth. So that's the main thing that we're going to be doing. And what we're going to do next is
I'm going to go ahead and create our main file and our main files. Obviously we're going to be
running all of our code and I'm just going to go ahead and just stub out some to do for us.
So we know the direction we're going to be taking this app. So the first thing that we're going to
be doing is setting up our agents. The next thing that we're going to do is set up our task, and
then we're going to be setting up our tools. So this is the order that we're going to be building
everything today. And what I'm going to also do now that we have that set up is actually go ahead
and install our dependencies so that we can actually won't run into any issues as we start
building out each one of these. So all we need to do is if we do a control back tick, you can
actually open up your terminal. And what you need to do is, like I said, we're going to be using
poetry to actually install our pyproject.toml file. And that's actually set up inside of my
ZSH terminal. So I'm just going to have to switch to that real fast, but what I'll have to do,
and you'll see more of this, like I said, in that crash course again, but all I have to do is just
type in poetry install dash dash no dash root. And that's going to go ahead and install all those
dependencies that we just talked about a few seconds ago. And it's going to make our lives
very easy going forward. So I've been loving this new way of actually installing and creating
new projects and setting up all the dependencies for them. Okay, cool. So now that we got that out
of the way, let's go ahead and actually open up our new poetry file. So we can see that everything's
working. So we just type in poetry dot shell, and this will create our new environment. So you can
see it's spawning a new shell and a look at that and showing that we're working with our new AI
newsletter project. Fantastic. And we can just make sure that it's working. If I just run print,
hello, fantastic. And then we're just gonna run Python main. Fantastic. All right. Yep. Everything
is working. So let's go ahead and start diving into the first task where we're actually going
to start setting up all of our new agents for crew AI. And when I go ahead and set up agents,
the first thing I like to do is actually go ahead and create a new agents file inside of my file
explorer. So that's what I do real fast. I'm trying to call it agents.py. Now, what we want to do
inside of this agents.py is create a class that's going to be able to return all of our different
agents. And we'll talk through each one of them real quick. But the important thing to note is
that a lot of the new features that we've discussed in the rest of this video actually do not come
from working with agents. Most of the new features we've talked about come from the crew itself and
also with task. So we're going to speed through this section really fast. And I'm actually just
going to go ahead and actually just paste all of the different agents and then walk you through
why we're doing what we're doing. So right out of the gate, we need to have four different agents
to run our program. And what they're going to be are the editor agent, who's kind of directing and
overseeing the entire process of creating our newsletter. The important thing that you'll
with this agent is that I'm actually setting max iterations. And that just allows us to make sure
that we don't end up in an endless loop where this runs 200 times just to make a newsletter.
We just want to be very quick. So this was one of the new features where they made it a little
bit more robust and actually make sure that we get a great output after this many iterations.
And the other thing that's important is we're allowing this agent to delegate work to other
agents. So that's super important because we want people to be able to like, Hey, I need this type
of information, you know, newsfetcher. Can you please go grab me that few other things? We have
our newsfetcher. This is the agent that's going to go out and search for the top AI news stories.
And what you'll notice for this agent, that it actually has a tool and these tools allow it to
go out and search the internet. So you'll see how we build this in just a little bit outside of that.
We have the news analyzer agent who goes out and actually, you know, makes a detailed summary of
the articles that they read. And then finally we have the news compiler agent who takes in
all the different content we've read from all the different articles and all the bullet points
and detailed markdown summaries into one final cohesive newsletter that we're going to send
out to all of our viewers. Okay, cool. So a few things that we need to do on our side,
you'll notice I'm getting some squiggly marks under agent. And the reason why we're getting
that is because we haven't actually imported that proper library yet. So, you know, from crew AI,
we want to import our agent. And what you'll notice is we're getting a squiggly under crew AI,
which is odd because we've already obviously installed all our dependencies earlier. And
that's because we haven't updated our visual studio code to start using our new Python
environment that we created a second ago. So all we need to do is go ahead and open up your terminal.
And what we're going to do is you'll notice whenever we spawned a new shell, it told me
exactly where it lived. So what I can do is just copy that address right there, click that Python
version down at the bottom. And what I can do is you'll see it says enter interpreter path. So I
click that link. I can paste in our new poetry environment that we just created, press enter.
And what you'll notice is it now says the exact Python environment that we just created. And
you'll notice the squigglies go away because obviously we've installed everything. One other
thing you'll notice is that we're getting some issues with our search tools, but Hey, we're
going to work on building those search tools in the third step of this tutorial, but give yourself
a pat on the back. You just set up some awesome agents. And now we're going to move over to go
ahead and setting up all of the tasks that need to run inside of our crew and to create our task.
All we need to do once again, open up our file Explorer, and then we're just going to make a
task.py file. And this one is going to be very similar where once again, we're just going to
make a class and this is going to be an AI news letter. And then we're just going to call it task.
So it's going to be a class. Now this one, what I'm going to do is I'm actually going to walk
you through each of the three tasks we're going to make and actually walk you through
why we're doing it and talk about how we're implementing the new features. So the first
task that we want to do is actually go off and fetch the news task that we're calling earlier.
So we can go out and grab all the new AI news stories. Now, let me walk you through what's
new about this function. So the first thing is we're obviously going to go off and start doing
asynchronous execution. And this is super important because this allows us to go off and fetch
five to 10 different news stories all at the same time. So that's the first one.
And the second one is we're going to start using expected stories. Now, in the past,
what we would have done is just say, Hey, go fetch the top news stories in the past 24 hours.
And that's just kind of what would happen. It just would have grabbed it. But what we can do
now is say, no, with my expected output, I want my stories that you go grab to include titles,
URLs, and a brief summary of each story for the past 24 hours. And then I go ahead and almost
generate an example array where we have little JSON objects of like, yep, this is exactly what
needs to come back so that I will be able to go off and manipulate and read all of the different
news that you go back and generate for me. Fantastic. And the next thing that we're going
to start doing is going ahead and actually analyzing the news that gets sent to us.
Now, this one is a little bit longer. So let me walk you through it. So once again,
we have a description of, Hey, go grab the new stories and just make sure we have at least
five well-formatted articles for our news. Then what we're going to do is once again,
we're going to have asynchronous task. So this will allow us to analyze different
news articles at the same time. And what is interesting is that we have context.
Now, if you remember from earlier, whenever we start executing a synchronous task,
there was also the ability to provide context and context was basically saying like, Hey,
whenever the previous task finishes, feed the output of it into this task. So in our case,
our analyze news task, where we're going to like, make sure that we're pulling out all the
necessary information from research articles. So we're basically going to be feeding the
output of this task into here, which is going to be the context of this task. So I hope that makes
sense where we're feeding this task into this task. And this is all happening because everything's
happening asynchronously. And once again, we're also going to be using expected outputs where
we're going to say like, Hey, when you go out and search for new stories and you get a breakdown of
I want your output to look just like this. So as you can see, everything's nice and formatted.
We're getting out the exact information, a rundown of what happened, the details and why it matters.
That's exactly what we want our output to look like. And the third task that we're going to be
focusing on is going to be the compiling or compilation of the newsletter itself. And for
this one, what you're going to notice is not only are we passing in the agent and the context,
we're also going to start working with callback functions. And that was one of the major new
things that we started talking about earlier. So for this one, what we're gonna do, let's go
part by part. Once again, we're going to be compiling newsletters using our context. And
this one's important because this compilation task is actually going to be receiving the inputs from
this previous task. So you can kind of see how we're slowly building up the chain where we start
off researching, then analyze, and then compile everything down into one final newsletter. So
that's just kind of the flow of how this crew is operating. And once again, what you can see,
that's pretty cool with this expected output is that we start off with a description of what we
want and provide once again, a great example of exactly what we want to see in the final output
to make sure we get really consistent and reliable results. And in this case, we just want to say,
Hey, these are the top news stories with the headlines. And then we go on and do a deeper
dive into each one of those stories with a rundown, the details and why it matters for each one of
those. And this is the same format that's getting used. Like I mentioned earlier in some of the top
performing newsletters that are out there on X right now, where they have hundreds of thousands
of readers. So this is going to produce some awesome results for us, but what we're going
to go ahead and do next is actually go ahead and clear up some of these squiggly marks.
So the first thing is you'll notice that we're missing task. So what we need to do for task
is this time, instead of importing agents, we need to import a task. So from crew AI,
I want to import a task. Fantastic. And the next squiggly mark that I see is for date time. So all
we have to do to import date time is just say, Hey, from date time, import date time. Fantastic.
So now this is all cleaned up. So what we're going to do next is we're going to hop over to
our main.py file and let's go ahead and actually start entering in some of the puzzle pieces that
we have just built so far. So the first thing that we want to do is go ahead and add in all
of our agents and we need to import them first. So what we're going to do is we're just going to
agents are equal to, and this is just going to be our AI newsletter agents. And this is what we
made earlier. And then we're going to have our task, which are just going to be our AI newsletter
task. And now these are obviously squiggly. So we need to go ahead and import those two.
So super simple, just from our agents file, import the AI newsletter agents. And then from our task
file, import the AI newsletter task. Great. So that's looking good.
And the next thing that we're going to start working on now that we have our agents is we're
going to go ahead and set them up. So this is going to be super simple. We're just going to
pull out our editor agent, and this one is just going to be agents dot editor agent. And then
our newsfetcher is going to be our newsfetcher one and so forth and so forth for the rest of
our different agents that we've just talked about. Fantastic. Now, what we're going to do is I'm
going to pull up our task side by side so that you can see why I'm passing in what I'm passing in.
Okay. So let's start off with a fetch news task. Now for this one, we're going to do is say fetch
news task. And then for this one, what you'll notice is all we need to pass in is an agent.
In this case, we want the newsfetcher to fetch the news. That's pretty straightforward. The next one
is going to be our analyze news task, news task. And for this one, we're going to do is just
basically, uh, uh, you gotta love a co-pilot filling in the right information, but what we
can do for our analyze news task is pass in the agent who in our case is going to be the
news analyzer that we created earlier. And then we want to pass in the context. Well, in our case,
what is the context that we want to pass in? And this is where things get a little bit interesting.
Well, we actually need to do is actually break this up and put it in array. And, um,
just because you can pass in multiple items to a context. So it's super important to remember
in our case, the only piece of context that we want to pass in is our fetched news items.
And this is basically just going to allow us to, like I said, start slowly building up from
researching the internet, analyzing what we've learned, and then building out a final newsletter.
Great. So I'm going to keep moving this to the side so that you guys can actually see what we're
And the final thing that we're going to do is go off and build our compile newsletter task.
And this one, um, this one's going to be a little bit longer than the rest. So let me go ahead and
show you what's happening. So we're going to go and create the task, pull it out from over here.
And then what you'll notice in our final version is we need to pass in the agent,
the context and the callback. So those are the three different items we need to pass in as
parameters. So in our case, um, we need to work on our agent who's going to be the news compiler.
Then we need to pass in our context, which is the previous task. Like it's, it's kind of cool that
you can see that we're building up. And then finally, we're going to pass in a callback.
Now we don't have any yet. So I'm going to put it to do to say, add callback function.
Fantastic. So now that we have that set up, what I'm going to also do is let's just go ahead and
skip a step. And we're going to actually go ahead and build our crew real fast so that you can see
how everything ties together. And then we'll fill in a few of those final missing puzzle pieces for
you guys. So we're going to go ahead and create a crew. And what we want to do with our crew is
we want to pass in our agents and that's just going to be everything we created up here. So
that's super straightforward. Then we're going to work on our task. Now our tasks are just going to
be these three tasks we created right here, super simple. And then this is where we're going to
start using some of the newer features. And more specifically, this is where we're changing things
to go off from sequential over to hierarchical. So all we have to do is just say process is equal
to process dot, and then we'll just hierarchical. So higher are kickle. Fantastic. And then lastly,
if you remember from the earlier training, we have to start defining a manager LLM in order
to just start actually using the hierarchical process. So that's what we're going to work on
implementing these next. Okay. So we're getting a few squigglies. So let's clean up these squiggle
marks and then actually go ahead and get this, uh, filling the missing puzzle pieces. So the
we're just going to say from crew import our crew, sorry, from crew AI, that was my bad crew.
And then we also want to import our process. This is what allows us to change, like I said,
between sequential and hierarchical. So that's looking great. And then the next thing is we need
to define our manager LLM that we want to actually run the entire orchestration and set up the chain
of command. So in our case, what I'd like to do is actually go ahead and just set up like a general
open AI, open AI GPT four. So just write it up here. I'm just gonna go ahead and initialize one
real fast and we'll just do something like this. So just open AI is equal to a chat, open AI.
And once again, more squiggles. So let's go ahead and knock those out real fast. And this one's
pretty straight forward. We're just going to use Lang chain for this, or we're going to say from
Lang chain and then open AI. I just went to import chat, open AI. Great. Things are looking good.
So let's go ahead and actually start using this in our LLM down here. Fantastic. So what you might
notice is that so far I've mentioned that we're going to use a hierarchical process to go off
and orchestrate and make sure there's a chain of command in that things are getting operated in a
top-down fashion inside of our crew. But what's cool is if you actually to like dig into what is
happening under the hood with crew AI, you'll see whenever we go with a hierarchical process,
there's actually a prebuilt agent. That's a manager that actually looks just like our other
agents right here, but it's just, you know, it's just defined to be a manager agent. So that's
pretty cool. That crew AI goes ahead and sets up a manager agent for us whenever we start using
hierarchical. Okay, fantastic. So now that we have went ahead and actually kind of set up a
little bit more of like the final output so that you guys can see what it looks like to actually
add in the new hierarchical process. Let's go ahead and start actually working on the next task,
which is going to be setting up our tools. More specifically, we want to go off and start
searching the internet. So let me show you how we're going to do that. So to set up our tools,
all we need to do is once again, open up our file Explorer. And what we're going to do is just make
a new folder. And we're just going to call this tools just because in most projects, you'll
actually have a bunch of different tools. So we want to keep things nice and organized. So the
first thing we need to do is just go in here and create a init.py file, just so that Python
recognizes that this is a directory. And then we're going to go off and actually add our tool,
which we're just going to call search tools.py. Now, what I'm going to do in here is I'm actually
just going to go ahead and like paste what the final output is, is because I've already described
in the previous crash course on why we've set up everything inside of this search tool. But let me
walk you through what's happening at a very high level. And if you want more detail, feel free to
go watch the entire free crash course that I set up earlier. So what's super important about this
is we have set up a tool that, and we know we've set up a tool because we've added the tool
decorator to this search internet function. So this is what allows the crew to recognize that
it has the ability to actually use this tool. And what it's going to do is we're going to pass
in a query. And this query is what we're going to pass into SERPR, which is a tool that allows you
to go off and search the internet. So what you actually need to do is if you haven't used SERPR
before, all you need to do is come over here, SERPR.dev. And like you said, you can see it's
the world's fastest and cheapest Google search API literally takes a second and produces a ton
of great results. So just sign up if you haven't before, but whenever you do finally sign up,
you'll be brought to a dashboard just like this to where you can see how many free credits you
have left. And like I said, it's free to use. So I definitely recommend using it, but what you need
to do is come over here, create API key. And what you can do is just click reset key. And so I'll
go ahead and show you how you guys can do this. You'll click reset key and then copy it. And once
you've copied it, what you're going to do is we're going to actually open up our .env file. And this
.env file is where we're going to go off and store all of our environment variables. So I'm just
going to come in here and paste it, but more specifically, we need to give a name to this
new key. And you can actually see it over here in the tools. It's our SERPR API key. So we're
just going to say SERPR API key is equal to that. Fantastic. And now that we've set up our tool with
our key, what it's going to do is go off and search the query in the internet. More specifically,
it's going to be looking for news articles. What we're going to have happen from here is it's going
to actually try and just make sure that there was no errors when it was searching the internet.
And then what it's going to do is create a quick string from all the information it got from its
top five results that it was looking up when it searched the web. So it's going to pass us back a
link to the actual article itself, the date, which is super important because we're building an AI
newsletter and we only want to make sure we're including stuff that comes from the past 24 hours.
So this date field that we get back whenever we use SERPR is going to allow us to make sure we're
not putting stuff in that was, you know, from three months ago. So this is going to make sure
we're getting the latest and greatest. And like I said, this is just going to return back a list of
internet search results back to the rest of our code. So now that we have this set up,
what we can actually do is start importing it in the rest of our code. So if you remember back in
our agents file, we had some tools that we said that our agents can go off and use. So all we
need to go off and actually start fixing these wigglies is we need to import the search tools
that we just created. So all we're going to do is up top, we're just going to say from our tools
folder and our search tools file, I want to import the search tools class. Fantastic. And this will
actually resolve all of our issues. So fantastic. You've just set up your new tools for your agents
to use. So let's hop back to our final main.py to go ahead and actually finish clearing everything
up because we're almost done guys. Y'all have crushed it so far. So the few other things that
we need to do to actually go ahead and get this crew to run is we need to go off and actually
grab our open AI keys and actually update our environment variables so that our open AI can
actually, you know, go off and do everything it needs to do inside of the crew. So let's go ahead
and grab our open AI keys real fast. So all we need to do over on open AI is go ahead and click
that we want to go over to the API. And once we've done that over here on the left hand side, we can
click API keys. And once we're here, we can go ahead and create some API keys for our project.
So I'm just going to go ahead and say, this is our crew AI updated. This is going to create a secret
key. So make sure you protect this secret key and don't share it with anybody. So I'm going to copy
it and we're going to head back over to our code. And it's important that you name this the proper
key. So you just got to call it open AI API key, because this is what open AI is going to search
for by default. So now that we have our key pasted in, what we're going to do is finish tying up a
few loose ends. So one of the main loosens that we haven't got to do yet is implementing this callback
function. And the reason we're going to create this callback function is because we want to
save our newsletter to our local, basically to our computer. Once it's done, it created,
and it's going to be saved as a Markdown file. So what we're going to do is go ahead and create
a new file and we're going to call it our file.io.py. Now what this is going to do is allow
us to save our final, like I said, our final newsletter as a Markdown file. So let's go ahead
and save it and let's start working on this. So like I said, this is going to, we're just going
to call it save Markdown. And what we're going to do is we just want to like go ahead and pass
in what we want to do, the task output. Now the task output is going to have a results to it.
And you'll see that in just a second, but the main thing we want to do, let me just like for speed
sakes, just show what we're gonna do. We're going to go ahead and get today's date because that's
what we're going to use as the name of the file. So we're going to set the name of the file to be
today's date.md. So it's Markdown. And then we're going to write the output of our task to inside
the Markdown file. And the way we can grab the result of the task is just say task output dot
result. And that's how we can grab the string content of our output. And then we're just going
to print that, Hey, you know, everything was saved properly. Fantastic. And then once we need to do
to go ahead and fix our missing dependencies, we're just going to say from datetime, import
datetime. Well, this is looking great. Y'all are crushing it. And then what we're going to do,
whenever we head back over to our main.py, what we can do now is actually update our callback
function. And what we're going to do is just say that we want to use our save, basically save
Markdown. So I'm just going to say, save Markdown. And then now we need to go import it. So just head
back up top. And what we're going to do is just say, um, one second, we're just going to go ahead
and say from our file.o file that we just created import, save Markdown looks great. And now that's
looking fantastic. And the only other things that we need to do before we can run it is let's go
ahead and scroll back down. And now that we've created our crew, it's up to us. You just go ahead
and kick it off. So what we're going to do, just say, you know, kick off the crew. So this is going
to be results as equal to, you know, crew.kickoff. So that's how you kick off the crew. And then
we're just going to print out the final results when the, when the crew's done. So we're just
going to say crew work results. Fantastic. Copilot is too smart sometimes. And then we're just going
to print the results. Okay, fantastic. So let's go ahead, try running this role fast, and then
we'll debug if any issues come up. So all we're going to do is go ahead, open up our terminal
again. And now we're just going to run python.main.py to go ahead and actually run our new crew.
And then this should start kicking off everything and start trying to generate our new AI newsletter
that will, it will later go ahead and actually save, but we actually ran into a quick error.
So let's go and fix this real fast. And it says, cannot import the name AI newsletter. So I think
we actually misnamed something. So let's go ahead and fix that real fast. And I know what we need
to do. If you just actually head back over to our agents file, what you'll notice is that it's
looking for agents plural. So we're just going to update the spelling of that, save it real fast,
try running it again, and hopefully things will work better this time. And Oh, we ran into one
more small error. Once again, we misnamed it. So AI newsletter task. So if we head over to our task
file, go ahead and copy this. We just misspelled it, put a lowercase L. Okay, cool. So let's go
ahead, rerun it again. And I think we're almost there at the very end. Finally, it did not find
our open AI key. And that's just a very quick issue that we need to resolve. All we need to do
is actually just load our environment variables that we have saved over here. So this one's super
simple. Just go back to your main.py file. And right up at the top, what we're going to do is
actually just go ahead and say, Hey, I want to load all the environment variables that I have
saved so that we can use them throughout the rest of our project. Okay, great. So let's go ahead,
try running it one more time now that we're in the home stretch. And then, all right, our crew
is off to the races. So what it's going to do, it just go ahead and run for a few minutes where
it's actually going to go ahead and work in the new hierarchical structure to where it's going to
go off and search for some cool new AI articles. It's going to take out, yep, like you see, this
is the exact expected output that we got or we're looking for. And this is our tool, our search tool
going off and actually grabbing the title, the link, and then sometimes it can't find the date,
but it will try if it can. And then it'll go off and generate snippets. And then, you know,
it's just going to keep going from there. So what I'm gonna do, and like, this is what I was saying
earlier to her, it's using that expected format that we set up. So like I said, what we've been
talking about actually does work and it actually does get implemented in our code. So what I'm
gonna do is I'm just gonna let this run for a few minutes and then I'll go ahead and show you
the final markdown file that'll get saved over here with today's date of February 20th in just
a little bit. All right. So our crew just got done generating our AI newsletter and it's honestly
pretty awesome. So today's February 20th, 2024, and the results it got were awesome. So literally
within the very past few days, Sora just came out and there's a ton of buzz on the internet right
now where people are talking about how this is awesome, what it's going to replace. And then
it's pretty cool that our newsletter follows the exact same format that we set it up earlier in our
expected output section. And what's also pretty cool is that this article actually just broke
six hours ago where the U.S. is now actually setting up an AI task force to make sure that
they're basically enforcing regulation. So this is breaking in real time and our AI newsletter found
it and put it in a format that we could now go share off in our newsletter. And then I guess
there was also some more interesting new articles about how I guess AI compares to the T-Race from
back in the day. So like I said, this is pulling out recent information that's happening in the
24 hours and putting it in a way that can be synthesized by our viewers and actually,
you know, hopefully save us some time while we go off and grow our newsletter and make millions.
But that's it for this video, guys. I hope y'all enjoyed this updated Crew AI tutorial where you
got to learn how to use the new updated features of Crew AI and you got to build your own AI
newsletter. So if you enjoyed this tutorial, I definitely think you'll love some of the other
AI tutorials I have on this channel. I also recommend checking out whichever video YouTube
has recommended for you over here on the side of the screen. But until next time,
I can't wait to see you guys and hope you have a great day. See ya.