Loading video player...
Check this out. I just asked an agent to
answer one of the world's greatest
debates. Is Messi or Ronaldo the
greatest soccer player of all time? This
isn't an easy question to answer, and it
definitely requires a good amount of
research. The agent automatically
spawned two parallel sub agents to look
into each of their achievements. This
meant searching the web over a dozen
times, compiling a comprehensive report
with cited sources. To be extra
thorough, the agent then critiqued its
own report and plugged any gaps that it
found. In the next few minutes, I'm
going to show you how quick and easy it
was to build this with deep agents.
For those of you who might be hearing
the term deep agent for the first time,
I think of deep agents as a more
powerful tool calling loop. The industry
has termed this type of flexible generic
agent as an agent harness.
Deep agents come with a few important
capabilities that extend it beyond the
naive tool calling loop. Deep agents
come with a planning tool to help keep
track of a to-do list for more complex
tasks. Deb aents also come with a set of
file system tools as well as the ability
to connect to a custom file system of
your choice. A popular use case is to
use the file system to offload context
from large tool call results. Another
interesting pattern is to use the file
system to store the agents actual
instructions or memories. So you can
improve the deep agent over time.
Deep agents also have the ability to
spawn sub agents. This makes deep agents
super flexible. It can spawn one or more
sub aents to work on siloed parts of a
complex problem. This keeps the main
agents context window clean while sub
aents are able to focus on narrower
parts of a task. And like I mentioned
before, the deep agents agent harness is
entirely built on lang chain and
langraph.
With these core features in mind, let's
build a simple deep agent together.
The first thing that I'm going to do is
install the deep agents package. I've
written the code for a sample researcher
built on deep agents. As you can see at
the top of the file, we've imported
create deep agent from the deep agents
package. We've also imported the sub
aent type, which we'll use to define a
couple of sub aents later.
For our research deep agent, we're going
to start by defining a web search tool
with Tavi. This is just a normal lang
chain tool. The LLM is going to generate
a simple query and we're going to search
in Tavi and return five results. For a
more custom research agent or for any
other agent, you can define more tools
that connect to other data sources that
are more specific to your use case.
Now that we have a tool defined, let's
define a few sub aents.
Like I mentioned earlier, sub agents are
great for working on isolated multi-step
tasks. Let's think for a second about
how this could be helpful in the context
of research. Some research questions can
be answered with a single internet
search, like what the weather's going to
be like tomorrow. Other questions can be
a lot more detailed. Let's say I want
the agent to plan me a twoe trip to
Japan and Korea where I spend a week in
each. That's going to take a lot more
calls to our web search tool. This is an
example where sub aents can really
shine. One sub agent can be in charge of
planning the Japan leg and another can
focus on Korea.
These are fairly disperate and isolated
tasks and so we can run them in parallel
by kicking off multiple research sub
aents at once. We define the spec for a
research sub aent here. We'll give it a
unique name, a description so that the
main agent knows when to call it, a
system prompt with instructions, and
then our internet search tool from
above.
So that was one sub aent mostly geared
towards context engineering and
isolation. Sub aents can also be really
useful for working on specific tasks
that the main agent doesn't want to
worry about. An example for our
researcher here is a critique sub agent.
This sub aent's sole focus is to
critique the final report that the main
agent wrote. Instead of putting all of
these critique instructions into the
main agent system prompt, we're
isolating these instructions. The main
agent is instructed to delegate work to
this critique sub agent for this task.
Note that our critique agent here is
instructed to critique a file from our
file system. So, the agent is actually
going to write its final report to the
file system and use it as a scratch pad
for the critique agent to then analyze.
Sub aents have access to the same files
that are written to by the main agent.
Now that we have our tool and our sub
aents defined, let's define the main
agent. This is the system prompt for the
main agent. It has instructions on when
to call the research and critique sub
aents and it also has instructions on
how to write the final report. We tie
everything together and create DP agent.
Here we specify that we want to use
sonnet 4 as our model. The main agent is
given the internet search tool to handle
simple queries and it's also given the
research sub aent for more complex
research tasks that can be isolated. We
also have the critique sub aent to
critique and improve our final report.
Now in order for this agent to run,
we're going to need to specify a few API
keys. I've specified a tably API key for
search and anthropic API key for our
model. I've also set up Blinksmith
tracing so we can take a look at what
the agent is doing under the hood.
Let's go ahead and run our agent and ask
it one of the most hotly contested
questions of all time. Who is the goat
Messi or Ronaldo?
I'm going to let this agent work for a
bit and we'll check back in on it when
it's done.
Awesome. Let's step through our trace.
We can see that this ran for good while.
One of the first things that the agent
did was write down its to-dos. The
to-dos include instructions on
researching Ronaldo and Messi. Right
after this, we can see the agent kicks
off two parallel tasks. These are sub
aents dedicated to researching Messi and
Ronaldo. And we can see that these are
kicked off in parallel, which saves us
some time. We can see that the web
search results themselves within these
tasks are a little bit messy, but the
sub aents return clean, crisp responses
with only the essential information to
the main agent.
With all of that information, the main
agent then writes a final report to its
file system with its comprehensive
findings. And after that, we can see
that we kick off the critique sub aent,
which reviews a final report.md.
This was just a simple example of a
research agent. Deep agents is built to
be super flexible as a harness, so you
can extend these pre-built tools however
you'd like. Hopefully, this gave you a
sense of how easy it is to get started
building with deep agents. There's a lot
more coming down the pipeline in both
Python and JavaScript, so stay tuned.
Thanks for watching.
In this video, we will walk through how to easily build a Typescript deep research agent This builds upon our new DeepAgents JS library. All it involves is some detailed prompting, some search tools, and some specialized sub agents Check out the code here if you'd like to follow along: https://github.com/nhuang-lc/research-deep-agent-js/tree/main