Foreigners and expats living outside their home country are faced with a large number of emails in multiple languages on a daily basis. They often encounter language barriers when it comes to setting reminders for events such as business meetings and client meetings. To solve this problem, this post shows you how to apply AWS services such as amazon Bedrock, AWS Step Functions, and amazon Simple Email Service (amazon SES) to create a fully automated multilingual calendar artificial intelligence (ai) assistant. It understands incoming messages, translates them into the preferred language, and automatically sets calendar reminders.
amazon Bedrock is a fully managed service that makes base models (FMs) from leading ai startups and amazon available via an API, so you can choose from a wide range of FMs to find the model that best fits your use case. With amazon Bedrock, you can get started quickly, privately customize FMs with your own data, and easily integrate and deploy them into your applications using AWS tools without having to manage any infrastructure.
AWS Step Functions is a visual workflow service that helps developers build distributed applications, automate processes, orchestrate microservices, and create data and machine learning (ML) pipelines. It allows you to orchestrate multiple steps in the pipeline. Steps can be AWS Lambda functions that generate prompts, analyze the output of core models, or send email reminders using amazon SES. Step Functions can interact with over 220 AWS services, including streamlined integrations with amazon Bedrock. Step Functions pipelines can contain loops, map jobs, parallel jobs, conditions, and human interaction, which can be useful for human-ai interaction scenarios.
This post shows you how to quickly combine the flexibility and power of amazon Bedrock FM and Step Functions to build a generative ai application in just a few steps. You can reuse the same design pattern to deploy more generative ai applications with little effort. Both amazon Bedrock and Step Functions are serverless, so you don’t need to think about managing and scaling infrastructure.
Source code and implementation instructions are available at amazon-bedrock-and-aws-step-functions” target=”_blank” rel=”noopener”>Github repository.
Solution Overview
As shown in Figure 1, the workflow starts at amazon API Gateway and then goes through different steps in the Step Functions state machine. Pay attention to how the original message flows through the pipeline and how it changes. First, the message is appended to the message. Then, the base model transforms it into structured JSON. Finally, this structured JSON is used to perform actions.
- The original message (amazon-bedrock-and-aws-step-functions/blob/main/doc/sample-inputs/norsk1.json” target=”_blank” rel=”noopener”>Example in Norwegian) is sent to a Step Functions state machine via API Gateway.
- TO amazon-bedrock-and-aws-step-functions/blob/main/src/lambda/prompt_generator/prompt_generator.py” target=”_blank” rel=”noopener”>Lambda function generates a message that includes system instructions, the original message, and other necessary information such as the current date and time. (Here is the amazon-bedrock-and-aws-step-functions/blob/main/src/lambda/prompt_generator/generated_prompt_example.json” target=”_blank” rel=”noopener”>notice generated from the example message).
- Sometimes the original message may not specify the exact date, but instead say something like “please RSVP by this Friday” which implies the date based on the current context. Therefore, the function inserts the current date into the message to help the model interpret the correct date. this Friday.
- Invoke Bedrock FM to perform the following tasks as described in the message, and pass the output to the next step of the parser:
- Translate and summarize the original message in English.
- Extract event information such as subject, location, and time from the original message.
- Generate a list of action plans for events. For now, the instruction only asks the FM to generate an action plan to send calendar reminder emails to attend an event.
- amazon-bedrock-and-aws-step-functions/blob/main/src/lambda/llm_output_parser/llm_output_parser.py” target=”_blank” rel=”noopener”>Parse the FM output to ensure you have a valid schematic. (Here is the amazon-bedrock-and-aws-step-functions/blob/main/src/lambda/llm_output_parser/parsed_result_example.json” target=”_blank” rel=”noopener”>result analyzed from the sample message.)
- Claude Anthropic on amazon Bedrock can control output format and generate JSON, but it might still produce the result like “this is the json {…}”. To improve robustness, we implemented an output parser to ensure schema adherence, thus strengthening this pipeline.
- Go through the list of action plans and perform step 6 for each item. Each action item follows the same outline:
- Choose the right tool for the job:
- If he
tool_name
It does not mattercreate-calendar-reminder
then run subflow A to send a calendar reminder email using amazon-bedrock-and-aws-step-functions/blob/main/src/lambda/send_calendar_reminder/send_calendar_reminder.py” target=”_blank” rel=”noopener”>Lambda Function. - To support other possible jobs in the future, you can expand the message to create a different action plan (assign different values to
tool_name
) and perform the appropriate action described in subflow B.
- If he
- Made.
Prerequisites
To run this solution, you must have the following prerequisites:
Implementation and testing
Using the AWS Cloud Development Kit (AWS CDK), you can deploy the full stack with a single command line by following the deployment instructions in the amazon-bedrock-and-aws-step-functions” target=”_blank” rel=”noopener”>Github repositoryThe deployment will generate the API Gateway endpoint URL and an API key.
Use a tool like curl to send messages in different languages to API Gateway for testing:
Within 1-2 minutes, email invitations should be sent to the recipient from your sender email address, as shown in Figure 2.
Clean
To avoid incurring future charges, remove the resources by running the following command in the source code root path:
$ cdk destroy
Future expansion of the solution
In the current implementation, the solution only sends calendar reminder emails; the message only tells the base model to generate action items where tool_name
It does not matter create-calendar-reminder
You can extend the solution to support more actions. For example, automatically send an email to the event originator and politely decline if the event is in July (summer vacation for many):
- Modify the notice instruction: If the event date is in July, create an action item and set the value of
tool_name
tosend-decline-mail
. - Similar to subflow A, create a new subflow C where
tool_name
matchessend-decline-mail
:- Invoke amazon Bedrock FM to generate email content explaining that you cannot attend the event because it is in July (summer break).
- Invoke a Lambda function to send the rejection email with the generated content.
Additionally, you can experiment with different foundation models on amazon Bedrock, such as Meta Llma 3 or Mistral ai, to achieve better performance or lower cost. You can also explore Agents for amazon Bedrock, which can orchestrate and execute multi-step tasks.
Conclusion
In this post, we explore a solution pattern for using generative ai within a workflow. With the flexibility and capabilities offered by amazon Bedrock FMs and AWS Step Functions, you can create a powerful generative ai assistant in just a few steps. This assistant can streamline processes, improve productivity, and handle multiple tasks efficiently. You can easily modify or upgrade its capacity without being burdened by the operational overhead of managed services.
You can find the source code of the solution at amazon-bedrock-and-aws-step-functions” target=”_blank” rel=”noopener”>Github repository and implement your own multilingual calendar assistant by following the implementation instructions.
Please see the following resources for more information:
About the Author
Fenglu is a Senior Solutions Architect at AWS with 20 years of professional experience. He is passionate about helping organizations design scalable, flexible, and resilient architectures that address their business challenges. His current focus is on leveraging artificial intelligence (ai) and Internet of Things (IoT) technologies to improve the intelligence and efficiency of our physical environment.