top of page

How to create a Brave Search agent

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.


App interface for creating automation agents. Features DuckDuckGo web and news search settings, with options to edit, test, or delete.

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:

  1. Eval

  2. HTTP Request

  3. Eval

  4. Provide Context


We will go through what each tool does and how they connect to each other below.


Eval (1)

Agent editing interface on a dark background, with blue "OR" and "Save" buttons. Text includes "Eval" and JavaScript code details.

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:

encodeURIComponent

Your 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


HTTP request editor with fields for URL, method (GET), and headers. "Edit Agent" and "Save" buttons are present. Dark background.

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.

UI displaying "Edit Agent" mode. The section shows a JavaScript code input panel with code for evaluating search results. Black and gray theme.

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.


UI showing "Edit Agent" with "Provide Context" popup. Toggle option labeled "LLM tool call." Text fields include input instructions. Buttons: Cancel, Save.

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

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Email

Location

Gold Coast, Australia

SUBSCRIBE

Sign up to receive news and updates from Layla

Thanks for submitting!

© 2024 by Layla Network

  • Discord
  • Facebook
  • X
  • Youtube
  • Instagram
bottom of page