Building a Typescript deep research agent
Key Takeaways
Building a Typescript deep research agent using LangChain's DeepAgents JS library, involving detailed prompting, search tools, and specialized sub-agents.
Full Transcript
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.
Original Description
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
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from LangChain · LangChain · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Chat With Your Documents Using LangChain + JavaScript
LangChain
LangChain SQL Webinar
LangChain
LangChain "OpenAI functions" Webinar
LangChain
LangSmith Launch
LangChain
LangChain x Pinecone: Supercharging Llama-2 with RAG
LangChain
LangChain Expression Language
LangChain
Building LLM applications with LangChain with Lance
LangChain
Benchmarking Question/Answering Over CSV Data
LangChain
LangChain "RAG Evaluation" Webinar
LangChain
Fine-tuning in Your Voice Webinar
LangChain
Tabular Data Retrieval
LangChain
Building an LLM Application with Audio by AssemblyAI
LangChain
Superagent Deepdive Webinar
LangChain
Lessons from Deploying LLMs with LangSmith
LangChain
Shortwave Assistant Deepdive Webinar
LangChain
Cognitive Architectures for Language Agents
LangChain
Effectively Building with LLMs in the Browser with Jacob
LangChain
Data Privacy for LLMs
LangChain
"Theory of Mind" Webinar with Plastic Labs
LangChain
LangChain Templates
LangChain
Using Natural Language to Query Postgres with Jacob
LangChain
Building a Research Assistant from Scratch
LangChain
Benchmarking RAG over LangChain Docs
LangChain
Skeleton-of-Thought: Building a New Template from Scratch
LangChain
Benchmarking Methods for Semi-Structured RAG
LangChain
LangSmith Highlights: Getting Started
LangChain
LangSmith Highlights: Debugging
LangChain
LangSmith Highlights: Datasets
LangChain
LangSmith Highlights: Evaluation
LangChain
LangSmith Highlights: Human Annotation
LangChain
LangSmith Highlights: Monitoring
LangChain
LangSmith Highlights: Hub
LangChain
SQL Research Assistant
LangChain
Getting Started with Multi-Modal LLMs
LangChain
Build a Full Stack RAG App With TypeScript
LangChain
Auto-Prompt Builder (with Hosted LangServe)
LangChain
LangChain v0.1.0 Launch: Introduction
LangChain
LangChain v0.1.0 Launch: Observability
LangChain
LangChain v0.1.0 Launch: Integrations
LangChain
LangChain v0.1.0 Launch: Composability
LangChain
LangChain v0.1.0 Launch: Streaming
LangChain
LangChain v0.1.0 Launch: Output Parsing
LangChain
LangChain v0.1.0 Launch: Retrieval
LangChain
LangChain v0.1.0 Launch: Agents
LangChain
Build and Deploy a RAG app with Pinecone Serverless
LangChain
Hosted LangServe + LangChain Templates
LangChain
LangGraph: Intro
LangChain
LangGraph: Agent Executor
LangChain
LangGraph: Chat Agent Executor
LangChain
LangGraph: Human-in-the-Loop
LangChain
LangGraph: Dynamically Returning a Tool Output Directly
LangChain
LangGraph: Respond in a Specific Format
LangChain
LangGraph: Managing Agent Steps
LangChain
LangGraph: Force-Calling a Tool
LangChain
LangGraph: Multi-Agent Workflows
LangChain
Streaming Events: Introducing a new `stream_events` method
LangChain
Building a web RAG chatbot: using LangChain, Exa (prev. Metaphor), LangSmith, and Hosted Langserve
LangChain
OpenGPTs
LangChain
Open Source RAG with Nomic's New Embedding Model (and ChromaDB and Ollama)
LangChain
LangGraph: Persistence
LangChain
More on: Prompt Craft
View skill →Related Reads
📰
📰
📰
📰
Prompt Engineering Without the Guru Stuff
Medium · ChatGPT
Entrepreneurs don’t need more hours. They need better prompts.
Medium · ChatGPT
Why Most People Get Bad AI Answers: Prompt Engineering Explained
Medium · ChatGPT
How Prompt Engineering is Changing the Way We Search for Information!
Medium · ChatGPT
🎓
Tutor Explanation
DeepCamp AI