Embedding the agent into the web chat
IBM watsonx Orchestrate allows you to embed intelligent agents directly into your web applications using the Embedded Chat feature. This integration supports secure communication, flexible UI customization, and advanced event handling to deliver rich conversational experiences.Why embed agents?
Embedding agents into your application provides:- Real-time interaction: Users engage with agents directly within your app.
- Custom UI integration: Match the agent’s look and feel to your brand.
- Secure communication: RSA encryption and JWT authentication protect sensitive data.
- Context-aware automation: Agents can access encrypted context variables to personalize responses.
- Scalable deployment: Embed across multiple environments using consistent configuration.
Prerequisites
Environments: draft vs. live
- Draft: Used for testing. Embed snippets target the draft variant.
- Live: Available after deployment. Embed snippets default to the live variant in production.
Application requirements
Your application must:- Include a server (local or cloud)
- Have an HTML element with ID
root - Place the embed script inside the
<body>tag - The page that embeds the web chat must use HTML’s strict mode (in clude the
<!DOCTYPE html>tag) - Enable security
Security configuration
Security is enabled by default, but must be explicitly configured. The embedded chat will not function until security is properly configuredSecurity Architecture
The embedded chat uses RSA public-key cryptography to secure communication. The configuration involves two key pairs:-
IBM Key Pair
- Generated by: watsonx Orchestrate service.
- Public key: Shared with your application. Your application uses this key to encrypt the
user_payloadsection of the JWT sent to watsonx Orchestrate. - Private key: Stored securely by watsonx Orchestrate.cUsed to decrypt the
user_payloadsection of the JWT.
-
Client Key Pair
- Generated by: You (or a security configuration tool).
- Public key: Shared with watsonx Orchestrate. Used to verify that JWTs originate from your application.
- Private key: Remains with you and must be stored securely. Used to sign JWTs sent to watsonx Orchestrate.
-
JWT Authentication
- When security is enabled, your application must:
- Generate a JWT signed with your private key (Client Key Pair).
- Include the JWT in all requests to the Embedded Chat API. watsonx Orchestrate validates the token using your public key.
- When security is enabled, your application must:
- All requests to the Embedded Chat API must include a valid JWT token
- The token must be signed with your private key
- The watsonx Orchestrate service validates the token using your public key
- This prevents unauthorized access to your watsonx Orchestrate instance
- Requests to the Embedded Chat API do not require authentication
- Anyone with access to your web application where chat is Embedded can access your watsonx Orchestrate instance. In addition, your Watson Orchestrate instance allows anonymous authentication to a limited set of Apis, which is required to get your embed chat to work for anonymous users.
- This option should only be used for specific use cases where anonymous chat access is required.
- Ensure your watsonx Orchestrate instance in this case, does not provide access to sensitive data or access to tools configured with functional credentials that access sensitive data.
Enabling security
1
Prerequisites
- IBM watsonx Orchestrate instance
- API Key with administrative privileges
- Service Instance URL from your watsonx Orchestrate instance
- On macOS and Linux: OpenSSL installed on your system (for key generation)
- Python Installed on your system (for key extraction from APIs)
2
Get the watsonx Orchestrate security tool
Copy the following automated script to configure security:
wxO-embed-chat-security-tool.sh
3
Change the script's permissions
On Unix-based systems (macOS and Linux), change the permissions to run the script:
4
Run the script
Run the script and follow the instructions to enable or disable security:
- The tool generates an IBM key pair via the API
- The tool generates a client key pair using OpenSSL
- Both public keys are configured in the service
- Security is enabled
wxo_security_config directory:
ibm_public_key.pem: IBM’s public key in PEM formatibm_public_key.txt: IBM’s public key in single-line formatclient_private_key.pem: Your private key (keep it secure!)client_public_key.pem: Your public key in PEM formatclient_public_key.txt: Your public key in single-line format
Anonymous Access
You may disable security for anonymous access, but only if:- No sensitive data is exposed.
- No tools with functional credentials are accessible.
How to embed
Use the CLI command to generate the embed script:<script> tag with configuration for your environment. You can add this script to an HTML page on your website.
The following is an example of the command’s output:
OUTPUT
Example implementation
The following is a minimal implementation example of a server and website running the web chat with security and authentication configured. This implementation uses NodeJS with the Express web application framework. The project uses the following folder structure:example-jwtRS256 keys with the following commands:
Context variables
To use context variables:- Enable
context_access_enabled: truein your agent definition. - Add variables like
channelto thecontext_variablesin your agent definition file. - Reimport the agent.
- Include context variables in the JWT payload.
createJWT
JavaScript
Customizing the embedded chat
Header
Header is an optional property inwxOConfiguration that controls whether header actions appear.
| Parameter | Type | Description |
|---|---|---|
header.showResetButton | boolean | Displays the Reset Chat button in the header when set to true. Default is true. |
header.showAiDisclaimer | boolean | Displays the AI disclaimer icon/button in the header when set to true. Default is true. |
Language
| Parameter | Type | Description |
|---|---|---|
defaultLocale | string | Defines the default language supported by the chat. Supported values: de, en, es, fr, it, ja, and pt-BR |
Styles
You can customize embedded web chats to create a unique chat interface that better fits your webpage. To apply custom styles, add astyle component inside the window.wxOConfiguration object in your web chat script. In this component, you can configure the following elements:
Header is an optional property of wxOConfiguration that controls the visibility of header actions.
| Parameter | Type | Description |
|---|---|---|
headerColor | string | Set a six-digit hex code that defines the chat header color. |
userMessageBackgroundColor | string | Set a six-digit hex code that defines the user message bubble color. |
primaryColor | string | Set a six-digit hex code that defines the interactive elements color. |
showBackgroundGradient | boolean | Displays the background gradient when set to true. Default is true. |
style component inside window.wxOConfiguration:
Layout
The watsonx Orchestrate embed supports a flexiblelayout object to control how and where the chat UI appears.
| Parameter | Type | Default | Description |
|---|---|---|---|
rootElementID | string | — | (fullscreen-overlay only) ID of the container node to mount chat into. |
showLauncher | boolean | true | (fullscreen-overlay only) Show the bubble launcher (true) or render chat immediately (false). |
layout.form | string | float | Defines the layout form of your web chat. Use fullscreen-overlay to display the web chat in fullscreen mode. No additional parameters are required.Use float to display the web chat as a floating window. Also configure:
custom to define a custom layout. Also configure the customElement parameter with your custom element. |
layout.width | string | — | (float only) Popup width (e.g. ‘350px’, ‘30rem’). |
layout.height | string | — | (float only) Popup height (e.g. ‘500px’, ‘40rem’). |
layout.showOrchestrateHeader | boolean | true | Render the standard header bar (true) or hide it (false). |
layout.customElement | HTMLElement | — | element reference to render into. |
JavaScript
Feedback, events and instance methods
Thumbs-up and thumbs-down feedback
In the embedded chat, you need to manually enable thumbs-up and thumbs-down feedback usingpre:receive handlers. First, subscribe to the pre:receive event to inject feedback options. Then, handle submitted feedback through the feedback event.
The following script shows how to configure feedback in the embedded chat:
JavaScript
sendFeedbackToBackend.js
Events
Embedded web chat supports a variety of events that allow you to trigger specific actions or customize behavior. The following tables list all supported events, grouped by category.Customization Events
| Event name | Description |
|---|---|
userDefinedResponse | Triggered when a response contains an unrecognized or user_defined response type. |
Message Events
| Event name | Description |
|---|---|
pre:receive | Triggered before the web chat receives a response from the agent. |
pre:send | Triggered before the web chat sends a message to the agent. |
receive | Triggered after the web chat receives a response from the agent. |
send | Triggered after the web chat sends a message to the agent. |
pre:restartConversation | Triggered before the conversation restarts. Useful for alerting the user that the chat will reset, allowing them to complete any ongoing actions (e.g., finishing a tool call). |
restartConversation | Triggered after the conversation restarts, before a new session begins. Useful for displaying specific UI elements when a new session starts. |
View Events
| Event name | Description |
|---|---|
view:pre:change | Triggered before the view state changes. |
view:change | Triggered after the view state changes. |
Security Events
| Event name | Description |
|---|---|
identityTokenExpired | Triggered when security is enabled and the JWT token expires. |
Miscellaneous Events
| Event name | Description |
|---|---|
chat:ready | Triggered when the web chat is fully loaded and ready to receive user input. Useful for displaying a welcome message or initializing UI components. |
Instance methods
While events are used to listen to the embedded chat, instance methods are used to take actions on the embedded chat. The following tables list all supported instance methods, grouped by category.Message
| Event name | Description |
|---|---|
doAutoScroll | Scrolls to the most recent message in the list. |
scrollToMessage | Scrolls the messages list to a specific message. |
send | Sends the specified message to the agent. |
updateHistoryUserDefined | Updates a user_defined property in message history. Need to store the user_defined in the message_state column of the messages table so that it will appear in the history |
restartConversation | Restarts the conversation with the agent. |
User Interface
| Event name | Description |
|---|---|
changeView | Changes the current view state. |
updateLocale | Changes the display language. Supported values: de, en, es, fr, it, ja, and pt-BR. |
Security/Identity
| Event name | Description |
|---|---|
updateIdentityToken | Replaces the current JWT with a new one for continued secure communication. This is commonly used when tokens expire or are refreshed during a session. |
destroy | Destroys the web chat and removes it from the page. |
Events
| Event name | Description |
|---|---|
once | Subscribes a handler function to an event so it runs only once when that event occurs. After the event fires, the handler is no longer called. |
off | Removes a subscription to an event type. |
on | Subscribes to a type of event. |
Events and instance methods example
The following example shows how to configure events and instance methods in the embedded web chat:JavaScript
API Integration
You can also integrate your agent with external applications by using the ADK’s provided agent completions API. These APIs allow agents to be shared across multiple watsonx Orchestrate instances:- Orchestrate Native Runs API: For long-duration workflows. API Documentation:
- Chat Completions Compatibility Layer: OpenAI-compatible for easy integration. API Documentation:

