Skip to main content

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.
Use the CLI command to generate the embed script:
This outputs a <script> tag with configuration for your environment. When targeting the local environment, the command uses your agent’s draft variant. On a production instance, it defaults to using your agent’s live (deployed) variant. The following is an example of the command’s output:
OUTPUT

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).
Example:

Security configuration

Security is enabled by default, but must be explicitly configured. The embedded chat will not function until security is properly configured

Security Architecture

The embedded chat uses RSA public-key cryptography to secure communication. The configuration involves two key pairs:
  1. IBM Key Pair
    • Generated by: watsonx Orchestrate service.
    • Public key: Shared with your application. Your application uses this key to encrypt the user_payload section of the JWT sent to watsonx Orchestrate.
    • Private key: Stored securely by watsonx Orchestrate.cUsed to decrypt the user_payload section of the JWT.
  2. 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.
  3. 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:
  • 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
When security is disabled:
  • 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:
After you configure security:
  1. The tool generates an IBM key pair via the API
  2. The tool generates a client key pair using OpenSSL
  3. Both public keys are configured in the service
  4. Security is enabled
All keys are saved in the wxo_security_config directory:
  • ibm_public_key.pem: IBM’s public key in PEM format
  • ibm_public_key.txt: IBM’s public key in single-line format
  • client_private_key.pem: Your private key (keep it secure!)
  • client_public_key.pem: Your public key in PEM format
  • client_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.

Context variables

To use context variables:
  1. Enable context_access_enabled: true in your agent definition.
  2. Add variables like channel to the context_variables in your agent definition file.
  3. Reimport the agent.
  4. Include context variables in the JWT payload.
You can add context variables to a JWT token using a JavaScript script. The following script shows how to include context variables inside a JWT token in your server:
createJWT
You can check the examples for watsonx Assistant web chat that are mostly compatible with the watsonx Orchestrate embedded chat to see how to use this code example After generating the JWT token, pass it to the embedded web chat. The following example shows how to do that:
JavaScript

Customizing the embedded chat

Header is an optional property in wxOConfiguration that controls whether header actions appear.

Language

Styles

You can customize embedded web chats to create a unique chat interface that better fits your webpage. To apply custom styles, add a style 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. The following is an example of how to customize the embedded web chat using the style component inside window.wxOConfiguration:

Layout

The watsonx Orchestrate embed supports a flexible layout object to control how and where the chat UI appears.
The following is an example of how to customize the layout of the embedded web chat to display it in fullscreen mode:
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 using pre: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
watsonx Orchestrate does not persist feedback internally. You are responsible for storage and analysis. If you want to store feedback on your backend, you can capture feedback data and send it to your own backend API:
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

Message Events

View Events

Security Events

Miscellaneous Events

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

User Interface

Security/Identity

Events

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: