Logotype Sitevision Developer
Log in
Log in

Working with AI Assistants

AI Assistants are powerful tools you can use to build AI-powered solutions for your website. They combine the strengths of artificial intelligence to handle questions and requests, together with your organization’s specialized knowledge and expertise.

Published: 2025-11-03  |  Updated: 2026-04-30

What are AI Assistants?

AI Assistants combine a Large Language Model (LLM), a knowledge base set up through a Retrieval-Augmented Generation (RAG) framework, and a set of custom instructions. This allows you to create tailored solutions and assistants specifically relevant to your needs.

What are my options when creating AI Assistants?

When creating an AI Assistant for your website, you have two options:

  1. Use the general Assistant module provided by Sitevision through the Sitevision Marketplace External link..
  2. Build your own custom solution.

In this article, we will explore the second option.

User Story

We want to create an easily accessible place on our intranet where employees can ask questions related to their work, for example: how to document expenses, what benefits are available, or what career options they have.

The intranet likely contains all this information, but it can be difficult to find. An AI Assistant can help by finding and presenting the right answer when you ask a question.

Setting Up an Assistant

First, we need to create an Assistant in your website’s site settings. To do this, you will need an AI service and a knowledge base. See the following three tabs.

Site settings tabs needed for ai assistants

AI services

In the AI services tab you can find the available LLMs on your site. The Sitevision AI service is the LLM that is provided. If you have other AI Services you want to use this is also possible given the correct license agreement.

AI Services tab

Knowledge

In the Knowledge tab you define the scope you want to use. The more specific you can be the better. You want to create Expert Assistants to generate as precise answers as possible. If a too wide scope is defined irrelevant or conflicting information might be supplied to the AI. As with any search based functionality, only include what should be accessible. A great experience begins with great data.

Edit knowledge base

A knowledge base is not limited to only internal information from your website. You can also import external sources, allowing you to centralize all your information in one place.

Assistants

In the Assistants tab you combine and define the packaged Assistant. Select an AI Service you want to use and select the Knowledge you want to base the responses on. Additionally you can define a behavioral prompt.

By default, and it is always included, is a simple prompt Sitevision defines internally to control the basic behavior. Answer in markdown format, answer only based on the provided knowledge, and the current date to better handle time related questions. Therefore you do not need to provide a system prompt, but you likely want to add some custom instructions. For example define some tonality instructions, if you want certain keywords highlighted, if you want the responses to include counter questions etc. Test and iterate to find an additional prompt that works for your use case.

Edit Assistant behavior

With these instructions and restrictions defined we can start using an assistant. For example using the Assistant module available through Sitevision marketplace External link..

Example conversation with the assistant module provided by sitevision through sitevision marketplace

More custom solutions might be necessery and of course Sitevision provides a SDK to easilly work with Assistants in your own tailored apps.

Let's explore the aiAssistant SDK

The aiAssistant SDK is the utility you want to use when building conversational assistant solutions. We have looked at how to set these up in the site settings and visualizing the result in the Assistant module. But how do I build my own module based on this technology?

The basic workflow contains three main steps:

  1. Create a conversation.
  2. Fetch knowledge related to the user query.
  3. Let the assistant answer the question and stream the result to the client.

Example

Let's look at some code snippets.

Configuration

First we need to make an assistant available in our application. The best way to achieve this is to create a selector in our app's configuration. This can easily be achieved with ResourceLocatorUtil.getAiAssistantRepository() External link. from the Public API and a custom-selector.

config/index.js - Get assistant options
js
(() => { const router = require("router"); const resourceLocatorUtil = require("ResourceLocatorUtil"); router.get("/", (req, res) => { const aiAssistants = []; resourceLocatorUtil .getAiAssistantRepository() .getNodes() .forEachRemaining((aiAssistant) => { aiAssistants.push({ id: aiAssistant.getIdentifier(), name: aiAssistant.getName(), }); }); res.render({ aiAssistants, }); }); })();
config/index.html - Add options to the custom-selector
html
<div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><%= i18n('settings') %></h3> </div> <div class="panel-body"> <div class="form-group"> <label><%= i18n('assistant') %></label> <select name="aiAssistant" data-component="custom-selector" data-removable required > <% aiAssistants.forEach(function(aiAssistant) { %> <option value="<%- aiAssistant.id %>"><%- aiAssistant.name %></option> <% }); %> </select> </div> </div> </div>

That's our configuration done. When the module is placed on a page the admin needs to select an assistant before proceeding.

Client - Initiate request

We will focus on the aiAssistant SDK parts, but let's include some client code as well.

Imagine a simple textbox or input field where the user can submit a question. When the user sends their questions we need to initiate a request which will be able to handle a streamed answer.

