Skip to content

Commit 3ffaaca

Browse files
feat: Add AWS Bedrock integration support
- Add comprehensive AWS Bedrock documentation with setup guide - Support for Anthropic Claude, Amazon Titan, Cohere, and Meta models via Bedrock - Include IAM permissions, regional availability, and cost optimization guidance - Add Python example demonstrating multi-model usage - Add YAML cookbook example for multi-agent workflows - Update navigation to include AWS Bedrock in models section - Maintain backward compatibility through existing LiteLLM integration Resolves #481 Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
1 parent bb91873 commit 3ffaaca

4 files changed

Lines changed: 370 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
framework: crewai
2+
topic: "Technology Research and Content Creation using AWS Bedrock"
3+
4+
roles:
5+
research_specialist:
6+
role: "Research Specialist"
7+
backstory: |
8+
You are an experienced technology researcher with deep expertise in analyzing
9+
emerging technologies and market trends. You excel at gathering comprehensive
10+
information from various sources and synthesizing it into actionable insights.
11+
goal: |
12+
Research and analyze the latest developments in artificial intelligence and
13+
cloud computing technologies, focusing on practical applications and market impact.
14+
verbose: true
15+
allow_delegation: false
16+
llm:
17+
model: "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0"
18+
temperature: 0.3
19+
tools:
20+
- "InternetSearchTool"
21+
tasks:
22+
technology_research:
23+
description: |
24+
Research the latest developments in AI and cloud computing. Focus on:
25+
1. Emerging AI model architectures and capabilities
26+
2. Cloud service innovations and their business impact
27+
3. Integration patterns between AI and cloud platforms
28+
4. Market adoption trends and future predictions
29+
expected_output: |
30+
A comprehensive research report with:
31+
- Executive summary of key findings
32+
- Detailed analysis of 3-5 major technology trends
33+
- Market impact assessment
34+
- Future outlook and recommendations
35+
36+
content_creator:
37+
role: "Technical Content Creator"
38+
backstory: |
39+
You are a skilled technical writer and content creator who specializes in
40+
translating complex technology concepts into engaging, accessible content
41+
for various audiences including developers, business leaders, and end users.
42+
goal: |
43+
Create compelling and informative content that explains complex technologies
44+
in clear, engaging ways while maintaining technical accuracy and relevance.
45+
verbose: true
46+
allow_delegation: false
47+
llm:
48+
model: "bedrock/amazon.titan-text-express-v1"
49+
temperature: 0.7
50+
tasks:
51+
content_creation:
52+
description: |
53+
Based on the research findings, create engaging technical content including:
54+
1. A blog post explaining the technology trends for a business audience
55+
2. Technical documentation for developers
56+
3. Executive summary for decision makers
57+
4. Social media content highlighting key insights
58+
expected_output: |
59+
A content package including:
60+
- 800-word blog post with clear structure and examples
61+
- Technical implementation guide (500 words)
62+
- Executive summary (200 words)
63+
- 3-5 social media posts with key takeaways
64+
65+
quality_reviewer:
66+
role: "Content Quality Reviewer"
67+
backstory: |
68+
You are a meticulous editor and quality assurance specialist with extensive
69+
experience in technical content review. You ensure accuracy, clarity, and
70+
consistency while maintaining the intended tone and message.
71+
goal: |
72+
Review and refine all content to ensure it meets high standards for accuracy,
73+
clarity, engagement, and professional presentation.
74+
verbose: true
75+
allow_delegation: false
76+
llm:
77+
model: "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0"
78+
temperature: 0.2
79+
tasks:
80+
content_review:
81+
description: |
82+
Review all created content for:
83+
1. Technical accuracy and factual correctness
84+
2. Clarity and readability for target audiences
85+
3. Consistency in tone and messaging
86+
4. Grammar, style, and formatting
87+
5. Overall engagement and impact
88+
expected_output: |
89+
A comprehensive review report with:
90+
- Content quality assessment
91+
- Specific recommendations for improvements
92+
- Final polished versions of all content
93+
- Quality score and approval status
94+
95+
dependencies:
96+
- research_specialist
97+
- content_creator
98+
- quality_reviewer

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"models/google",
157157
"models/openrouter",
158158
"models/anthropic",
159+
"models/aws",
159160
"models/cohere",
160161
"models/mistral",
161162
"models/deepseek",

