Building My First AI Agent with Strands SDK and Amazon Bedrock Errors, Fixes & Lessons Learned

Building My First AI Agent with Strands SDK and Amazon Bedrock: Errors, Fixes & Lessons Learned

使用 Strands SDK 和 Amazon Bedrock 构建我的第一个 AI Agent:错误、修复与经验总结

Introduction

I recently attended an AWS event where we built our first AI agent using the Strands Agents SDK and Amazon Bedrock. The quickstart guide looked simple enough — a few lines of Python, some tools, and a running agent. But the real learning happened in the errors. This article walks you through what I built, every error I hit, and exactly how I fixed them.

简介

最近我参加了一场 AWS 活动,我们使用 Strands Agents SDK 和 Amazon Bedrock 构建了第一个 AI Agent。快速入门指南看起来非常简单——几行 Python 代码、一些工具,然后 Agent 就能运行了。但真正的学习过程其实是在解决错误的过程中发生的。本文将带你了解我构建的内容、我遇到的每一个错误,以及我是如何修复它们的。


What We Built

A simple AI agent that can:

  • Tell you the current time
  • Perform calculations
  • Count letters in a word Three tools. One agent. Sounds easy. It wasn’t — but that’s what made it worth writing about.

我们构建了什么

一个简单的 AI Agent,它可以:

  • 告诉你当前时间
  • 执行计算
  • 统计单词中的字母数量 三个工具,一个 Agent。听起来很简单。实际上并非如此——但这正是它值得一写的原因。

Project Structure

Here’s the folder structure I used:

Agent/
├── .venv/
├── agent.py
└── requirements.txt

项目结构

这是我使用的文件夹结构:

Agent/
├── .venv/
├── agent.py
└── requirements.txt

Setting Up the Environment

First, create and activate a virtual environment:

python -m venv .venv
.venv\Scripts\Activate.ps1 # Windows PowerShell

Then install the required packages:

pip install strands-agents strands-agents-tools

环境配置

首先,创建并激活虚拟环境:

python -m venv .venv
.venv\Scripts\Activate.ps1 # Windows PowerShell

然后安装所需的包:

pip install strands-agents strands-agents-tools

The Agent Code (Starting Point)

The quickstart gave us this agent.py:

from strands import Agent, tool
from strands_tools import calculator, current_time

@tool
def letter_counter(word: str, letter: str) -> int:
    """ Count occurrences of a specific letter in a word. """
    if not isinstance(word, str) or not isinstance(letter, str):
        return 0
    if len(letter) != 1:
        raise ValueError("The 'letter' parameter must be a single character")
    return word.lower().count(letter.lower())

agent = Agent(tools=[calculator, current_time, letter_counter])

message = """ I have 3 requests:
1. What is the time right now?
2. Calculate 3111696 / 74088
3. Tell me how many letter R's are in the word "strawberry" 🍓 """

agent(message)

Simple and clean. Then I ran it. And the errors began.

Agent 代码(起点)

快速入门指南提供了这段 agent.py 代码:

from strands import Agent, tool
from strands_tools import calculator, current_time

@tool
def letter_counter(word: str, letter: str) -> int:
    """ 统计单词中特定字母出现的次数。 """
    if not isinstance(word, str) or not isinstance(letter, str):
        return 0
    if len(letter) != 1:
        raise ValueError("'letter' 参数必须是单个字符")
    return word.lower().count(letter.lower())

agent = Agent(tools=[calculator, current_time, letter_counter])

message = """ 我有 3 个请求:
1. 现在几点了?
2. 计算 3111696 / 74088
3. 告诉我单词 "strawberry" 中有多少个字母 R 🍓 """

agent(message)

简单明了。然后我运行了它。接着,错误就开始出现了。


Error 1: Anthropic Use Case Form Not Submitted

botocore.errorfactory.ResourceNotFoundException: Model use case details have not been submitted for this account. Fill out the Anthropic use case details form before using the model. └ Model id: global.anthropic.claude-sonnet-4-6

What happened: The Strands SDK defaults to Amazon Bedrock with Claude Sonnet 4. But Anthropic requires first-time users to submit a use case form before accessing their models on Bedrock.

How I fixed it:

  1. Went to the AWS Bedrock Console in us-east-1.
  2. Navigated to Model Catalog and searched for Claude Sonnet 4.6.
  3. Clicked the model and hit “Submit use case details”.
  4. Filled out the form (Company name, website, industry, intended users, and use case description).
  5. Submitted and waited ~15 minutes. Once the “Submit use case details” button disappeared and “Open in playground” appeared, I knew it was approved.

错误 1:未提交 Anthropic 用例表单

botocore.errorfactory.ResourceNotFoundException: 该账户尚未提交模型用例详情。在使用模型前,请填写 Anthropic 用例详情表单。 └ 模型 ID: global.anthropic.claude-sonnet-4-6

发生了什么: Strands SDK 默认使用 Amazon Bedrock 的 Claude Sonnet 4。但 Anthropic 要求首次使用的用户在通过 Bedrock 访问其模型之前,必须先提交一份用例表单。

我是如何修复的:

  1. 进入 us-east-1 区域的 AWS Bedrock 控制台。
  2. 导航至 Model Catalog(模型目录) 并搜索 Claude Sonnet 4.6
  3. 点击该模型并选择“Submit use case details(提交用例详情)”。
  4. 填写表单(公司名称、网站、行业、预期用户以及用例描述)。
  5. 提交并等待约 15 分钟。当“Submit use case details”按钮消失并出现“Open in playground”时,我就知道它已获批。

Error 2: Missing Dependency for AWS Login

botocore.exceptions.MissingDependencyException: Using the login credential provider requires an additional dependency. You will need to pip install "botocore[crt]" before proceeding.

What happened: The AWS credential provider I was using needed an extra C extension package called awscrt.

How I fixed it:

pip install "botocore[crt]"

That installed awscrt-0.32.2 and resolved the issue immediately.

错误 2:缺少 AWS 登录依赖项

botocore.exceptions.MissingDependencyException: 使用登录凭证提供程序需要额外的依赖项。在继续之前,你需要运行 pip install "botocore[crt]"。

发生了什么: 我使用的 AWS 凭证提供程序需要一个名为 awscrt 的额外 C 扩展包。

我是如何修复的:

pip install "botocore[crt]"

这安装了 awscrt-0.32.2 并立即解决了该问题。


Error 3: Wrong Model ID — ValidationException

botocore.errorfactory.ValidationException: The provided model identifier is invalid. └ Model id: us.anthropic.claude-sonnet-4-6-20251031-v1:0

What happened: I had added a BedrockModel to my code with a guessed model ID, but it wasn’t valid for my account.

How I fixed it: I ran this command to list all valid inference profile IDs available to my account:

aws bedrock list-inference-profiles --region us-east-1 --profile tidding --query "inferenceProfileSummaries[?contains(inferenceProfileId, 'anthropic')].inferenceProfileId"

It returned a list including: "us.anthropic.claude-sonnet-4-6". That was the correct ID. No version suffix needed.

错误 3:模型 ID 错误 — ValidationException

botocore.errorfactory.ValidationException: 提供的模型标识符无效。 └ 模型 ID: us.anthropic.claude-sonnet-4-6-20251031-v1:0

发生了什么: 我在代码中添加了一个 BedrockModel 并猜测了一个模型 ID,但它对我的账户无效。

我是如何修复的: 我运行了以下命令来列出我账户下所有有效的推理配置文件 ID:

aws bedrock list-inference-profiles --region us-east-1 --profile tidding --query "inferenceProfileSummaries[?contains(inferenceProfileId, 'anthropic')].inferenceProfileId"

它返回了一个列表,其中包括:"us.anthropic.claude-sonnet-4-6"。这就是正确的 ID,不需要版本后缀。


The Final Working Code

After all the fixes, here is the final agent.py:

from strands import Agent, tool
from strands.models import BedrockModel
from strands_tools import calculator, current_time

@tool
def letter_counter(word: str, letter: str) -> int:
    """ Count occurrences of a specific letter in a word. """
    if not isinstance(word, str) or not isinstance(letter, str):
        return 0
    if len(letter) != 1:
        raise ValueError("The 'letter' parameter must be a single character")
    return word.lower().count(letter.lower())

# Specify the Bedrock model explicitly
model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-6", 
    region_name="us-east-1"
)

# Create the agent with tools
agent = Agent(model=model, tools=[calculator, current_time, letter_counter])

message = """ I have 3 requests:
1. What is the time right now?
2. Calculate 3111696 / 74088
3. Tell me how many letter R's are in the word "strawberry" 🍓 """

agent(message)

Run it with:

$env:AWS_PROFILE = "tidding"
python agent.py

最终可运行的代码

经过所有修复后,最终的 agent.py 如下:

from strands import Agent, tool
from strands.models import BedrockModel
from strands_tools import calculator, current_time

@tool
def letter_counter(word: str, letter: str) -> int:
    """ 统计单词中特定字母出现的次数。 """
    if not isinstance(word, str) or not isinstance(letter, str):
        return 0
    if len(letter) != 1:
        raise ValueError("'letter' 参数必须是单个字符")
    return word.lower().count(letter.lower())

# 显式指定 Bedrock 模型
model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-6", 
    region_name="us-east-1"
)

# 使用工具创建 Agent
agent = Agent(model=model, tools=[calculator, current_time, letter_counter])

message = """ 我有 3 个请求:
1. 现在几点了?
2. 计算 3111696 / 74088
3. 告诉我单词 "strawberry" 中有多少个字母 R 🍓 """

agent(message)

运行方式:

$env:AWS_PROFILE = "tidding"
python agent.py

Key Lessons Learned

  1. Always submit the Anthropic use case form first. It’s a one-time requirement per AWS account and blocks everything until done.
  2. Don’t guess model IDs. Use aws bedrock list-inference-profiles to get the exact valid ID for your account.
  3. Specify the model explicitly. The default Strands model ID may not match what your account supports.
  4. botocore[crt] is required when using the AWS login credential provider on Windows. Install it early.
  5. Set your AWS profile before running the agent.

关键经验总结

  1. 务必先提交 Anthropic 用例表单。 每个 AWS 账户只需提交一次,但在完成之前,它会阻塞所有操作。
  2. 不要猜测模型 ID。 使用 aws bedrock list-inference-profiles 获取你账户下准确有效的 ID。
  3. 显式指定模型。 默认的 Strands 模型 ID 可能与你账户支持的不匹配。
  4. 在 Windows 上使用 AWS 登录凭证提供程序时,必须安装 botocore[crt] 尽早安装它。
  5. 在运行 Agent 之前设置好你的 AWS Profile。

What the Agent Loop Looks Like

Once running, the Strands agent follows this loop: Input → Reasoning (LLM) → Tool Selection → Tool Execution → Back to Reasoning → Response The agent automatically decides.

Agent 的运行循环是什么样的

一旦运行起来,Strands Agent 会遵循以下循环: 输入 → 推理 (LLM) → 工具选择 → 工具执行 → 回到推理 → 响应 Agent 会自动做出决策。