Skip to main content
This is a beta feature according to Algolia’s Terms of Service (“Beta Services”).
You can interact with your published agents using HTTP API or use the AI SDK UI for a seamless integration.

Steps for integrating Agent Studio

1

Prepare your agent

Ensure that your agent is configured and published in the Algolia dashboard. To learn more, see Get started with the Agent Studio dashboard.
2

Get your agent ID

On the Agents page in the Agent Studio’s dashboard, find your published agent’s ID.
3

Choose how you want to integrate Agent Studio

  • HTTP API: directly interact with your agent using HTTP requests.
  • InstantSearch: use the InstantSearch.js or React InstantSearch libraries to integrate search capabilities alongside your agent.
  • AI SDK UI: use the React-based SDK for a ready-to-use conversational UI.

API integration

Interact with your GenAI agent directly using the Agent Studio API. Example curl request:
curl 'https://{{"YourApplicationID"}}.algolia.net/agent-studio/1/agents/{{agentId}}/completions?stream=false&compatibilityMode=ai-sdk-5' \
  -X POST \
  -H 'Content-Type: application/json' \
  -H 'x-algolia-application-id: YourApplicationID' \
  -H 'X-Algolia-API-Key: YourSearchOnlyApiKey' \
  --data-raw '{
  "messages": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "What is 1+1 ?"
                }
            ]
        }
    ]
}'
And the response would look like the following:
JSON
{
  "role": "assistant",
  "parts": [
    {
      "type": "step-start"
    },
    {
      "type": "text",
      "text": "1 + 1 = 2"
    }
  ]
}
To continue the conversation, include the previous messages in the request:
JSON
{
    "messages": [
        {
            "role": "user",
            "content": "What is 1+1 ?"
        },
        {
            "role": "assistant",
            "content": "The sum of 1 + 1 is 2."
        },
+        {
+            "role": "user",
+            "content": "What is the sum of the previous value + 3"
+        }
    ]
}

Enable conversation persistence

To automatically save conversations server-side, include both a conversation ID and message IDs in your request:
curl
curl 'https://{{"YourApplicationID"}}.algolia.net/agent-studio/1/agents/{{agentId}}/completions?stream=false&compatibilityMode=ai-sdk-5' \
  -X POST \
  -H 'Content-Type: application/json' \
  -H 'x-algolia-application-id: YourApplicationID' \
  -H 'X-Algolia-API-Key: YourSearchOnlyApiKey' \
  --data-raw '{
  "id": "alg_cnv_abc123",
  "messages": [
        {
            "id": "alg_msg_001",
            "role": "user",
            "parts": [
                {
                    "text": "What is 1+1 ?"
                }
            ]
        }
    ]
}'
Both fields are required:
  • id: conversation identifier (prefix with alg_cnv_ for consistency)
  • messages[].id: unique ID for each message (prefix with alg_msg_)
You can then retrieve the conversation history using the conversations API. For more information, see Conversations.
  • Replace {{ALGOLIA_APPLICATION_ID}} with your Algolia .
  • Replace {{agentId}} with your published agent ID.
  • Use your application’s search-only API key for authentication.
  • The endpoint supports streaming responses and is compatible with ai-sdk v4 and v5.
  • For streaming responses, set stream=true in the query parameters.
  • For production, secure your API keys and restrict usage as needed.

InstantSearch integration

Agent Studio is compatible with InstantSearch.js and React InstantSearch. The InstantSearch integration only supports ai-sdk v5. The benefits of using InstantSearch are:
  • Provides an out-of-the-box chat interface with multiple customization options.
  • Integrates search results alongside your agent’s responses.
  • Handles custom tools with minimal setup.
For more information, see Get started with React InstantSearch and the examples on GitHub.

Examples

import { liteClient as algoliasearch } from 'algoliasearch/lite';
import { InstantSearch, Chat } from 'react-instantsearch';
import 'instantsearch.css/components/chat.css';

const searchClient = algoliasearch('APP_ID', 'SEARCH_API_KEY');
export function App() {
  return (
    <InstantSearch searchClient={searchClient}>
      <Chat
        agentId="AGENT_ID"
        itemComponent={({ item }) => (
          <div>
            <h3>{item.title}</h3>
            <p>{item.description}</p>
          </div>
        )}
      />
    </InstantSearch>
  );
}

Rendering search results

If your agent uses a search tool, you must define item templates or components to control how search results appear in the chat interface. Templates are required for search results. They let you display product information, images, or other data in a format that fits your application.
<Chat
  // ...otherProps
  itemComponent={({ item }) => (
    <div>
      <h3>{item.title}</h3>
      <p>{item.description}</p>
      <img src={item.image} alt={item.title} />
    </div>
  )}
/>
The itemComponent (React) or templates.item (JavaScript) template renders each search result item with custom HTML and styling. If your agent uses a search tool, you must define this template to display search results correctly in the chat interface.

Tools

InstantSearch Chat widgets let you integrate tools in your agent’s responses. Once a tool has been added to your agent in the dashboard, you can customize how it’s rendered with InstantSearch. For a complete guide to configuring tools in Agent Studio, see Tools for Agent Studio.
<Chat
  // ...otherProps
  tools={{
    weather: {
      layoutComponent: ({
        message,
        indexUiState,
        setIndexUiState,
        addToolResult,
      }) => <CustomWeatherComponent message={message} />,
      onToolCall: ({ addToolResult, input, ...rest }) =>
        addToolResult({ output: { temperature: 20 } }),
    },
  }}
