Building an AWS Solution Architect Agent with Generative AI
Tips and guidance on building a Generative AI Agent.
- Role: How the agent should behave, explanation of the concept of tools.
- Instructions: Provides examples of tasks and their solutions
<<all_tools>>
, which is replaced at runtime with the tools specified by the user.1
2
3
4
5
6
7
You are an expert AWS Certified Solutions Architect. Your role is to help customers understand best practices on building on AWS. You will generate Python commands using available tools to help will customers solve their problem effectively.
To assist you, you have access to three tools. Each tool has a description that explains its functionality, the inputs it takes, and the outputs it provides.
First, you should explain which tool you'll use to perform the task and why. Then, you'll generate Python code. Python instructions should be simple assignment operations. You can print intermediate results if it's beneficial.
Tools:
<<all_tools>>
{}
. The variable response
is placed within these braces, meaning its value will be inserted into the string when it's printed.1
2
3
4
5
6
7
8
9
10
Task: "Help customers understand best practices on building on AWS by using relevant context from the AWS Well-Architected Framework."
I will use the AWS Well-Architected Framework Query Tool because it provides direct access to AWS Well-Architected Framework to extract information.
Answer:
"""py
response = well_architected_tool(query="How can I design secure VPCs?")
print(f"{response}.")
"""
Task: "<<prompt>>"
I will use the following
<<prompt>>
directive, a placeholder that instructs the model on how to respond to a new, user-supplied prompt, thereby demonstrating the flexibility and adaptability of our Agent.- AWS Well-Architected Framework Query Tool: This tool will allow your agent to interact directly with the AWS Well-Architected Framework, extracting valuable data to inform architectural decisions.
- Code Generation Tool: This tool will generate code from AWS CloudFormation scripts to Python code.
- Diagram Creation Tool: This tool will create AWS diagrams.
1
2
3
4
from transformers import Tool
class AWSWellArchTool (Tool):
pass
- name: This is the name of the tool.
- description: This will be used to populate the prompt of the agent.
- inputs and outputs: These aid the interpreter in making informed decisions regarding data types. They both consist of a list of possible values which could be text, image, or audio.
- 'text': This type would be used when the input or output is a string of words, like a question to the tool or an answer from it.
- 'image': This would be chosen if the input or output is a picture or diagram. For example, if the user wanted to analyze an architectural diagram or if the tool needed to output a diagram to illustrate its answer.
- 'audio': This type would be selected when the input or output is a sound or speech, which might be useful for voice-based interaction scenarios.
- A call method: This contains the inference code.
1
2
3
4
5
6
7
8
9
10
from transformers import Tool
class AWSWellArchTool(Tool):
name = "well_architected_tool"
description = "Use this tool for any AWS related question to help customers understand best practices on building on AWS. It will use the relevant context from the AWS Well-Architected Framework to answer the customer's query. The input is the customer's question. The tool returns an answer for the customer using the relevant context."
inputs = ["text"]
outputs = ["text"]
def __call__(self):
pass
1
2
3
query = "How can I design secure VPCs?"
well_arch_tool = AWSWellArchTool()
well_arch_tool(query)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import transformers
from transformers import Tool
from transformers.tools import HfAgent
# This is where you insert your custom prompt
sa_prompt = PROMPT
# Initialize the agent with the chosen LLM, your custom prompt, and the additional tools.
agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoderbase", run_prompt_template=sa_prompt,additional_tools=[code_gen_tool,well_arch_tool])
# List of default tools
default_tools = ['document_qa', 'image_captioner', 'image_qa', 'image_segmenter', 'transcriber', 'summarizer', 'text_classifier', 'text_qa', 'text_reader', 'translator', 'image_transformer', 'text_downloader', 'image_generator', 'video_generator',]
# Remove default tools from the agent's toolbox
for tool in default_tools:
try:
del agent.toolbox[tool]
except:
continue
1
agent.run("A diagram that shows an s3 bucket connected to a lambda function")
1
2
3
4
5
6
==Explanation from the agent==
I will use the following
==Code generated by the agent==
architecture_diagram = diagram_creation_tool(query=" A diagram that shows an s3 bucket connected to a lambda function")
==Result==
<class 'PIL.PngImagePlugin.PngImageFile'>
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.