Towards AWS

Where Cloud Experts, Heroes, Builders, and Developers share their stories, experiences, and…

Follow publication

Multi-Agent Collaboration: Serverless AI Agents using AWS CDK, Bedrock, and Python

--

In our previous 2-part article, we deployed the first version of the application that connected a Bedrock Agent with a data source for an imaginary Steakhouse.

We saw how users could seamlessly interact with it to get information about menus and deals and create and delete reservations.

This article will take it further by adding more agents to the mix. These agents are designed to perform specific tasks for Steakhouse and would be managed by a Supervisor agent. We will see multi-agent collaboration in AWS and how to build a robust system that can handle multiple use cases.

Let’s get right into it!

Prerequisites

  • AWS account
  • AWS CLI setup locally
  • AWS CDK set up.
  • Python3
  • Model access is enabled for the required models. Specifically, Amazon Bedrock has access to the Amazon Titan Embeddings V2 model and Anthropic Claude 3 Haiku.
  • Previous article

What would we cover

  • Current architecture
  • We review the new Steakhouse architecture.
  • We walk through the Python and AWS CDK code.
  • We perform some tests to see it in action.

Case Study: Steakhouse

Our imaginary company Steakhouse has seen a lot of success from deploying the Bedrock agent we discussed in our last article, this convinced management to invest more into agents for various use cases.

They have also expanded and are no longer solely focused on being a steakhouse, but now have short lets they manage for customers, as well as an HR department for internal staff. They also added a ticket support team and would love to have an agent help in this department.

So Steakhouse now has 4 sub-agents: A Reservation Agent(would keep managing Steakhouse meal orders for customers), an HR Agent(would manage all staff HR issues), a Shortlet(would manage the new short let for customers), and ticket support(would manage ticket support for customers).

Then a Supervisor Agent made possible by AWS Bedrock multi-agent collaboration, would be directly connected to the client to receive all requests and coordinate with the sub-agents to give back an optimal response.

Current Steakhouse Architecture

Current Architecture

New Steakhouse Architecture

New Architecture with Supervisor

We can see that:

  1. The user visits the Streamlit Web app to interact with the Agent by visiting the URL exposed by the load balancer.
  2. The Streamlit Web app interacts with the Supervisor agent.
  3. The supervisor agent then decides which agent(s) to forward the request to, aggregates the response, and outputs the final relevant response to the user.

Project Overview

Project Overview

The folder structure is designed as follows:

  1. The agents_python folder contains the 2 stacks for the app, the Agent stack, and the Streamlit stack.
  2. The streamlit folder contains the files for setting up the streamlit app via the app.py file and interacting with the bedrock agent via the agent.py helper file.
  3. The dataset contains the files that would be added to the knowledge base and used by each agent.
  4. The lambdas/actiongroup includes the action group lambda functions of the 4 sub-agents.

We will review some parts of the newly added code.

Creating the Supervisor Agent

  supervisor_agent_role = iam.Role(
scope=self,
id='SupervisorAgentRole',
role_name='AmazonBedrockExecutionRoleForSupervisorAgent-Steakhouse',
assumed_by=iam.ServicePrincipal('bedrock.amazonaws.com'))

supervisor_agent_role.add_to_policy(iam.PolicyStatement(
sid='SupervisorInvokeBedrockLambda',
effect=iam.Effect.ALLOW,
resources=[
agent_model_arn],
actions=['bedrock:InvokeModel', 'lambda:InvokeFunction']))

supervisor_agent_role.add_to_policy(iam.PolicyStatement(
sid='SupervisorAgentInvoke',
effect=iam.Effect.ALLOW,
resources=["*"],
actions=['bedrock:*']))

# Create supervisor agent
cfn_supervisor_agent = bedrock.CfnAgent(self, "SupervisorAgent",
agent_name=supervisor_agent_name,
agent_resource_role_arn=supervisor_agent_role.role_arn,
auto_prepare=True,
description=supervisor_agent_description,
foundation_model=agent_model_id,
instruction=supervisor_agent_instruction,
idle_session_ttl_in_seconds=1800,
)
cfn_supervisor_agent_alias = bedrock.CfnAgentAlias(
self, "SupervisorAgentAlias",
agent_alias_name=supervisor_agent_alias_name,
agent_id=cfn_supervisor_agent.attr_agent_id)

self.bedrock_supervisor_agent_id = cfn_supervisor_agent.attr_agent_id
self.bedrock_supervisor_agent_alias_id = cfn_supervisor_agent_alias.attr_agent_alias_id

From the above, we set up the supervisor agent with a role and required permissions.

We also create an Alias for the supervisor agent and set it up for production use. Lastly, we export the bedrock_supervisor_agent_id and bedrock_supervisor_agent_alias_id to be used by the Streamlit Stack.

Updating app.py

app = cdk.App()
agent_stack = AgentStack(app, "AgentStack")
streamlit_stack = StreamlitStack(app, "StreamlitStack",
bedrock_agent_id=agent_stack.bedrock_supervisor_agent_id,
bedrock_agent_alias_id=agent_stack.bedrock_supervisor_agent_alias_id
)

streamlit_stack.add_dependency(agent_stack)

We update the app.py to use the supervisor agent and agent alias in the streamlit stack. This way the app would interact with the supervisor agent rather than a specific sub-agent.

A point to note: We created 4 sub-agents and assigned each an action group, with corresponding lambda function and connected them to a single Knowledge Base. However, due to the code snippet size we won't be seeing them in this article, but you can always see the full project on the repo here.

Time to deploy 🔥 🔥

To deploy the app:

cdk deploy --all

This would deploy the 2 stacks, first the Agent Python stack and then the Streamlit stack.

Enabling Multi-agent Collaboration

Before we test the app, we need to set up the multi-agent collaboration manually using the AWS Console.

This is because AWS CDK doesn't currently support this feature, we would carry it out via the console.

Click on the bedrock agents in the console, then select the Supervisor Agent and follow these steps:

Click the Edit in Agent Builder button:

Next, scroll down and click the Edit button in the Multi-agent collaboration feature section:

Next, enable the Multi-agent collaboration feature.

Scroll down and add the 4 sub-agent collaborators

  1. HR Agent Collaborator:
HR Agent Collaborator

2. Reservation Agent Collaborator:

Reservation Agent Collaborator

3. Shortlet Agent Collaborator:

Shortlet Agent Collaborator:

4. Ticket Agent Collaborator:

Ticket Agent Collaborator

Next click the “Save and exit” button at the top. This would save the changes and take us to the agent details.

Now we have 4 collaborators:

Supervisor Agent Collaborators

Click the “Save and exit” button on this page, so it saves the changes.

Agent details

Next, proceed to prepare the agent so the changes we made would take effect on the supervisor agent.

Click on the “Prepare” button

Prepare agent

Next, click on the alias and edit so we can update it to use the latest changes:

Supervisor agent alias

In the Edit alias modal, choose “Create a new version and associate it to this alias”. Then click the save button.

Edit alias

This would create a new version and update the alias to point to this new version.

Now the changes made are in the supervisor alias that the streamlit app is connected to.

Testing the app

We would test the app via the Streamlit app and the AWS console. The reason for this is the AWS console allows us to see traces, this way we can see how the supervisor agent interacts with the sub-agents when answering user queries, something we won't be able to see directly when we test using the streamlit app.

Testing the app via AWS Console

Query 1

Customer: Whats the best steak I can get as well as best dessert

Agent: For the best steak option, I would recommend the Wagyu Ribeye. At $60 for a 12oz cut, it is a premium and flavorful steak with unmatched marbling and richness. The Tomahawk Steak is also an excellent choice for sharing.

For dessert, the Chocolate Lava Cake served with vanilla ice cream sounds like an indulgent and delicious option. The Tiramisu is another great choice for those who prefer a coffee-flavored dessert.

You may also want to consider taking advantage of the weekly steak specials like the Filet Mignon Feast on Thursdays or the discounts on T-Bones on Tuesdays.

Query 1
Trace timeline
Orchestration and Knowledge Base

Note: As can be seen, the Supervisor agent calls only the Reservation sub-agents which uses the Knowledge Base for context.

Query 2

Customer: Steakhouse Menu for Tuesday and available short lets

