Skip to content

Commit f7b71b6

Browse files
committed
Merge branch 'release-1.5.9' of https://github.com/agno-agi/agno into release-1.5.9
2 parents df143f4 + aad98c7 commit f7b71b6

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

cookbook/models/aws/bedrock/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ source ~/.venvs/aienv/bin/activate
1313

1414
### 2. Export your AWS Credentials
1515

16+
#### 2.A: Leverage Access and Secret Access Keys
1617
```shell
1718
export AWS_ACCESS_KEY_ID=***
1819
export AWS_SECRET_ACCESS_KEY=***
@@ -30,6 +31,22 @@ agent = Agent(
3031
)
3132
```
3233

34+
#### 2.B: Leverage AWS SSO Credentials
35+
Log in through the aws sso login command to get access to your account
36+
```shell
37+
aws sso login
38+
```
39+
40+
Leverage sso settings in the AwsBedrock object to leverage the credentials provided by sso
41+
```python
42+
import boto3
43+
agent = Agent(
44+
model=AwsBedrock(id="mistral.mistral-small-2402-v1:0", aws_sso_auth= True),
45+
markdown=True
46+
)
47+
```
48+
49+
3350
### 3. Install libraries
3451

3552
```shell

libs/agno/agno/models/aws/bedrock.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ class AwsBedrock(Model):
3232
2. Or provide a boto3 Session object
3333
3434
Not all Bedrock models support all features. See this documentation for more information: https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference-supported-models-features.html
35+
36+
Args:
37+
aws_region (Optional[str]): The AWS region to use.
38+
aws_access_key_id (Optional[str]): The AWS access key ID to use.
39+
aws_secret_access_key (Optional[str]): The AWS secret access key to use.
40+
aws_sso_auth (Optional[str]): Removes the need for an access and secret access key by leveraging the current profile's authentication
41+
session (Optional[Session]): A boto3 Session object to use for authentication.
3542
"""
3643

3744
id: str = "mistral.mistral-small-2402-v1:0"
3845
name: str = "AwsBedrock"
3946
provider: str = "AwsBedrock"
4047

48+
aws_sso_auth: Optional[bool] = False
4149
aws_region: Optional[str] = None
4250
aws_access_key_id: Optional[str] = None
4351
aws_secret_access_key: Optional[str] = None
@@ -70,18 +78,21 @@ def get_client(self) -> AwsClient:
7078
self.aws_secret_access_key = self.aws_secret_access_key or getenv("AWS_SECRET_ACCESS_KEY")
7179
self.aws_region = self.aws_region or getenv("AWS_REGION")
7280

73-
if not self.aws_access_key_id or not self.aws_secret_access_key:
74-
raise AgnoError(
75-
message="AWS credentials not found. Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables or provide a boto3 session.",
76-
status_code=400,
77-
)
81+
if self.aws_sso_auth:
82+
self.client = AwsClient(service_name="bedrock-runtime", region_name=self.aws_region)
83+
else:
84+
if not self.aws_access_key_id or not self.aws_secret_access_key:
85+
raise AgnoError(
86+
message="AWS credentials not found. Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables or provide a boto3 session.",
87+
status_code=400,
88+
)
7889

79-
self.client = AwsClient(
80-
service_name="bedrock-runtime",
81-
region_name=self.aws_region,
82-
aws_access_key_id=self.aws_access_key_id,
83-
aws_secret_access_key=self.aws_secret_access_key,
84-
)
90+
self.client = AwsClient(
91+
service_name="bedrock-runtime",
92+
region_name=self.aws_region,
93+
aws_access_key_id=self.aws_access_key_id,
94+
aws_secret_access_key=self.aws_secret_access_key,
95+
)
8596
return self.client
8697

8798
def _format_tools_for_request(self, tools: Optional[List[Dict[str, Any]]]) -> List[Dict[str, Any]]:

0 commit comments

Comments
 (0)