Example: Research Assistant
Beam’s agent framework is designed for concurrency and synchronization. In this example, we’ll show how you can deploy an app that scrapes online product reviews.
You can follow along with the tutorial in the video below.
Why Beam?
Beam’s Petri Net framework is ideal for workflows that require concurrency and scalability. This app uses Beam to:
- Retrieve Google Shopping URLs for a product name you provide to the bot.
- Scrape review pages for those products.
- Summarize reviews into a report.
Pre-requisites
You’ll need three API keys to run the example below:
- Firecrawl API key (free), used for scraping product pages
- SerpApi API key (free for 100 searches a month), used to retrieve Google Shopping URLs
- OpenAI API Key
Set up your environment variables by adding these keys to a .env
file in your project directory.
Setup
Defining Locations
Locations represent the states of data flowing through the network. In this app, we’ll use three states:
- ProductName: The product to search for (i.e. “headphones”)
- URL: URLs of product pages retrieved from Google Shopping
- ReviewPage: Online product pages with customer reviews
Define these locations in your code:
Create the Bot
Let’s setup the bot, which is what manages the workflow. Add your API keys and define the locations (states) it will manage.
Adding Transitions
Transitions are events or actions in your bot, triggered by changes to the locations (state).
Retrieve Product URLs
The first transition takes a product category (e.g., “headphones”) and uses SerpAPI to retrieve Google Shopping URLs for the product.
Scrape Review Pages
The second transition scrapes review pages from each product URL using Firecrawl.
Summarize Reviews
The final transition summarizes reviews from all the scraped pages into a markdown file.
Pay close attention to the inputs
field below. This transition will not begin running until 3 ReviewPage
markers have been created from the previous transition.
Once deployed, you’ll be able to see the tasks in the dashboard, with the transition waiting until all ReviewPage
markers have been emitted.
Deploying the Bot
Deploying the bot gives you access to a dashboard, where you can interact with the bot using a Chat UI.
What’s next?
With the bot deployed, there are a few things you can try:
Create a Public Chat Page
You can create a public, sharable Chat Page for your bot by adding an authorized=False
argument to the bot
:
When deployed, this gives you a sharable Chat UI. You can retrieve the URL to the Chat UI by clicking next to the “lock” icon.
Here’s what the Chat UI looks like:
Add Interactivity
We provide a number of helper commands using a class called context
.
Context variables can be used for prompting the user for input, creating blocking requests to the bot, and sending message to the user.
Available Commands
Method | Description |
---|---|
context.confirm() | Pause a transition until a user says yes or no. |
context.prompt() | Send a blocking or non-blocking request to the model (e.g., “summarize these reviews”). You can pass an optional wait_for_response=False boolean to make this non-blocking. |
context.remember() | Add an arbitrary JSON-serializable object to the conversation memory. |
context.say() | Output text to the user’s chat window. |
context.send_file() | Send a file to the user from a transition. |
context.get_file() | Retrieve a file from the user during a transition. |
View The Code
You can see the full code for this example below.
Was this page helpful?