AWS Logo
Menu
From 'Bonjour' to 'Boarding Pass': Multilingual AI Chatbot for Flight Reservations

From 'Bonjour' to 'Boarding Pass': Multilingual AI Chatbot for Flight Reservations

Create a global flight reservation chatbot in minutes! This tutorial walks you through building a multilingual chatbot using the Multi-Agent Orchestrator framework. Learn to effortlessly chain AI agents for instant language processing and booking across multiple languages. Transform complex, multi-step processes into a polyglot flight reservation system.

Published Aug 29, 2024
Last Modified Aug 30, 2024
Imagine a bustling international airport. Travelers from every corner of the world are rushing to catch their flights, a symphony of languages filling the air. Now, picture a single AI chatbot capable of assisting each of these travelers in their native tongue, booking flights with incredible efficiency. Sounds like something out of a spy movie, doesn't it? Well, get ready, because I'm about to show you how to make this a reality!
In this article, I'll guide you through creating a multilingual AI chatbot for booking flights. Here's the exciting part: we'll be using a framework I helped develop called the Multi-Agent Orchestrator. This framework is our secret weapon, making our mission much easier, and I'm thrilled to share it with you.
The Multi-Agent Orchestrator framework is like M from James Bond movies. But instead of managing just one 007, it coordinates a whole team of AI secret agents. Each AI agent has its own special skills - like language translation or flight booking. These AI agents work together on their mission: to help travelers from around the world.
Here's what I'll cover in this article:
  1. What the Multi-Agent Orchestrator framework is and how it works
  2. How to set up our chatbot that speaks many languages and books flights
  3. How to use Amazon Lex to understand what people are saying
  4. How to make our chatbot translate languages
  5. How to put everything together to make a smooth, multi-language experience
By the end of this article, you'll know how to use AI agents together to do complex tasks. This skill is useful for more than just booking flights. You could use it for online shopping, helping customers, or any job where talking to people in different languages is important.
So, open your computer and get ready to code. I'm excited to show you how to make a chatbot that can talk to people from all around the world!
Here is the cool part: our flight reservation bot is just one example of what's possible. The Multi-Agent Orchestrator framework includes a flexible feature that allows each agent to perform a series of actions in sequence. This capability opens up endless possibilities for building complex, multi-step workflows. In this article, we'll explain how this works and show you how to apply it to create a seamless experience, such as translating user input, processing it with Amazon Lex, and translating the response back—all in one fluid interaction.
While I'm focused on flight reservations here, you could easily adapt this idea to create a network of diverse AI agents to fit to your specific needs. The key is that the Multi-Agent Orchestrator framework remains constant, providing a solid foundation for various applications.
You might deploy agents for processing orders, answering customer inquiries, or providing technical support - all while maintaining seamless communication across multiple languages. The specific roles and capabilities of each agent can be customized to your requirements, whether you're in e-commerce, customer service, healthcare, or any field where clear, multilingual communication is crucial.
The framework allows you to mix and match different types of AI agents - perhaps combining a language model for natural conversation, a specialized agent for data processing, and another for decision-making. This versatility opens up a world of possibilities, enabling you to create sophisticated, multi-functional systems that can handle complex tasks across language barriers.

Let's get started

Before we dive in, make sure you have the following:
  • An AWS account with access to Amazon Lex, Amazon Bedrock, and Amazon Comprehend
  • Python 3.7 or later installed on your local machine
  • Basic knowledge of Python and AWS services
  • The AWS CLI installed and configured with your credentials

Step 1: Set up an Amazon Lex Bot

To implement this example, you'll need an Amazon Lex bot, as the framework itself doesn't create any resources. Follow these steps to quickly set up a Lex bot:
  1. Sign in to the AWS Management Console and navigate to the Amazon Lex service.
  2. Click on "Create bot" and select the template "Airline Services" from the list of templates.
  3. Give your bot a name (e.g., "MultilingualAirlineBot")
  4. Choose your preferred language (e.g., English)
  5. Under "IAM permissions", select "Create a role with basic Amazon Lex permissions"
  6. Click "Next"
  7. Review the sample intents and slots, then click "Create bot"
  8. Once the bot is created, build and test it in the Lex console to ensure it's working correctly
  9. Note down the Bot ID, Bot Alias ID, and Locale ID from the bot settings
Important: Sample data to be used when providing answers in the example below is available here.

Step 2: Install required libraries

Open your terminal and install the necessary Python libraries:

Step 3: Import required classes

Create a new Python file named multilingual_chatbot.py and add the following imports:

Step 4: Configure the Orchestrator

