Skip to content

Instantly share code, notes, and snippets.

@jasonforte
Last active September 1, 2025 12:02
Show Gist options
  • Select an option

  • Save jasonforte/4baae39af1aadd70dd13737825bbc960 to your computer and use it in GitHub Desktop.

Select an option

Save jasonforte/4baae39af1aadd70dd13737825bbc960 to your computer and use it in GitHub Desktop.
Simple Agent Example - Amazon Bedrock Agents
AWS_REGION_NAME = 'eu-west-1'
BEDROCK_AGENT_ALIAS_ID = ''
BEDROCK_AGENT_ID = ''

Simple Bedrock Agent Example - Sorting Emails

This is example code for a youtube video by MakeOps on how to deploy an agent using Amazon Bedrock Agents.

Resources

  • .env file with configurations
  • main.py with the code
  • email-samples.txt with 4 examples used in the video
  • prompt.txt - the entire prompt if following along

Resources

# ./samples/accounts.txt
Hi
I'm looking to start placing orders with you. Do you have a price list for shipments between London and Manchester?
Kind Regards
Thembi
# ./sample/logistics.txt
Hi Team
I'm reaching out to understand the status of my shipment #1234564. What is the expected delivery date?
Kind Regards
Trevor
Logisics Manager
BigCompany Ltd.
# ./sample/management.txt
Hi
We're looking to get in contact with your executive team. We're a team of angel investors looking to potentially invest in your startup.
Let me know who I can reach out to.
Kind Regards
Ronald
LMN Investment Partners
# ./sample/spam.txt
Hi
We're offering you a free getaway if you join our newsletter within the next week. What that means?
If you join our newsletter before 8 October, then you'll stand a chance to win one of our getaway vouchers.
Don't loose out. Join today!
Regards
Sunrise Holidays
import os
import boto3
import uuid
from dotenv import load_dotenv
load_dotenv()
aws_region_name = os.environ.get('AWS_REGION_NAME')
bedrock_agent_alias_id = os.environ.get('BEDROCK_AGENT_ALIAS_ID')
bedrock_agent_id = os.environ.get('BEDROCK_AGENT_ID')
bedrock_agent = boto3.client('bedrock-agent-runtime', region_name=aws_region_name)
SAMPLE_MESSAGES = {
'logistics': './samples/logistics.txt',
'spam': './samples/spam.txt',
'accounts': './samples/accounts.txt',
'management': './samples/management.txt'
}
def load_message(message_type):
assert message_type in SAMPLE_MESSAGES, f'invalid message type: must be one of {SAMPLE_MESSAGES.keys()}'
with open(SAMPLE_MESSAGES[message_type], 'r') as fp:
return fp.read()
def invoke_agent(prompt, session_id=None):
if not session_id:
session_id = str(uuid.uuid4())
response = bedrock_agent.invoke_agent(
agentId=bedrock_agent_id,
agentAliasId=bedrock_agent_alias_id,
inputText=prompt,
sessionId=session_id,
)
return {
'sessionId': response['sessionId'],
'completion': response['completion']
}
def print_response(response):
assert 'chunk' in response, 'no chunk in response'
output = response['chunk']['bytes'].decode()
print(f'## Response:\n{output}\n')
return output
def process_inbound_email(message):
response = invoke_agent(message)
outputs = []
for c in response['completion']:
print_response(c)
outputs.append(c)
return response['sessionId'], outputs
You are a helpful email processing assistant. Your job is to read, understand and categorize different incoming emails for our company. The outcome is to hand off the email to the most appropriate team for handling the email.
Here are some details about our company:
<company>
We are ABC Shipping, we handle logistics for companies looking move goods in the manufacturing sector. We are a small 10 - 15 person company but we highly value speedy, professional and direct messaging with our customers and partners.
</company>
Here are some of the details of the teams that you can route messages to:
<teams>
<team><name>Accounts</name><details>Handle new & existing customer requests, accounts, billing etc.</details></team>
<team><name>Logistics</name><details>Handle active orders and shipments, details of inbound and outbound times etc.</details></team>
<team><name>Marketing</name><details>Our marketing team host in-person events that require coordination</details></team>
<team><name>Leadership</name><details>Management team including CEO, CFO and directors.</details></team>
</teams>
## Your Task
For each new message you receive do the following:
- Read the email very carefully to understand the details of the message.
- Consider each <team> and decide on which would be the best suited team to handle the message.
- If you don't think there is a good fit for any <team>, or you think it's spam respond with NO_MATCH, this will be handled separately.
- Draft a simple acknowledgement email to respond to the email, if it's NO_MATCH then don't respond.
- In the acknowledgement email ensure to abide by our principals.
## Response Format
<outputTeam><team.name> OR NO_MATCH</outputTeam>
<outputResponse>Your email response</outputResponse>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment