A domain specific bot addresses queries related to a specific domain or topic. Some examples are - Travel bot(Travel related conversations), Weather bot (Weather related conversations).
If a user wants to have a cross-domain conversation, then the user will have to switch between the different bots.
There are scenarios where an user wants to have a conversation involving multiple domains. For example - When I want to travel to a place, I want to query for the weather and then book a cab or flight. I might have to end up switching between two bots, weather bot and travel bot. What if I could just have one interface bot which will redirect my messages to a specific bot and get answers to me?
Well, this code pattern showcases an implementation of this approach.
The solution here is to have an agent bot (or an interface bot) and a few other bots which can handle conversations for a specific domain - let's call these specific bots. The agent bot knows about the specific bots and also about which domain each of them can handle. When user initiates conversation with agent bot, the agent bot will understand the intent of user query and it will redirect the user query to a specific bot. Subsequent requests from user are redirected to specific bot. When the conversation with the specific bot is over or when the specific bot is not able to handle the request, the control is given back to agent bot which will then redirect the messages to appropriate bot.
This approach provides seamless experience for users. It can be used by organisations which provide a host of services to its customers like financial services, tours and travel agencies, news agencies etc..
Advantages with this approach are:
- Plug and play the bots
- Modular approach facilitates Bots composition
- Come up with new services by composing two or more Bots
- Easy to maintain, make changes, add/remove functionalities
- Easy to troubleshoot issues
- Transparent to user
In this code pattern we will use Watson assistant Bot for building Bots and Node.js application as orchestration layer.
When the reader has completed this Code Pattern, they will understand how to:
- How to configure a bot to make it Agent Bot
- How to configure a specific bot to return control to Agent Bot
- How to build an orchestration layer to stitch Agent Bot and specific Bots
- User accesses web application and types in a message. Nodejs application, an orchestration later, sends user message to agent bot
- Agent bot determines the intent of the message and responds with the specific bot details, to which the message needs to be redirected.
- Node.js application sends message to the specific bot (Weather Bot, in this case). Specific bot responds. Conversation continues between user and specific bot.
- When the conversation with specific bot is over, user message is then sent to agent bot to determine the intent.
- Node.js application sends message to the specific bot (Travel Bot, in this case). Specific bot responds. Conversation continues between user and specific bot.
- Clone git repo.
- Create bots.
- Configure application with bots details.
- Deploy application to IBM Cloud.
- Run application.
- On command prompt run the below command to clone the git repo.
git clone [email protected]:IBM/watson-assistant-multi-bot-agent.git
or
git clone https://github.com/IBM/watson-assistant-multi-bot-agent.git
run cd watson-assistant-multi-bot-agent
to change directory to project parent folder
- Click this link to create Watson assistant service.
- Enter the service name as
Watson Assistant-bots
. You can choose to enter any name you like. - Ensure you select the right region, organisation and space.
- Under
Pricing Plans
, selectLite
plan. - Click
Create
. - Watson Asistant service instance should get created.
- Go to IBM Cloud Resource list and click on the Watson Assistant service instance created in above steps.
- On the Watson Assistant Resource list page, click
Launch Watson Assistant
.
- Click
Skills
tab in the side bar.
- Click the
Create skill
button. - Select the
Dialog skill
box - Click the
Next
button. - Select the
Import skill
tab.
- Click on
Choose JSON file
. - Browse to the cloned repository parent folder -> WA.
- Select
agent-bot.json
and clickOpen
.
- Click
Import
button. - Repeat above steps in section Import bots to import
travel_bot.json
andweather_bot.json
.
- Go to IBM Cloud Resource list and click on the Watson Assistant service instance.
- On the Watson Assistant Resource list page, click
Launch Watson Assistant
. - Click
Skills
tab in the side bar.
- On
agentBot
clickactions
, the three vertical dots on the top right corner.
-
Click
View API Details
. -
Copy and save
Skill ID
for later use. It can be interchangeably used as Workspace ID. -
Repeat above steps in section Configure application with bots details for all the other bots also.
-
Go to IBM Cloud Resource list and click on the Watson Assistant service instance.
-
Copy
API Key
andUrl
using the copy buttons as shown in below image or using theShow Credentials
and copying the field contents. Save them in a text file for later use.
- Under project parent folder, open
manifest.yml
file for editing. - Update
ASSISTANT_IAM_API_KEY
with Watson Assistant service instance's API Key as noted in section Gather required details - Update
ASSISTANT_IAM_URL
with Watson Assistant service instance's Url as noted in section Gather required details - Update
WORKSPACE_ID_AGENT
,WORKSPACE_ID_TRAVEL
,WORKSPACE_ID_WEATHER
with Workspace IDs of respective bots as noted in section Gather required details
Updated manifest.yml
file looks as below
- On command prompt, navigate to project parent folder
- On command prompt, login to IBM Cloud using
ibmcloud login
oribmcloud login --sso
(for federated login). - Ensure that you are in the right organisation, space and region using the below command.
ibmcloud target
- Run the below command to deploy the application to IBM Cloud.
ibmcloud cf push
- Check the logs of the application using the command
ibmcloud cf logs <app_name> --recent
. - Ensure that the application is deployed to IBM Cloud successfully. If you see any errors in logs, fix them and redeploy the application.
- Login to IBM Cloud and from the dashboard.
- Click on
Cloud Foundry apps
. The application you deployed should be listed and it should be in running state. - Click on the application and again click on
Visit App URL
.
- The application home page opens.
- On command prompt monitor logs using the command
ibmcloud cf logs watson-assistant-multi-bot-agent
- On the application home page type a weather related query
What does the weather look like tomorrow?
. - Check the log files and notice that the message first goes to Agent Bot and then it is redirected to the Weather Bot.
- In the interface, you are asked to enter the location. Enter a location, e.g.
Bengaluru
. - Check the logs. Because the conversation with the Weather Bot has not ended, subsequent messages are sent to the Weather Bot itself, without the intervention of the Agent Bot.
- The Weather Bot responds with an answer to user query and hence conversation with Weather Bot is treated as ended.
- Next user enters a travel related query
Book a cab
. - In the logs, notice that the message is sent to Agent Bot and then it is redirected to Travel Bot.
- In the interface you are asked to enter a date for cab booking. Enter a date or you can just say
Today
. - Check the logs. Because the conversation with the Travel Bot has not ended, subsequent messages are sent to the Weather Bot itself, without the intervention of the Agent Bot.
- In the interface you are asked to enter time for the cab to arrive. Say
12 PM
. - Check the logs. Travel Bot responds with an answer. The conversation with Travel Bot has ended.
- The above conversation flow can continue and the Agent Bot will redirect the messages to specific bots based on the intent of user query
- Some of the basic messages as greetings and bye can be handled by Agent Bot itself.
- In the interface type
Thank you. Bye
- Overall Flow of messages between bots is as shown in the below diagram
Legend for above image
- Message sent to Agent Bot.
- Message redirected to Weather Bot.
- Response from Weather Bot.
- Message sent to Weather Bot.
- Response from Weather Bot (end of conversation with Weather Bot).
- Message sent to Agent Bot.
- Message redirected to Travel Bot.
- Response from Travel Bot.
- Message sent to Travel Bot.
- Response from Travel Bot.
- Message sent to Travel Bot.
- Response from Travel Bot (end of conversation with Travel Bot).
- Message sent to Agent Bot.
- Response from Agent Bot (end of conversation).
- To add a new bot, create a new bot in the Watson Assistant service instance created earlier for this code pattern or you can use an existing bot that you want to use. Let's say you added a bot for
Restaurant Booking
and named it asRESTAURANT_BOOKING
. - In
manifest.yml
file, add an entry for new bot as shown below
WORKSPACE_ID_RESTAURANT_BOOKING: xxxxxxxxxxxxxxxxxxxxxxxx
- In the RESTAURANT_BOOKING Bot, when the conversation is over (last node in a dialog), add a context parameter
destination_bot
and value asAGENT
. It enables the control to be passed to back to the Agent Bot. You can refer to the leaf nodes in other already imported bots for examples. - Open Agent Bot. Add an intent for Restaurant Booking, say restaurant. Then in dialog, add a node for restaurant intent. Add a context parameter
destination_bot
and value asRESTAURANT_BOOKING
. - Redeploy the application for the configuration changes to take effect.
- That's it, you are set to you new
RESTAURANT_BOOKING
bot as a plug and play bot.
We introduced an Agent Bot which understands intents of messages. Agent Bot will redirect a message to a specific bot which can handle that message. We saw how to configure Agent Bot, Specific Bots and orchestration application to have this arrangement possible. We also saw how to plug and play this setup to add a new bot.
-
The application page displays but there is no greetings message, when the application pages loads.
- Verify Watson Assistant username and password are correct.
- Verify workspace_id of the agent bot is correct.
-
No response for a chat message Verify workspace_id of a specific bots is correct.
-
If there is any other issue, check application logs using the below command
ibmcloud cf logs <app-name> --recent