AWS Logo
Menu

Create an agent with web search capabilities

Add web search capabilities to your custom agent

Ross Alas
Amazon Employee
Published Oct 6, 2024
Follow me on LinkedIn for more AWS & GenAI-related content: www.linkedin.com/in/ross-alas
In my previous blog, Create your own custom AI agent with Amazon Bedrock and Converse API (Link), I provided a guide on creating your own agent along with a RetrieveUrl tool that allows the agent to retrieve various web links. In this blog post, I'm going to provide you an example of how you can add a web search functionality using Brave Search. You can use other search providers as well like Google, Bing, Yahoo, and others. You'll just have to modify the code provided below.
By providing your agent with search capabilities, you can open up powerful capabilities such as:
  • Accessing up-to-date information to answer questions
  • Automated research (e.g., market research, academic search)
  • Summarize web information
Check out how to set it up below and enjoy!
search results for generative ai, machine learning, and artificial intelligence
Figure 1. Search results for generative ai, machine learning, and artificial intelligence
Disclaimer: You may incur AWS and Brave Search API charges and the following contains only sample code that is not directly suitable for production. Read MIT-0 LICENSE for license info.
Prerequisites
  • Follow the setup here: Create your own custom AI agent with Amazon Bedrock and Converse API (Link)
  • Brave API Data for AI Key to allow you to use the search results for inference
Add your API key to your environment variable
Once you have created an API key, add it to your environment variable.
In Linux/MacOS:
Add web search tool to tools.py
Once you have all of the files created in my first blog created, add the following to tools.py
Modify agent.py to import the new tool
In agent.py, make sure to import the new tool and add the new tool to the agent:
Run streamlit
Once you have made all of the changes above, run the app!
You should now be able to access the local URL displayed in the terminal. Typically http://localhost:8501
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments