Loading video player...
In this video, we'll use deep agents to
create a deep research example. You can
see here the final result. It'll be an
agent that can write to-dos and then
track them as well. It can also kick off
sub aents. So, it has a research sub
aent and we can see that it will use
this to do specific research queries.
And then we can also see that it has a
critique agent at the end that does
specific critiques as well. And then it
will also write its final output to this
final report.mmd file. And we'll get
back this pretty comprehensive report
for any question that we ask. So in this
video, we'll see how to build this from
scratch using deep agents, a new package
we released for creating agents that can
plan over longer time horizons and go
deeper into particular tasks. Let's see
how it works.
All right, so I'm going to start from
scratch with a blank file. The first
thing I'm going to do is implement a
search tool. Now, this is important
because my deep researcher will need to
do search to find out the answers to
specific sub questions. So, in order to
implement this tool, we're going to use
Tavilli. Tavilli is a search tool for
connecting agents to the web. So, you
can go in, sign up here, get an API key
and all of that. Once we've done that,
let's go back into our code. We're going
to import the Tavilli client from
Tavilli. We can then go ahead and create
an instance of this Tavilli client.
We're going to be looking in our
environment variables for a Tavilla API
key. And so you'll need to make sure to
expose that. So let's import the OS
package so we can import it there.
Great. Now that we have this client,
we're going to write a function that
will be the tool that we give the agent.
So we can write something like this. a
function that takes in a query which is
a string and then also can optionally
take in an integer which is the max
results to include and then also
optionally take in a boolean of whether
to include the raw content or not and
then the description of this of this
function this is important this will be
the description that we give to the
agent when we give it this tool so now
we've got this tool this is going to be
the backbone of our research agent let's
go ahead and actually create a really
simple research agent that just has this
and uses as deep agents. So in order to
do that, we're just going to import
create deep agent from deep agents.
We're going to write some custom
instructions for the deep agent. So
let's call this instructions.
This is pretty basic and that's because
I'm going to actually improve it a bunch
later on, but this is a good placeholder
for now. And then let's just do agent
equals create deep agent
instructions equals instructions tools
equals internet search. And that's
basically it. I now have a deep agent
that will go ahead and do some research.
So let's actually see how to use this.
In order to use it, I'm going to create
this langraph.json file. This is where I
point to the file that contains the
agent and then the name of the variable
where my agent is stored.
From here I can go into the terminal. I
can install langraph C cli and then
after I install this I can do langraph
dev to run a developer server for this
agent.
Going in here I can see the basic agent
here. Let's add in a message and let's
ask it something to research. So let's
ask it what is langraph
and we can see that it starts
by spinning up
this general purpose research sub aent
to research lang graph comprehensively
and all of that. Now while this is
running I'm actually going to improve
the agent.
So let's go back.
So let's go back to this file and let's
add in two sub aents and then improve
the system prompt. So the first sub
agent we're going to add is a dedicated
researcher agent. In order to do that,
we're going to add a dedicated system
prompt just for this researcher.
So this is the subress research prompt
here. And we're then going to create a
dictionary representing this sub
research agent. So we're going to give
it a name, research agent. We're going
to give it a description. And so this is
going to be used by the main agent to
send questions to it. So use to research
more in-depth questions. Only give this
researcher one topic at a time. Do not
pass multiple sub questions to this
researcher. And then I'm going to give
it the prompt. So this is the subress
research prompt above. And then I'm
going to give it access to tools that I
want it to have. And so I want it
specifically to only have access to this
internet search tool. So great, I'm
going to define that there. Now I'm
going to define another sub aent that
I'm going to call the critique sub aent.
And so this is going to be an agent
that's specifically used to critique the
final report that's been generated so
far. So now one thing that I have to
think through is how does this critique
agent know where the final report is?
And for that I'm going to use the file
system, the virtual file system that
comes built in with deep agents. So, I'm
going to modify the system prompt in a
second to say, "Hey, when you've got
this final report, write it to a file
called final report.md." And then this
critique agent is going to know to look
for that final report.md
and then and then and then critique
that. Great. So, let's do this. I now
have this critique prompt. You are
dedicated editor. You bring task to
critique a report. And so, you can see
here that I say you can find the report
at final report.md.
And then you can see here that I also
say you can find the question topic for
this report at question.ext. So one
thing I'm also going to want to do is
prompt this general agent to write down
the original question into question.ext.
So this file system can basically be how
these agents can communicate with each
other in a more structured manner
besides just the messages that they send
in and out. So this research sub agent,
this just used the messages. It just
took in a question that was the message
and it outputed its response as a
message and and it communicated with the
main agent via messages. This critique
agent is now using files in the file
system to communicate. And so this is a
this is a more token efficient way than
passing in the final report every time
to this to this critique agent. So after
I have this prompt, I can create the
dictionary representing the critique
agent. I'm going to give it a name. I'm
going to give it a description. And then
I'm going to give it a prompt. I'm not
going to give it any tools. And so by
default, it will inherit all the tools
that the main agent has access to,
including reading and writing from
files, internet search, to-do list,
things like that. Now, I'm going to go
ahead and modify the instructions. And
so, I'm going to write a lot more
detailed instructions, and there's going
to be a few key parts of that.
So, a lot of this a lot of this prompt
is taken from the deep research repo
that we created earlier and that I'll
link to. And so that's where a lot of
this this detailed prompts comes from.
But I added in a few things specific to
deep agents. So the first thing you
should do is write the original user
question to question.ext. So remember
this is how we communicate the question
the original question that the user
asked to the to the critique agent. So
we tell this this main agent to write it
down. We're then going to use the
research agent. So we're we're
referencing this this specific research
agent above. We're going to use this to
conduct deep research. And then when we
have enough fi information, we're going
to write a final report and we're going
to write it to final report.md. So
again, this is the same file name as we
pass the critique agent. So this is how
it knows how to write to those files.
You you can then call the critique agent
to get a critique of the final report.
After that, if needed, you can do more
research. So we're giving you
instructions on basically how and when
to call these sub agents in a very
dedicated manner. And that's because
this this general purpose research agent
needs those that kind of like knowledge
of when to use these different agents
and and and how we want to
and how we want it to use those those
different agents. And so we're passing
that in the prompt. And so now the last
thing we're going to do is we're going
to go back down here and we're going to
pass in the sub aents that we have.
One last little thing that we're going
to do, we're actually going to set the
recursion limit of this agent to a,000.
So, by default, this is 25, which means
that this agent can run basically 25
different steps, but this is a deep
research agent. It might run for a
while. So, we're going to increase that
all the way up to a,000. If we go back
up to Studio, we can see that the agent
has finished running and it's created
this uh report. It's not super long and
that's because we're using the more
simple prompt and no sub aents that we
had before. So, we're going to try again
with these better sub aents and this
better prompt. Before doing that, we're
actually going to set up deep agents UI
to be able to interact with this agent.
So, this is a GitHub repo that Nick on
our team created and it's basically a UI
for specifically interacting with these
deep agents. It visualizes the to-dos,
it visualizes the sub aents, it shows
the file system. This is what you saw at
the start of the video.
So we've got this running and we're now
going to give it a go. So let's ask it a
question like what is langraph?
And when we kick it off, we can now see
that it streams things back in a nice
manner. So first we can see that it
writes this question.ext to a file.
Again, this is what we prompted it to
do. Now it's creating to-dos. And so if
we go over to the tasks, we can see a
list of what it's doing. And now it's
got one in progress. It's researching
Langraph basics. What is its purpose and
key features? It now spins up a sub
agent. So if we click on this, we can
see the input. And we're going to wait a
little bit for the research agent to
come back, the sub research agent to
come back because that's the research
agent that's doing all of the work.
Here we are about halfway through the
process. And so we can see here that the
original subress research agent came
back with its response and then it
kicked off a few more. And so it's now
running on a third. We can see here that
the tasks two are done. One is in
progress and then it's still got some to
go. So let's check back in at the end.
We can see here that it's created its
research. And so if we look in the
files, we can see this final report MD.
And we can see that we get back a much
better and more detailed report than
before. So this shows the power of using
sub aents and also the importance of
having a really detailed prompt. This is
this is one of the key parts of uh deep
agents in general. They have detailed
prompts. So this is a full endto-end
example of how to build deep researcher
on top of deep agents. Hope you enjoyed.
In this video we will use `deepagents` to build a Deep Research example. This consists of defining a search tool, defining some sub agents, and writing a detailed prompt. Example folder: https://github.com/hwchase17/deepagents/tree/master/examples/research Deep Agents UI: https://github.com/langchain-ai/deep-agents-ui Open Deep Research (where we got the prompt from): https://github.com/langchain-ai/open_deep_research