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.
<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).
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.
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.
Language
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.
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 flexiblelayout object to control how and where the chat UI appears.
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
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:- Orchestrate Native Runs API: For long-duration workflows. API Documentation:
- Chat Completions Compatibility Layer: OpenAI-compatible for easy integration. API Documentation:

