Integration Guide
Embedded Agent
The @smartdatahq/embedded-agent
package is a powerful tool for integrating AI-driven conversational agents into your web applications. This guide will walk you through the installation and setup process.
Prerequisites
Before using the @smartdatahq/embedded-agent
package, ensure the following:
You have Node.js (version 14 or higher) and npm installed on your system.
You have a valid identifier to connect to the @smartdatahq/embedded-agent
service. Make sure you contact us to get your identifier.
Installation
To install the package, use npm or yarn:
Using npm
Using npm
Basic Usage
Here is an example of how to integrate the embedded agent into your React application:
Import the Component
If your application is mostly SSR, you might need to dynamically import the package since it needs to run on the browser. For example, in next.js, you would want to import it like this
Configure the embedded agent
Use the following example to set up the agent in your application:
API
identifier (Required)
contextSchema
Notes: The contextSchema is defined in compliance with JSON Schema draft-07. This ensures the agent uses a well-defined schema for extracting and validating context data.
Learn more here: https://tour.json-schema.org/
onContextJsonUpdate
onSearchResult
Additionnal API
You can also customize the embedded agent with additional props, including:
className: Custom class for styling the embedded agent container.
minimized: Default minimized state of the embedded agent. If being used, you need to update it to match the value you get from the onMinimizedChange function.
onMinimizedChange: Callback for changes in the minimized state.
isRendered: boolean. You can set this to false if you don't want the agent to show on render. Instead, we will display a message that can be clicked to load the agent. This is false by default. If set to true, the agent is displayed instead of the message prompt.
onChatbotRender: This function is called when the agent is rendered. It only runs if you set render to false and manually click the message that displays in place of the agent.
isRendered: boolean. You can set this to false if you don't want the agent to show on render. Instead, we will display a message that can be clicked to load the agent
onError: Callback for handling errors.