Before you begin
Make sure you have:- An Algolia account. Create one for free if you don’t already have one.
- Node.js 20.19 or later.
- React InstantSearch 7.34.0 or later.
The
ChatandChatTriggerwidgets require this version. - instantsearch.css 8.15.0 or later. Earlier versions don’t include the chat and AI Mode button stylesheets.
- An API key from a supported LLM provider. For supported providers, see LLM providers.
Start from the product search app
This quickstart extends the product search quickstart. If you completed the quickstart, open that project and skip to Create your agent. To build the app from scratch instead of downloading it, follow the product search quickstart first, then return here.1
Download the product search app
To download the app, run:
2
Add your Algolia credentials
In the Algolia dashboard, open the API Keys page and copy these values:
- Application ID. Identifies your Algolia application.
- Write API key. Used by the indexing script to update records and index settings.
- Search API key. Used by the React app to query the index and call Agent Studio from the browser.
.env.local file and add the values to it:.env.local
Keep your Write API key secret.
Don’t commit
.env.local to version control or expose the write key in your app.3
Index the sample products
Run the indexing script to create the
quickstart-products index,
add sample product records,
and configure product_type as a facet.You should see
Successfully indexed products. in your terminal.
In the Algolia dashboard, you can explore the quickstart-products index on the Browse page.Create your agent
Create an agent that can search thequickstart-products index and answer shopping questions.
1
Open Agent Studio in the dashboard
- In the Algolia dashboard, select your application.
- On the left sidebar, select Generative AI > Get started.
- Under Agent templates, select Shopping assistant.
- On the Shopping assistant page, click Start setup.
2
Add an LLM provider
On the Connect your agent to an LLM provider page,
select an existing provider or create a new one and enter the required credentials.
For more information about supported providers and the required credentials,
see LLM providers.Click Next: Data Access.
The Algolia Sandbox provider lets you test Agent Studio in the dashboard only.
You need to use your own provider if you want to follow this quickstart.
3
Connect an index
On the Define your agent’s knowledge page,
select the
quickstart-products index and click Save.
Agent Studio automatically generates a description for the index.Click Next: Prompt.4
Set up agent instructions
This quickstart uses the default template for a shopping assistant,
with only a few adjustments.On the Guide your agent’s responses page,
replace the following placeholders in the template:
- Replace
{{INSERT_BRAND}}withAlgolia - Replace
{{INSERT_INDUSTRY}}withfashion - Replace
{{INSERT_LANGUAGE}}withEnglish - Feel free to delete the line with the
{{INSERT_COMPETITORS_LIST}}placeholder. This quickstart doesn’t need it, but leaving it in shouldn’t cause any issues.
5
Accept the default entry points, conversation features, and safety controls
- On the Configure how users find your agent page, accept the defaults and click Next: Conversation Features.
- On the Enhance your agent’s conversations page, accept the defaults and click Next: Safety Controls.
- On the Protect your agent’s usage page, accept the defaults and click Complete.
- In the confirmation dialog, click Start exploring. This opens the agent’s details page.
6
Test and publish your agent
On the agent’s details page, you can change all settings,
including the agent prompt and safety controls.
You can also test your agent with a few queries.When you’re ready to use the agent in your app, click Publish.
In the confirmation dialog, click View integration help.
Copy your agent ID.
Add chat to the product search app
Add the React InstantSearch chat widgets to the existing product search app.1
Optional: upgrade your dependencies
If you just downloaded the code with The chat widgets require
npx gitpick, you can skip this step.If you completed the product search quickstart a while ago,
upgrade the InstantSearch libraries:react-instantsearch 7.34.0 or later and instantsearch.css 8.15.0 or later.2
Add your agent ID
Add your published agent ID to
.env.local:.env.local
3
Update the app
Replace Place
src/App.tsx with the following code.
The highlighted lines show changes to the product search app you prepared earlier.src/App.tsx
Chat and ChatTrigger inside the same InstantSearch component as the search widgets.The product search app’s single ProductCard becomes two components,
because search results and agent responses provide different props:SearchProductCardrenders search results with highlighting and snippets.Hitspasses each record as ahitprop.ChatProductCardrenders products returned by the agent’s Algolia Search tool as plain text. TheitemComponentprop ofChatpasses each record as anitemprop.
4
Update styles
Replace
src/App.css with the following code.
The highlighted lines show changes to the product search app you prepared earlier.src/App.css
5
Test the chat
Start the development server:If the server was already running, restart it.
Open
http://localhost:5173.The app shows a product grid, a product type filter, and a search box with an AI Mode button.
A floating chat button is in the lower corner.Select AI Mode and ask questions, such as
Show polka dot pants or What should I wear to a wedding?.
The agent returns matching products from the quickstart-products index.Customize the assistant experience
Add a welcome message and prompt suggestions
Add a welcome message and prompt suggestions
Use Pass Add styles for the prompt suggestions to For more information, see Customize the chat welcome screen.
emptyComponent to show a welcome message before the first chat message.
Prompt suggestions help users start a conversation.Add the prompts and welcome component before the App component:src/App.tsx
ShoppingAssistantWelcome to the Chat component:src/App.tsx
src/App.css:src/App.css
Adjust token and rate limits
Adjust token and rate limits
You set cost controls and rate limits during agent creation in the Safety Controls stage.
You can adjust them anytime to manage LLM usage.
Cost controls limit output tokens, tool or reasoning loops, and conversation length.
Rate limits restrict calls to the agent’s
/completions endpoint.For more information, see Cost control and Rate limiting.What’s next
- Integrate Agent Studio to learn about API and frontend integrations.
- Use tools in Agent Studio to add search, client-side, or Model Context Protocol tools.