/>
The tools prop is an object where the keys are the tool names defined in your agent configuration. Each tool includes a layoutComponent to customize how tool calls appear in the chat interface. The layoutComponent accepts these props:
  • message: a message object with tool call information, including tool input and output. For more information about the message structure, read the AI SDK documentation.
  • indexUiState and setIndexUiState: manage the InstantSearch UI state, useful for updating filters or queries based on tool calls.
  • addToolResult: function to add an output for the tool call. For client-side tools, you must call this at least once before the next message. For more information, see the AI SDK documentation.
You can also provide an optional onToolCall function to run custom logic when the tool is invoked. It receives the same arguments as the onToolCall function in the useChat hook, plus an additional addToolResult function to provide tool outputs.

Prompt suggestions

Prompt Suggestions can be enabled in InstantSearch by enabling the suggestions feature in the Agent Studio dashboard or API. When enabled, the Chat widgets automatically handle and display suggestions after each agent response. You can customize the suggestions layout using the suggestions component or template.
<Chat
  // ...otherProps
  suggestionsComponent={({ suggestions, onSuggestionClick }) => (
    <div>
      <h4>Suggestions:</h4>
      <ul>
        {suggestions.map((suggestion, index) => (
          <li key={index} onClick={() => onSuggestionClick(suggestion)}>
            {suggestion}
          </li>
        ))}
      </ul>
    </div>
  )}
/>

Complete examples

import { liteClient as algoliasearch } from 'algoliasearch/lite';
import { InstantSearch, Chat } from 'react-instantsearch';
import 'instantsearch.css/components/chat.css';

const searchClient = algoliasearch('APP_ID', 'SEARCH_API_KEY');

export function App() {
  return (
    <InstantSearch searchClient={searchClient}>
      <Chat
        agentId="AGENT_ID"
        itemComponent={({ item }) => (
          <div>
            <h3>{item.title}</h3>
            <p>{item.description}</p>
          </div>
        )}
        tools={{
          weather: {
            layoutComponent: () => <div>Custom weather component</div>,
            onToolCall: ({ addToolResult }) =>
              addToolResult({ output: { temperature: 20 } }),
          },
        }}
      />
    </InstantSearch>
  );
}

Filter suggestions integration

You can use the Filter Suggestions widget to display relevant facet filter suggestions powered by Algolia AI Agents. This helps users refine their search with context-aware suggestions. To create this agent, choose the Filter suggestions template in the Agent Studio dashboard. The model used should be a faster, cheaper one (for example gpt-4.1-mini), as suggestions don’t require deep reasoning.

Examples

import { liteClient as algoliasearch } from 'algoliasearch/lite';
import {
  InstantSearch,
  FilterSuggestions,
  RefinementList,
  Hits,
  SearchBox,
} from 'react-instantsearch';
import 'instantsearch.css/components/filter-suggestions.css';

const searchClient = algoliasearch('APP_ID', 'SEARCH_API_KEY');
export function App() {
  return (
    <InstantSearch searchClient={searchClient} indexName="instant_search">
      <SearchBox />
      <FilterSuggestions agentId="AGENT_ID" />
      <RefinementList attribute="brand" />
      <Hits />
    </InstantSearch>
  );
}
For more details, see:

AI SDK UI integration

The Agent Studio is compatible with AI SDK UI, a React-based UI integration for building conversational interfaces. Agent Studio supports both ai-sdk v5 and v4. AI SDK UI isn’t required to use Agent Studio, but it makes the integration process much easier by handling common tasks like UI rendering and state management. The benefits of using the AI SDK UI are:
  • Abstractions over low-level HTTP requests
  • Built-in error handling, retries, and extensibility using middleware and plugins
  • Fast setup for conversational user interfaces
It also allows for advanced use cases, such as:
  • Custom tool handling
  • UI state control
For more information, see the AI SDK documentation.

Installation

npm install ai @ai-sdk/react

Example React integration

React
import { useState } from 'react';
import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport } from 'ai';

const App = () => {
  const [input, setInput] = useState('');

  const { messages, sendMessage } = useChat({
    transport: new DefaultChatTransport({
      api: `https://${'YourApplicationID'}.algolia.net/agent-studio/1/agents/${agentId}/completions?stream=true&compatibilityMode=ai-sdk-5`,
      headers: {
        'x-algolia-application-id': 'YourApplicationID',
        'x-algolia-api-key': 'YourSearchOnlyApiKey',
      },
    }),
  });

  const handleSubmit = (e) => {
    e.preventDefault();
    sendMessage({ text: input });
    setInput('');
  };

  return (
    <>
      {messages.map((message) => (
        <div key={message.id}>
          {message.role === 'user' ? 'User: ' : 'AI: '}
          {message.parts.map((part, index) =>
            part.type === 'text' ? <span key={index}>{part.text}</span> : null,
          )}
        </div>
      ))}

      <form onSubmit={handleSubmit}>
        <input value={input} onChange={(e) => setInput(e.target.value)} />
        <button type="submit">Submit</button>
      </form>
    </>
  );
};
Last modified on February 24, 2026