Agent: According to the information gathered: The Steakhouse menu for Tuesday features the “T-Bone Tuesday” special, where T-Bone steaks are $5 off and served with any two sides. The available short lets at the Steakhouse this week include: — Standard Room: $50 per night — Deluxe Room: $80 per night — Suite: $120 per night — Penthouse: $250 per night All short let rooms come with amenities such as free WiFi, air conditioning, 24/7 security, housekeeping services, and access to a shared lounge. Additional amenities like kitchenettes and private pools are available in select room types.

Query 2
Multi-agent trace timeline

Note: As can be seen, the Supervisor agent calls both sub-agents which each use the Knowledge Base for context

Query 3

Customer: What is the sick leave policy for me as a staff, also could you create a ticket for John with the following details: incident date: 22/03/2022 and reason: Shortlet room was untidy

Agent: Based on the information provided:

1. The Steakhouse sick leave policy states that all employees, including part-time staff, are eligible for sick leave. Employees can use sick leave for personal illness, medical appointments, or caring for an immediate family member. Employees must notify their manager as soon as possible if they need to take sick leave, and for absences longer than three consecutive days, a medical certificate is required.

2. I have successfully created a new ticket for John with the following details: — Incident date: 22/03/2022 — Reason: Shortlet room was untidy The new ticket has been assigned the booking ID ‘59175490’.

Query 3
Multi-agent trace timeline
Ticket created in DynamoDB

Note: As can be seen, the Supervisor agent calls both sub-agents. It uses the Hr sub-agent Knowledge Base for context and uses the Ticket sub-agent Action group to make an api call that created the ticket in DynamoDB.

Query 4

Customer: Create shortlet reservations for John for 4 days on 28/02/2025 for 2 guests, for shortlet type use standard. Then recommend 1 good dessert I could take.

Agent: Based on the information provided, I have completed the following actions:

1. Created a new shortlet booking for John with the following details: — Booking ID: 679b0fce — Date: 28/02/2025 — Shortlet Type: standard — Number of Guests: 2 — Number of Days: 4

2. Recommended the Tiramisu or the Crème Brûlée as the best dessert options to pair with the steakhouse shortlet booking: — Tiramisu is a “perfect” pairing for Prosecco wine, which is recommended for “lighter desserts”. This would complement the indulgence of a shortlet stay. — Crème Brûlée is an elegant, classic dessert option that would pair well with a steakhouse meal. Its rich, creamy texture would make for a sophisticated end to a shortlet experience. So in summary, I would recommend either the Tiramisu or the Crème Brûlée as the best dessert option to pair with the steakhouse shortlet booking.

Query 4
Shortlet created in DynamoDB

Note: As can be seen, the Supervisor agent calls the shortlet and reservation sub-agents. It uses the Shortlet sub-agent Action group to make an api call that created the shortlet reservation in DynamoDB and the Reservation sub-agent Knowledge Base for context for Dessert.

Testing the app via Streamlit App

Query 5

Customer:

Create HR booking for sick leave for Janet from 03/04/2025 to 010/04/2025, the main reason is cough, detailed comment is severe cold and doctor recommended rest. Return Shortlet details for Shortlet id: 679b0fce

User Question

Agent:

Agent Response
HR time off item created in DynamoDB

My Observation

  1. I was faced with request per minute(RPM) rate throttling when I was actively testing the agent. This wasn’t a pleasant experience. I had to update my model to use Haiku 3, which gave me higher RPM, as I couldn't get the Bedrock team to increase my Claude Sonnet 3 RPM on time(I still have an open ticket for over a week now!). You may need to request an increase in service quota for Claude's quota, more info here.
  2. Also, the Supervisor Agent could act as a security agent where you could apply checks using guardrails.

Closing

This has been an interesting ride. This brings an end to an exciting use case of Steakhouse, where we got to build an AI Agent using Bedrock, and extended it to support multi-agent collaboration.

You can find the complete source code here.

Excited to see what you build!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Towards AWS

Where Cloud Experts, Heroes, Builders, and Developers share their stories, experiences, and solutions.

Written by Nwachukwu Chibuike

Full-stack developer, technical writer and lover of Jamstack. Passionate about lifelong learning.