March 202607:098k views

Build a deep research tool

About

Build your own Claude or Gemini like deep research tool, with just a few lines of code!

Transcript

Everything I said

00:00

We are gonna build our own deep research tool. It's gonna be awesome, it's gonna be cheap, and it's gonna be fast. And it's not gonna take very long, 'cause I got stuff I gotta do, okay? If you haven't used deep research, what the heck are you doing? Uh, go to Claude AI, turn on research mode. It's gonna crawl the internet, it's gonna look at a bunch of sources and try to answer your question. You can do the same thing on the Gemini web app, but what if you want to build your own little tool to do that from the command line?

00:27

Well, you gotta figure out how to search the internet, which is getting harder and harder these days. Good news, though, if you go read the change log, you might find something. But not just any change log, specifically the change log of BrowserBase.com. If you haven't heard of BrowserBase, it says, "We help AI use the web." We love a clear H1, don't we?

00:50

"We help AI use the web." Let's look at the change log. BrowserBase change log. Ha, not that many days ago, BrowserBase introduced BrowserBase Search. This looks nice. All I have to do is do BB.search. Now, on their side, they're managing thousands of browsers. How they do it, I don't super care, not my problem. I don't have to do Playwright, I don't have to do MCP.

01:12

I can just say, "Hey, BrowserBase, you figure it out. Good luck, have fun." That gets us step one. Step two is what do we do with these URLs after we get them? Well, let's see what else is in the change log. Uh-oh, BrowserBase Fetch is available today, not that many days ago. Let's click through. I told you it was going to be cheap, one dollar for 1,000 pages.

01:34

You do the math, 'cause I'm not gonna do it. That's pretty cheap. So let's build our deep research agent. But before we build it, in fact, I've already built it. I will show you how it works, but first I wanna show you that it works. So here we are, NPM run research, and I'm gonna pass it a prompt of, uh, state of browser-based AI architecture. This is a pretty thin prompt, but then it's great for a demo.

01:55

Typically, I would do something a little bit longer. I'm building a desktop app, and I need to know this about Rust and this about how Tari interacts with it, whatever. So we're just gonna run this, and this is just a little, it's a little TypeScript command line application. So it's doing the search. It said it found 75 hits. Across the 75 hits, there are 54 unique URLs, and it's gonna fetch 30.

02:19

All of this is controllable with, um, environment variables that you can pass in, and this code is fully available. Uh, it's, it's open source. You can use it, tweak it, whatever. You'll find the link down in the description below. But you can see we've moved on to the fetch stage, and so it is fetching all of these URLs. I, I, I'll show you the code in a second.

02:40

It's incredibly simple, okay? I didn't have to do any of the browser orchestration. Now, it's moved on to the summarization stage, and this is, um... I just kinda YOLO'd this. I just gave it all to OpenAI and said, "Hey, can you summarize this?" I will continue working on that part, because I have all that rich content, and then I do lose just a little bit in the summarization, and it's not quite as deep as, um, or it's not quite as filled out as Claude's part.

03:06

But the hard part is getting all of that content, and BrowserBase handled that for us. So you can see, saved to, and then it just saves it to this markdown file. So if we were to pull this up in the editor, you'll see, ta-da, we have a deep research report. So here are all the findings, WebMCP, browser use, minimal dependencies, ABP, not something that I'm super familiar with.

03:29

Uh, we have a consensus and contradictions, and then we have the sources down here, and then just a few, uh, uh, diagnostics if you wanna keep going further. Now we have the bones of a research product that can be called from your CLIs, your agents can use it locally, and you don't have to manage, uh, browsers either locally or in the cloud.

03:49

Let me show you just a little bit of the code. Like I said, this is all available open source. You can find it on GitHub, but let me show you just a little bit of the code to see how it works. There's really not much here. There's a lot of scaffolding, but the real, the real stuff is, is pretty thin. Index just serves as an entry point, and then we have discovery over here.

04:10

So if we go up here, you'll see, uh, we've got search with retry. So what we're gonna do here is we're gonna take our BrowserBase ins- instance and just say, "Search." That's it. That's all you gotta do. Search the web. Um, so it's gonna search the web with your query, and the number of results is, uh, configurable. That's one of those, uh, environment variables that you can set.

04:31

So all we do is we search the web. That's it. That's all we do. Um, there are some more heuristics around, like, once the URLs come back, what are good candidates? Uh, we do a little bit of deduplicating. We make sure that we have, like, a diversity of domains to make sure we're not pulling all from one, like, vendor or provider or something.

04:52

And then we have fetch, and fetch is fetch with retry. We pass in our BrowserBase instance, and then we say, "BrowserBase, fetch, create." That's it. And then we pass through the candidate URL, um, and we do wanna follow redirects and potentially use proxies, stuff like that. So I'd show you more of the, uh, BrowserBase interactions, but there's not any more.

05:15

I just pulled in the BrowserBase SDK, set up my environment variables, and then I just call their methods. And who knows what goes on behind the scenes. I don't care. Not my problem. You'll see the synthesis here. Um, we do the summarize chunk, and this is where I hand it off to OpenAI, and I say, "You're preparing evidence for resources. Do this, do that, do that." This is the part I would probably tune up a little bit to have it retain some more of the depth.

05:43

Again, I didn't give it a super in-depth prompt, and so maybe that's why, um, this part comes back as a pretty tight executive summary, which can be helpful. But oftentimes, I want the more in-depth stuff. And you can also imagine after the first round of results comes back and it's synthesized, you send it back through another loop, right? So you ask OpenAI, "Based on this, what else should I search for?" And then you go back to BrowserBase and have that search some more, and you just, you have it in this nice loop, and you can configure, "Eh, maybe I wanna do four

06:13

or five loops," or, "Maybe I wanna stop after 500 results," or something like that. That's, I mean, that's it. Uh, you go look at the code. There's not that much there, and that's because it mostly relies on the BrowserBase SDK and the OpenAI SDK. Uh, BrowserBase does all the complicated browser orchestrating, and then OpenAI does a little bit of that summarization.

06:34

Like I said, it is incredibly cheap. Uh, 1,000 free searches, uh, and then it's one dollar for 1,000 pages. So, uh, mere pennies. Go use it before they figure out it's too cheap. And thank you to BrowserBase for sponsoring this video. This is a product that I have absolutely used before they came knocking, and I still use it to this day.

06:56

So go build your own deep research agent or check out mine on GitHub. Um, feel free to grab it, change it, PRs, whatever. I hope that you enjoyed this, and I hope that you will check out BrowserBase. See ya.

AI & agents

More videos on AI & agents

All videos

Get the next one by email

I’ll send you some more. Not too many.

Join 7,500+ other readers.

Read past issues