docs/models/aws.mdx

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
title: "AWS Bedrock"
3+
description: "Instructions for integrating AWS Bedrock models with PraisonAI, including API setup and agent configuration"
4+
icon: "aws"
5+
---
6+
7+
# Add AWS Bedrock to PraisonAI
8+
9+
AWS Bedrock provides access to high-performing foundation models from leading AI companies like Anthropic, Cohere, Meta, Stability AI, and Amazon through a single API.
10+
11+
## Setup
12+
13+
### Prerequisites
14+
15+
Make sure you have AWS credentials configured:
16+
17+
```bash
18+
pip install boto3
19+
```
20+
21+
### Environment Variables
22+
23+
Set up your AWS credentials:
24+
25+
```bash
26+
export AWS_ACCESS_KEY_ID=your_access_key_id
27+
export AWS_SECRET_ACCESS_KEY=your_secret_access_key
28+
export AWS_REGION=us-east-1
29+
```
30+
31+
## Using AWS Bedrock Models
32+
33+
### Available Models
34+
35+
AWS Bedrock supports various model providers:
36+
37+
- **Anthropic Claude**: `bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0`
38+
- **Anthropic Claude Instant**: `bedrock/anthropic.claude-instant-v1`
39+
- **Amazon Titan**: `bedrock/amazon.titan-text-express-v1`
40+
- **Cohere Command**: `bedrock/cohere.command-text-v14`
41+
- **Meta Llama**: `bedrock/meta.llama2-70b-chat-v1`
42+
43+
### agents.yaml Configuration
44+
45+
```yaml
46+
framework: crewai
47+
topic: create movie script about cat in mars
48+
roles:
49+
researcher:
50+
backstory: Skilled in finding and organizing information, with a focus on research efficiency.
51+
goal: Gather information about Mars and cats
52+
role: Researcher
53+
llm:
54+
model: "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0"
55+
temperature: 0.7
56+
tasks:
57+
gather_research:
58+
description: Research and gather information about Mars, its environment, and cats, including their behavior and characteristics.
59+
expected_output: Document with research findings, including interesting facts and information.
60+
tools:
61+
- ''
62+
```
63+
64+
### Python Code Example
65+
66+
```python
67+
from praisonaiagents import Agent
68+
69+
# Using Anthropic Claude via Bedrock
70+
agent = Agent(
71+
instructions="You are a helpful assistant",
72+
llm={
73+
"model": "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
74+
"temperature": 0.7
75+
}
76+
)
77+
78+
# Using Amazon Titan via Bedrock
79+
titan_agent = Agent(
80+
instructions="You are a helpful assistant",
81+
llm={
82+
"model": "bedrock/amazon.titan-text-express-v1",
83+
"temperature": 0.7
84+
}
85+
)
86+
87+
response = agent.ask("What is artificial intelligence?")
88+
print(response)
89+
```
90+
91+
## IAM Permissions
92+
93+
Ensure your AWS IAM user/role has the necessary permissions to access Bedrock:
94+
95+
```json
96+
{
97+
"Version": "2012-10-17",
98+
"Statement": [
99+
{
100+
"Effect": "Allow",
101+
"Action": [
102+
"bedrock:InvokeModel",
103+
"bedrock:InvokeModelWithResponseStream"
104+
],
105+
"Resource": "*"
106+
}
107+
]
108+
}
109+
```
110+
111+
## Regional Availability
112+
113+
AWS Bedrock is available in the following regions:
114+
- `us-east-1` (N. Virginia)
115+
- `us-west-2` (Oregon)
116+
- `ap-southeast-1` (Singapore)
117+
- `ap-northeast-1` (Tokyo)
118+
- `eu-central-1` (Frankfurt)
119+
- `eu-west-3` (Paris)
120+
121+
Make sure to set your `AWS_REGION` environment variable to a supported region.
122+
123+
## Cost Optimization
124+
125+
AWS Bedrock charges are based on:
126+
- **Input tokens**: Text sent to the model
127+
- **Output tokens**: Text generated by the model
128+
129+
Consider using smaller models for development and testing to optimize costs.
130+
131+
## Error Handling
132+
133+
Common errors and solutions:
134+
135+
- **AccessDeniedException**: Check your IAM permissions
136+
- **ResourceNotFoundException**: Verify the model ID is correct and available in your region
137+
- **ThrottlingException**: Implement retry logic with exponential backoff
138+
- **ValidationException**: Check your input parameters and format
139+
140+
## Advanced Configuration
141+
142+
### Custom Endpoint
143+
144+
For specific regions or custom endpoints:
145+
146+
```python
147+
agent = Agent(
148+
instructions="You are a helpful assistant",
149+
llm={
150+
"model": "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
151+
"aws_region": "us-west-2",
152+
"temperature": 0.7
153+
}
154+
)
155+
```
156+
157+
### Streaming Responses
158+
159+
For real-time responses:
160+
161+
```python
162+
agent = Agent(
163+
instructions="You are a helpful assistant",
164+
llm={
165+
"model": "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
166+
"stream": True
167+
}
168+
)
169+
```
170+
171+
| PraisonAI Chat | PraisonAI Code | PraisonAI (Multi-Agents) |
172+
| --- | --- | --- |
173+
| [LiteLLM](https://litellm.vercel.app/docs/providers) | [LiteLLM](https://litellm.vercel.app/docs/providers) | [Models](../models.md) |

examples/models/aws-bedrock.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
"""
3+
AWS Bedrock Integration Example
4+
5+
This example demonstrates how to use various AWS Bedrock models with PraisonAI agents.
6+
7+
Requirements:
8+
pip install praisonaiagents boto3
9+
10+
Environment Variables:
11+
AWS_ACCESS_KEY_ID=your_access_key_id
12+
AWS_SECRET_ACCESS_KEY=your_secret_access_key
13+
AWS_REGION=us-east-1
14+
"""
15+
16+
import os
17+
from praisonaiagents import Agent
18+
19+
def main():
20+
"""
21+
Example of using AWS Bedrock models with PraisonAI agents
22+
"""
23+
24+
# Verify AWS credentials are set
25+
required_env_vars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_REGION']
26+
for var in required_env_vars:
27+
if not os.getenv(var):
28+
print(f"Error: Environment variable {var} is not set")
29+
print("Please set your AWS credentials:")
30+
print("export AWS_ACCESS_KEY_ID=your_access_key_id")
31+
print("export AWS_SECRET_ACCESS_KEY=your_secret_access_key")
32+
print("export AWS_REGION=us-east-1")
33+
return
34+
35+
print("AWS Bedrock Models Example")
36+
print("=" * 40)
37+
38+
# Example 1: Anthropic Claude via Bedrock
39+
print("\n1. Using Anthropic Claude 3.5 Sonnet via Bedrock")
40+
claude_agent = Agent(
41+
instructions="You are a helpful assistant that provides concise, accurate responses.",
42+
llm={
43+
"model": "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
44+
"temperature": 0.7
45+
}
46+
)
47+
48+
response = claude_agent.ask("What is artificial intelligence in 50 words?")
49+
print(f"Claude Response: {response}")
50+
51+
# Example 2: Amazon Titan via Bedrock
52+
print("\n2. Using Amazon Titan Text Express via Bedrock")
53+
titan_agent = Agent(
54+
instructions="You are a technical assistant focused on providing clear explanations.",
55+
llm={
56+
"model": "bedrock/amazon.titan-text-express-v1",
57+
"temperature": 0.5
58+
}
59+
)
60+
61+
response = titan_agent.ask("Explain machine learning in simple terms.")
62+
print(f"Titan Response: {response}")
63+
64+
# Example 3: Multi-agent conversation using different Bedrock models
65+
print("\n3. Multi-agent conversation with different Bedrock models")
66+
67+
# Research agent using Claude
68+
researcher = Agent(
69+
instructions="You are a research specialist who gathers and analyzes information.",
70+
llm={
71+
"model": "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
72+
"temperature": 0.3
73+
}
74+
)
75+
76+
# Writer agent using Titan
77+
writer = Agent(
78+
instructions="You are a creative writer who crafts engaging content.",
79+
llm={
80+
"model": "bedrock/amazon.titan-text-express-v1",
81+
"temperature": 0.8
82+
}
83+
)
84+
85+
# Research phase
86+
research_topic = "renewable energy trends"
87+
research_result = researcher.ask(f"Research the latest trends in {research_topic}. Provide 3 key insights.")
88+
print(f"Research Result: {research_result}")
89+
90+
# Writing phase
91+
writing_result = writer.ask(f"Write a compelling introduction paragraph about renewable energy based on this research: {research_result}")
92+
print(f"Writing Result: {writing_result}")
93+
94+
print("\n" + "=" * 40)
95+
print("AWS Bedrock integration demonstration complete!")
96+
97+
if __name__ == "__main__":
98+
main()

0 commit comments

Comments
 (0)