App.js - Send the request
jsx
const App = () => { const [responses, setResponsesState] = React.useState([]); const conversationIdentifier = React.useRef(null); async function onSubmit({ query }) { const url = router.getStandaloneUrl("/query"); const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", [security.csrf.getHeaderName()]: security.csrf.getToken(), }, body: JSON.stringify({ input: query, conversationIdentifier: conversationIdentifier.current, }), }); ...

Define the endpoint

Define an endpoint for the query request. In our example we need to collect the input and conversationIdentifier parameters and fetch our assistant node.

index.js - Define the endpoint
js
import aiAssistant from "@sitevision/api/server/aiAssistant"; import appData from "@sitevision/api/server/appData"; import router from "@sitevision/api/common/router"; router.post("/query", (req, res) => { const aiAssistantNode = appData.getNode("aiAssistant"); const { input, conversationIdentifier } = req.params; ...

Create a conversation

Now let’s start exploring the aiAssistant SDK. As mentioned earlier, the first step in the main workflow is to create a conversation. However, we do not want to create a new conversation every time we make a request.

For follow-up questions, we should continue the existing conversation instead of starting a new one. In other words, a new conversation should only be created when it is the beginning of a new interaction. Otherwise, we reuse the previously created conversation for any follow-ups.

index.js - Create conversation
js
if (!conversationIdentifier) { conversationIdentifier = aiAssistant.createConversation(aiAssistantNode); }

The createConversation function will return a string. This is an unique key for the conversation.

Fetch knowledge

We want to create a specialized assistant, so we need to collect the specific data it should use to generate its answers. Without this data, the LLM will answer according to its general training knowledge, which may not reflect the specialized context we need.

To get relevant data from the Knowledge base we have set up along our assistant we need query it. This is done with the function querySemanticIndex.

index.js - Query the knowledge base
js
const searchResult = aiAssistant.querySemanticIndex(aiAssistantNode, { query: input, maxHits: 3, }); let texts = ""; searchResult.forEach(({ text }) => { texts += text + "\n\n"; // Add a clear separation between different texts }); if (texts.length < 1) { return "No relevant information found."; }

In this example, we only retrieve the text result from the knowledge base.

However, you can also access additional metadata, such as the source id (and additional properties for external sources). This allows you to include richer context about each source, which can help the AI provide more informed and relevant answers.

Ask the assistant - options

Our last step is to give the assistant the relevant information we have gathered and let it answer the question. Here the askAssistant function comes in handy.

First we need to define the options. Four are required:

  • conversationIdentifier - the conversation key
  • message - the query
  • onChunk - How to handle each chunk in the stream
  • onFinish - How to handle the end of the request

In this example we will use one optional property, knowledge. Here we insert the knowledge we previously collected to base our answer on. If this is omitted, the LLM will answer according to its training data which might be highly irrelevant to a business specific assistant. The property is optional, but you most likely want to provide it.

index.js - askAssistant options
js
const options = { conversationIdentifier, message: input, knowledge: texts, onChunk: function (chunk) { res.send(chunk); if (chunk && chunk.trim().length > 0) { res.flush(); } }, onFinish: function (result) { if (result.error) { console.error("Failed to generate ai response, cause: " + result.error); return res.status(500); } }, };

There are more optional options to utilize, consult the documentation for more information.

Ask the assistant

When our options are defined we can initiate the stream. We set a few headers to make sure there are no problems when streaming our answer.

In this example we send the conversationIdentifier as a custom header to be able to store this on the client, and resume the conversation in follow up questions. You could also create the conversation in a separate call, create it on page load, save it in the user session or something else. Figure out a fitting solution for your use case.

When our status and headers are set. Initiate the anwer by calling the askAssistant function.

index.js - askAssistant
js
res .status(200) .set("Content-Type", "text/plain") .set("Cache-Control", "no-cache") .set("X-Conversation-Identifier", conversationIdentifier); aiAssistant.askAssistant(aiAssistantNode, options);

Client - handle response

By calling the askAssistant function we initate a stream. On the client we need to handle this. Consult the following snippet as a simple example.

App.js - Handle the response
jsx
// Continues from the previous client snippet... if (!response || !response.body || !response.ok) { const error = new Error("No response from server"); error.status = response.status; throw error; } const reader = response.body.getReader(); let result = ""; while (true) { const { done, value } = await reader.read(); if (done) { break; } const text = new TextDecoder().decode(value); result += text; const response = { message: result, }; setResponses((responses) => { const newResponses = responses.slice(); newResponses[newResponses.length - 1] = response; return newResponses; }); } if (!conversationIdentifier.current) { // Save the conversation identifier to be able to continue the conversation for subsequent messages conversationIdentifier.current = response.headers.get( "X-Conversation-Identifier" ); }

Example finished!

That's a wrap for our example. The example snippets used in this article are copied (with some modifications) from an example app freely available on GitHub External link.. See the ai-assistant-recommendations External link. package. Check this one out along with more example projects from Sitevision.

aiAssistant - additional funtions

This example focused on the three main funcions in the aiAssistant SDK. However as of writing there a three more functions available. Here's a very brief explanation on how and when you can use these.

askLLM

The askLLM is a function used to ask the LLM a question. This is not a streamed response so you need to wait for the response to fully finish before proceeding. Use this for supplementary functions to create more advanced functionallity in the assistant you are building.

For example:

  • Check what type of question the user sent - to handle the response in another way with the option additionalInstructions in the askAssistant function.
  • Rewrite the user query to supply the AI with more information if maybe demographic or target audience is important to the way it should respond.
  • Maybe you need to ask the user to supply more information before you can proceed with the query.

getConversationMemory

Previous messages in the conversation can be accessed through the getConversationMemory function. If you need to check something in the history in relation to a new query before proceeding, this is an option.

getConversationKnowledge

The last set of knowledge used can be accesed with getConversationKnowledge. This way you can reuse the last set of knowledge if the user asked a simple follow up question.

In closing

AI is a powerful tool which allows you to create solutions which can help and guide the user to complete their task more efficient.

The aiAssistant SDK alllows you as a developer to create a conversational AI with a few simple steps.

Take an extra look at the aiAssistant documentation and our exemples on github External link. and start experimenting!