Add the following configuration to your multilingual_chatbot.py:
Replace YOUR_BOT_ID and YOUR_BOT_ALIAS_ID with the actual values from your Lex bot.

Step 5: Implement a language detection function

Add a helper function to detect the language of user input:
In this example, we identify the user's language by analyzing their initial input and then use this language for the remainder of the conversation. You might choose to follow this approach, or you may already have a method to determine the user's language, in which case this step would be unnecessary.

Step 6: Create the agents

Implement the main function that sets up the agents and handles the conversation:
The code creates the run_multilingual_chatbot() function, which sets up two agents: a technical agent and a multilingual agent. For the purposes of this article, while we include a technical agent but our focus is on the multilingual agent. This multilingual agent employs the ChainAgent to effectively orchestrate three sub-agents:
  1. Translator to English – This agent converts the user's input into English, ensuring the input is ready for processing.
  2. Lex Bot – Serves as the core agent that processes the user's request using an Amazon Lex bot.
  3. Translator from English – This agent translates the bot’s response back into the user's original language.
These agents are seamlessly linked within the ChainAgent, enabling our chatbot to handle multilingual interactions efficiently by automatically translating input and output while interacting with the English-configured Lex Bot.
The framework allows you to orchestrate multiple top-level agents for user input and select the best one, while also enabling each agent to be composed of a chain of sub-agents, as demonstrated in our multilingual example.
This diagram illustrates how the agents are assembled within the framework:
Multi lingual diagram flow
Multi lingual diagram flow

Step 7: Execute the script

Save your multilingual_chatbot.py file and run it:
Now, let's test our multilingual chatbot with examples in different languages. We'll start with French, then exit the script and restart it to demonstrate interactions in Spanish and Portuguese.
Notice the lines beginning with "You:", which represent user input, and the lines starting with "> Response:" which show the chatbot's replies.

French

Now, let's exit the script and start a new conversation in Spanish.


Spanish

Let's exit once more and restart the script, this time interacting in Portuguese.

Portuguese

An alternative approach: direct Agent usage

While the Multi-Agent Orchestrator is powerful for managing multiple agents and complex workflows, there are scenarios where you might not need its full capabilities. If you have a specific sequence of tasks and don't require agent selection or complex orchestration, you can call an agent directly.
In the multilingual chatbot example, we use a chain of three tasks:
  1. Translate to English
  2. Process with Lex bot
  3. Translate back to the original language.
We can accomplish this by directly using the ChainAgent.
Direct Agent call
Direct Agent call
In this direct approach, the user input flows through a predefined sequence of agents within a ChainAgent, bypassing the need for an orchestrator.
Let's see how to implement this version for the chatbot example.
Here, we create the ChainAgent as before, but instead of adding it to an orchestrator, we call its process_request method directly.

Conclusion

In this article, I've demonstrated how to build a multilingual chatbot that leverages the Multi-Agent Orchestrator framework, allowing users to interact with an airline bot in their preferred language. However, this example only scratches the surface of what's possible with this framework.
One of the key strengths of the Multi-Agent Orchestrator is its flexibility in agent selection and chaining. The framework allows you to have multiple agents available to handle user input, automatically selecting the best-fit agent based on the context or query. You can also chain multiple agents to process a single user input, unlocking multiple ways to cover diverse use cases.
While I've focused on an airline services bot, you can apply these principles to any Lex bot template (or any other agent) or custom bot you create.
It's worth noting that while this example uses Python, the Multi-Agent Orchestrator framework is also available for TypeScript, allowing you to implement similar functionality in a JavaScript environment. This cross-language support provides flexibility in choosing your development ecosystem.
In the above example, we used the BedrockTranslatorAgent with the Claude Haiku model for translation. However, the framework offers great flexibility in terms of model selection. Depending on your specific requirements, you could easily swap out the translation model for a smaller and faster one, or even integrate a locally running model. This adaptability makes it straightforward to optimize your chatbot for different performance requirements or deployment scenarios.
I encourage you to explore further and adapt this example to your specific needs.

Explore more

Ready to dive deeper? Check out the resources below to get the most out of the Multi Agent Orchestrator:
  • 📚 Documentation: Get comprehensive guidance and details on how to use the toolkit effectively.
  • 🛠️ GitHub Repository: Access the source code, contribute, or browse issues and updates.
  • 📦 NPM Repository: Find installation details and version information for the toolkit.
  • 📦 PyPi Repository: Find installation details and version information for the toolkit.
     
If you find this framework helpful, please consider giving us a star on GitHub. Also we would love to hear your thoughts, so feel free to leave a comment below. And if you have ideas for new features or improvements, don't hesitate to create a feature request on our GitHub repository.
 

Comments