How to create a Brave Search agent
- Layla

- Oct 24
- 2 min read
Brave offers an alternative search to Google, with a more focus on privacy.
Brave offers an API: https://brave.com/search/api/
If you like to use Brave search instead of DuckDuckGo in Layla, this article will give you a tutorial on how to create your own Brave Search Agent, with your own API key, to replace the DuckDuckGo Agent in Layla.
This is an advanced tutorial. You will learn several methods of obtaining and parsing results from HTTP requests, which hopefully you can use in your future agents!
Register an API Key
The first step is to register on brave.com and get an API key. Follow the instruction on their website. From now on, we will assume you obtained an API key and have it saved somewhere.
Familiarise yourself with the Brave API documentation: https://api-dashboard.search.brave.com/app/documentation/web-search/get-started
We will create our agent using this.
Duplicate the DuckDuckGo Agent in Layla
The easiest way to start is to duplicate the DuckDuckGo Agent in Layla. This will give you most things setup.

After you've duplicated the agent, remove all the tools, but keep the triggers (we want this new agent to be triggered by a web search query as well, and the default DDG agent has that all set up).
Add 4 tools in this order:
Eval
HTTP Request
Eval
Provide Context
We will go through what each tool does and how they connect to each other below.
Eval (1)

The first tool is simple: we need to encode any input as a URI component to send to the API. This is simply the JavaScript function:
encodeURIComponentYour input to the tool will be run through "eval" and the result will be the output of this tool. You can see the "{{input}}" here, which represents the raw text from your input message.
HTTP Request (2)
The second tool is the HTTP request tool, where we will call the Brave Search API. See their documentation here: https://api-dashboard.search.brave.com/app/documentation/web-search/get-started

Note our URL and our Headers. The headers contain the "X-Subscription-Token" is our API key.
You can see our "{{input}}" is in the url query string, which will be sent to the API.
Eval (3)
This is the most complicated tool call to-date.
This tool takes the output from the previous tool call (the HTTP Request), which should be in JSON format, according to the Brave API documentation. So this tool will parse the json, and convert it to plain text, which is then ready to be sent to the LLM.

This tool takes the "{{input}}" as raw string, and assigns it to the "i" variable. Then we call JSON parse on it, which we then map it to a standard bullet point list which will be the output of our tool.
This is all just JavaScript; those of you who are familiar with programming should understand this just fine.
Provide Context (4)
The last step is to take our output and provide it as context to the LLM.

This tool is simple: it gives some context that the results come from Brave API, and instructs your character to tell you about the results.
With these 4 tools, your agent is complete!
I recommend you disable the original DuckDuckGo agent so as to not conflict.
Here is the Agent JSON for you to import directly:


Comments