Bot with Tovie Data Agent
This lesson shows how to call Tovie Data Agent from Tovie DialogStudio bots. The bot uses HTTP request blocks to get information from the knowledge base.
Tovie Data Agent is an intelligent question-answering system by Tovie AI. It uses large language models (LLMs) and the RAG technology. This system finds the required information in a set of documents and generates answers for users. For more information about Tovie Data Agent, see the website and documentation.
Prepare knowledge base
-
Go to Tovie Data Agent.
tipTo access Tovie Data Agent, contact your account manager or email us at support@tovie.ai.
-
Create a project.
-
Add sources and index the knowledge base. See the Tovie Data Agent documentation for instructions on preparing the knowledge base.
Tovie DialogStudio script
In this script, the bot:
- Creates a chat in Tovie Data Agent.
- Gets a question from the user.
- Sends the question to the knowledge base chat and receives a response.
- Sends the response to the user.
The knowledge base takes into account all history in its chat by default. You do not need to pass the history in the script.
Create chat
-
Create a screen called
Create chat
. Add a HTTP request block to it. -
Specify the HTTP request block settings to call the
POST /api/knowledge-hub/chat
method of the Tovie Data Agent API:- Request
- Response
- Body
- Headers
- Method is
POST
. - URL is
https://data-agent.tovie.ai/api/knowledge-hub/chat
.
Specify a variable:
- Variable name is
chatId
. - Value is
$httpResponse.id
.
The
$chatId
variable stores the Tovie Data Agent chat ID. The bot can send requests to the knowledge base chat using this ID.Enter an empty
{}
object in the field.Add two headers:
-
Header:
Content-Type
, value:application/json
. -
Header:
Authorization
, value:Bearer <token>
, where<token>
is the API key from the Tovie Data Agent project.Example value:
Bearer A1bcdE.abcde1234
.
As a result, the bot creates a chat in Tovie Data Agent at the beginning of the dialog.
Get question from user
-
Create another screen. Name it
Get answer
. Add a text to $var block to it. In the block, specify:- Message:
Ask a question, I will find the answer
. - Variable Name:
question
.
- Message:
-
Connect the Success exit from the HTTP request block to the
Get question
screen.

If the chat in the knowledge base is created successfully, the bot prompts for a question and saves the text into the $question
variable.
Send request to knowledge base
-
Create a screen called
Request to knowledge base
. Add a HTTP request block to it. -
Specify the HTTP request block settings to call the
POST /api/knowledge-hub/chat/{chatId}/query
method of the Tovie Data Agent API:- Request
- Response
- Body
- Headers
-
Method is
POST
. -
URL is
https://data-agent.tovie.ai/api/knowledge-hub/chat/${chatId}/query
.Here, the URL contains the
$chatId
variable. The variable stores the ID that was obtained when creating the chat.
Specify a variable:
- Variable name is
baseAnswer
. - Value is
$httpResponse.response
.
The variable
$baseAnswer
stores the knowledge base response to the user’s question.In the body, pass the user’s question using the
$question
variable:{"query": "$question"}
Add two headers:
-
Header:
Content-Type
, value:application/json
. -
Header:
Authorization
, value:Bearer <token>
, where<token>
is the API key from the Tovie Data Agent project.Example value:
Bearer A1bcdE.abcde1234
.
-
Connect the Transition after entering a $question exit on the
Get question
screen with theRequest to knowledge base
screen.

The bot gets a question and sends it to the knowledge base.
Sending response to user
-
Create a new screen called
Send to user
. Add a Text block to the screen with the response:Answer from the knowledge base: $baseAnswer
. The bot sends the knowledge base response that is stored in this variable. -
Add a Transition block to the same screen and connect the block to the
Get question
screen.

As a result, the bot sends a response to the user. After that, the bot prompts for a question again.
For each new question, the knowledge base prepares a response taking the chat history into account.
Possible errors
Errors when sending HTTP requests
Errors might occur when you send requests in HTTP request blocks. For example, if the Tovie Data Agent token has expired.
To handle such errors, create new screens and connect them to the Error exits of the HTTP request blocks. This way you can inform the user that the HTTP request failed.
Errors when generating response in knowledge base
Errors can occur when the knowledge base is generating a response.
For example, if the generation in the knowledge base ended with an error, the base sends a response, but $httpResponse.status
is set to FAILED
.
To handle such errors, use the Conditions block.
Send a response to the user only if $httpResponse.status
is set to FINISHED
:
$httpResponse.status === "FINISHED"
Script timeout
It can take a long time for the knowledge base to generate a response.
If the knowledge base is generating a response for more than 70 seconds, the bot sends an error message.