AWS Bedrock
Introduction
AWS Bedrock is Amazon’s fully managed foundation model (FM) service that allows developers to build and scale generative AI applications without provisioning or maintaining infrastructure. Bedrock provides access to a wide selection of foundation models from providers such as Anthropic, Meta, Cohere, and Amazon, through a single API.
With the new support in the Crypto.com AI Agent SDK, developers can connect the agent to Bedrock and decide exactly how it should work.
When setting it up with Crypto.com AI Agent SDK (v1.3.3 and above), developers can choose:
AI model: pick the specific model that works the best for you (for example, Anthropic Claude).
Knowledge base: connect to a Bedrock knowledge base so answers can draw from your own data or project documentation
Guardrail: set rules and safety checks to ensure responses follow compliance and usage requirements.
This integration allows developers to create scalable, secure AI agents that combine Crypto.com’s AI Agent SDK with AWS’s enterprise-grade AI infrastructure, which gives developers flexibility to decide which model powers the agent, what information it uses, and what constraints it follows.
Prerequisites: AWS Bedrock & Access Setup
1. Create a Bedrock Account & Pick a Model
Sign in to AWS Bedrock Console.
Browse AI models and choose one to use (e.g.,
anthropic.claude-3-haiku
). You can find the model details, including region availability, under theInfer
section.Note down the model ID and the regions where it’s available.
2. Access Bedrock
You can access Bedrock in two ways:
a. Access Key (Local Dev / Scripts) Use an AWS access key ID and secret access key:
Create an IAM user with BedrockFullAccess.
Generate an access key (ID + secret).
Store it securely in environment variables.
Learn more about creating AWS access keys.
b. IAM Role (Production) Assign an IAM role with Bedrock permissions to your EC2, ECS, EKS service. Example using EC2:
Launch an EC2 instance.
Attach an IAM role with BedrockFullAccess to the instance.
Connect to the EC2 instance, install Python and
cryptocom-agent-client
, create your dApp there.Your dApp can now call Bedrock without manually providing credentials.
3. (Optional) Create a Knowledge Base
Use AWS Knowledge Base if you want the agent to pull answers from your own data:
Prepare your data. If using S3, ensure the bucket is in the same region as your Bedrock instance.
Create an IAM user with the necessary permissions, such as Bedrock access, S3 vector permissions (if using S3 Vector), and S3 bucket access (if your data is stored in S3).
Create the Knowledge Base with your data source under the IAM user.
Note down the Knowledge Base ID, you’ll use it when initializing your Crypto.com AI Agent.
Learn more about AWS Knowledge Bases.
4. (Optional) Create a Guardrail
Use a Guardrail ID and version to enforce content rules and safety checks:
Prepare an IAM role with permissions like
bedrock:CreateGuardrail
.In the Bedrock console, create a guardrail using that IAM role.
A single guardrail can have multiple versions.
Copy the Guardrail ID and version, you’ll use them to apply the guardrail to your models or agents.
Learn more about AWS Guardrail.
Get Started
Here is the sample code using AWS Bedrock as the provider, with the AWS access key or an IAM role.
from crypto_com_agent_client import Agent, SQLitePlugin
agent = Agent.init(
llm_config={
"provider": "Bedrock",
"model": "your-ai-model-name", # Example: "anthropic.claude-3-sonnet-20240229-v1:0"
"provider-api-key": f"{your_aws_access_key_id}:{your_aws_secret_access_key}:{your_aws_region}",
"location-id": aws_region, # AWS region for Bedrock, example: "us-east-1"
"knowledge-base-id": your_knowledge_base_id, # AWS Bedrock Knowledge Base ID
"guardrail-id": your_guardrail_id, # Optional AWS Bedrock Guardrail ID
"guardrail-version": your_guardrail_version, # Optional AWS Bedrock Guardrail version
"model-kwargs": your_model_kwargs, # Optional model-specific parameters, example: {"temperature": 0.7, "max_tokens": 1024}
"debug-logging": True, # Enable to see knowledge base queries
"temperature": 0.7, # Will be overridden by model_kwargs if specified
},
blockchain_config={
"api-key": os.getenv("DEVELOPER_SDK_API_KEY"),
},
plugins={
"storage": SQLitePlugin(db_path="bedrock_agent.db"),
"personality": {
"tone": "professional",
"language": "English",
"verbosity": "medium",
},
"instructions": "You are an AI assistant with access to company knowledge base. Provide accurate, helpful responses based on available information."
},
)
response = agent.interact("What are the latest blockchain trends?")
print(response)
Note:
It is recommended to store sensitive data in environment variables.
Avoid hardcoding or exposing any keys in both development and production environments.
Last updated
Was this helpful?