Before you begin
- You need an Algolia application with the Agent Studio feature and the Comparison component enabled.
- To preview a configuration, you need an agent with an Algolia Search tool connected to an index.
- To integrate a configuration, your storefront needs the InstantSearch
chatwidget.
How product comparison works
- Users select products from the search results with a Compare toggle on each hit. The comparison bar shows the selected products.
- When users select Compare, the comparison bar opens the chat and sends a comparison request that names the configuration. The selected records travel with the request.
- Agent Studio replaces the request with the instructions from the configuration before calling the model. The chat doesn’t show a user message for the request: users go straight from the Compare button to the agent’s answer, and the comparison bar clears the selection.
- The default instructions tell the agent to compare the selected records with the
algolia_compare_productstool. The table has one column per selected product and one row per comparison criterion. The values come from the product records. Missing values are marked as “not listed”.
Create a comparison configuration
1
Open the comparison configurations list
In the Agent Studio dashboard, open your agent, go to the Components section, and select the Comparison component.
2
Create a configuration
Select Create and fill in:
- Name. An internal label. It’s not used in the integration.
- Goal. What the comparison should help users do.
- Instructions. Extra guidance for the agent, such as which attributes matter most.
Choosing a goal replaces the Instructions text.
Editing the instructions switches the goal to Custom.
Configure the selection limits
In the configuration editor, adjust how many products users can compare at once:- Minimum products. The minimum number of products users must select before they can compare. The default is 2.
- Maximum products. The maximum number of products users can select. The default is 3. The maximum is 6.
Customize the system prompt
The Advanced section shows the system prompt sent to the model. The default prompt tells the agent to compare the selected records with thealgolia_compare_products tool, take every value from the records, and mark missing values as “not listed”.
To write your own system prompt, turn on Customize and edit the text.
Keep the instructions to render the table with algolia_compare_products, take the values from the selected records, and mark missing values as “not listed”.
Preview a comparison
Use the live preview to test a configuration before you enable it:- Select an Index connected to your agent through an Algolia Search tool.
- Use Add product to search for records and add them to the selection, within the configured limits.
- Select Run comparison.
Enable and integrate a configuration
1
Enable the configuration
Turn on the Enabled toggle and save.
The agent only applies a configuration to compare requests once the configuration is enabled and saved.
2
Copy the configuration ID
Copy the Configuration ID from the editor.
Configuration IDs are stable: you can change the configuration’s behavior without updating your integration.
3
Add the widgets to your storefront
Select Integrate, choose an integration option, and copy the generated code.
In InstantSearch, pass the configuration ID and selection limits to For a custom comparison bar or toggle, use the
CompareBar (React) or compareBar (JavaScript), next to your hits and chat widgets.
The comparison bar shows the selected products but doesn’t render a way to select them:
add a Compare toggle to each hit that reads the shared selection from the render state.useCompare Hook (React) or the connectCompare connector (JavaScript).
For examples and configuration options, see the comparison widget reference for React or JavaScript.Compare from a single button
On pages without search results, such as the home page or a product page, you can start a comparison from one Compare products button. The button opens a dialog with a regular search interface: a search box, hits with a Compare toggle, and a Compare button. When users select Compare in the dialog, the dialog closes and the chat opens with the comparison. The pattern uses the same widgets as a results page, inside a<dialog> element:
- The search box and hits inside the dialog belong to the same
InstantSearchinstance and index as the chat widget, so the comparison request reaches the chat. - The Compare button in the dialog comes from
useCompare(React) orconnectCompare(JavaScript). Theircompare()function returnstruewhen it sends the request, which is when to close the dialog. - Keep the widgets in the dialog mounted while it’s closed, so the chat widget has an entry point when it starts. InstantSearch runs an initial search for the hidden hits.
Render a comparison table from product records
The chat widget includes a renderer for thealgolia_compare_products client-side tool.
The table has one column per selected product and one row per comparison criterion.
When you enable a comparison configuration, Agent Studio adds this tool to your agent, and the default instructions tell the agent to use it.
While a configuration is enabled, the tool’s name and input schema are read-only in the agent’s Tools list.
Without the tool, the agent writes the comparison as a Markdown table in its answer.
The agent passes the product object IDs and the criteria to algolia_compare_products, along with optional introductory text.
Each criterion has a label and one value per product, taken from the product records, including details from the descriptions.
The chat widget renders each product header with the same item template as the search results, using the records it holds: the selected products and any search results from the conversation.
Missing values appear as —.
While a configuration is enabled, you can edit the tool’s description from the agent’s Tools list, the way you edit the instructions.
The model reads the description to decide when to call the tool and what to pass, so use it for guidance that applies to every comparison, such as “Lead with price”.
The tool name and input schema are fixed, because the chat widget renders the table from them.
Select Reset to default to return to the default description.
If you manage the agent through the API instead, add the tool to the agent’s tools as a client-side tool, in the shape the Agent Studio API expects:
JSON
null, or shorter than the list of products appears as —.
To change how the table looks, override the comparison tool in the chat widget’s tools object,
using CompareProductsToolType as the property name.
For more information,
see the chat widget reference for React or JavaScript.
Send a compare request without InstantSearch
If you don’t use InstantSearch, send the compare request to the completions endpoint yourself. The user message text is a placeholder that names the configuration, and the selection travels as per-turn context:Command line
- Replace
CONFIGURATION_IDwith the configuration ID, in both the placeholder and the turn context. The match is case-sensitive. - The placeholder must be the entire text of the user message. A message that wraps it in other text passes through to the agent unchanged.
selected_productsis the selected records serialized as a JSON string. Remove internal attributes such as_highlightResultbefore serializing them.
data-prompt-shortcut part with the placeholder as sentinel and an empty displayText:
don’t show a user message for the request, as the InstantSearch chat widget does.
If the configuration doesn’t exist or you turned it off, the message passes through unchanged, so only send the placeholder for an enabled configuration.
For the request schema, see the Agent Studio API reference.
Manage configurations
From the configurations list, you can:- Search configurations by name.
- Duplicate a configuration to use it as a starting point. The copy is turned off by default.
- Delete a configuration. Disable it first: you can’t delete an enabled configuration.