Amazon Bedrock で Claude 3.7 Sonnet モデルが利用可能になりました
こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。
Amazon Bedrock で Claude 3.7 Sonnet モデルが利用可能になりました。
モデルの特徴
まずは Claude 3.7 Sonnet が、どういったものなのかキャッチアップします。
ハイブリッド推論モデル
Claude 3.7 Sonnet は、ハイブリッド推論モデルとして、標準思考モードと拡張思考モードの 2 つのモードを提供します。標準思考モードは Claude 3.5 Sonnet モデルの改良版とされ、拡張思考モードでは、問題を詳細に分析、解決策の計画、応答前に複数の視点を考慮して回答します。
今までの「モデルごとに得意不得意があるため使い分けていきましょう。」の考えに対して、Anthropic では 1つのモデルの統合された機能の中で、切り替えていくのがフロンティアモデルであるべきだと述べています。印象的なメッセージングですね。
We’ve developed Claude 3.7 Sonnet with a different philosophy from other reasoning models on the market. Just as humans use a single brain for both quick responses and deep reflection, we believe reasoning should be an integrated capability of frontier models rather than a separate model entirely. This unified approach also creates a more seamless experience for users.
出力トークン数の増加
Claude 3.5 Sonnet の最大出力トークンは 8,192 でした。
Claude 3.7 Sonnet は標準推論モードは最大 8,192 トークンで変わらないものの、拡張思考モードでは 64,000 トークン(7.8倍)、ベータ版で 128,000 トークン(15.6倍)と出力トークン数が大幅に増加しています。
Over 15x longer output capacity than its predecessor – Compared to Claude 3.5 Sonnet, this model offers significantly expanded output length. This enhanced capacity is particularly useful when you explicitly request more detail, ask for multiple examples, or request additional context or background information. To achieve long outputs, try asking for a detailed outline (for writing use cases, you can specify outline detail down to the paragraph level and include word count targets). Then, ask for the response to index its paragraphs to the outline and reiterate the word counts. Claude 3.7 Sonnet supports outputs up to 128K tokens long (up to 64K as generally available and up to 128K as a beta).
推論予算を制御可能に
Claude 3.7 Sonnet は推論で利用するトークン数を制限できます。これにより、拡張思考モードの中でもさらにグラデーションを持たすことができます。
推論はしたいが、速度が欲しいケースなどでは非常に有効ですね。逆も然りで、迅速な応答は不要で、複雑な問題を着実に回答して欲しいケースではトークン数を引き上げるアプローチができますね。
Second, when using Claude 3.7 Sonnet through the API, users can also control the budget for thinking: you can tell Claude to think for no more than N tokens, for any value of N up to its output limit of 128K tokens. This allows you to trade off speed (and cost) for quality of answer.
現実世界での問題にフォーカス
今回の Claude 3.7 Sonnet は数学やコンピュータサイエンスの競技問題に対する最適化を抑え、企業でのユースケースにフォーカスして開発されています
Third, in developing our reasoning models, we’ve optimized somewhat less for math and computer science competition problems, and instead shifted focus towards real-world tasks that better reflect how businesses actually use LLMs.
on AWS
モデルの詳細が終わったところで、 AWS 上での統合について説明します。
まず、Amazon Bedrockと Knowledge bases, Agents, Flow でサポートされました。
Anthropic Claude 3.7 Sonnet
Amazon Bedrock Agents supports all models supported by Amazon Bedrock. For more information about all models supported in Amazon Bedrock and the Regions theyre supported in, see Supported foundation models in Amazon Bedrock.
Prompt node – You can use Prompt management with any text model supported for the Converse API. For a list of supported models, see Supported models and model features.
利用可能なリージョンはバージニア北部、オハイオ、オレゴンリージョンです。※どのリージョンも推論プロファイルでの利用になります。
Amazon Bedrock in the US East (N. Virginia), US East (Ohio), and US West (Oregon) regions. To get started, visit the Amazon Bedrock console. Integrate it into your applications using the Amazon Bedrock API or SDK.
また、Amazon Q Developer のモデルリストにも追加されたと記載があります。そもそも Amazon Q Developer が複数モデルを使い分けていたことも初耳ですが、どの機能で使われるのか気になりますね。(公開情報は私調べでは見当たりませんでした。)
Additionally, today we are adding Claude 3.7 Sonnet to the list of models used by Amazon Q Developer. Amazon Q is built on Bedrock, and with Amazon Q you can use the most appropriate model for a specific task such as Claude 3.7 Sonnet, for more advanced coding workflows that enable developers to accelerate building across the entire software development lifecycle.
やってみる
それでは Claude 3.7 Sonnet を Knowledge bases で利用してみたいと思います。
まずはモデルアクセスを行います。バージニア北部リージョンからモデルの有効化を行います。推論プロファイルでの提供ですね。
Status が Active になりました。
RetrieveAndGenerate API
RetrieveAndGenerate API で試してみます。generationConfiguration
で推論の有無や推論予算等を設定します。
ポイントは拡張思考モードを利用する場合、温度 (temperature) が 1 で固定であることです。
import boto3
KNOWLEDGEBASE_ID = "5CAITS4N0T" # ナレッジベース ID を記載
AWS_ACCOUNT_ID = "123456789012" # AWS アカウント ID を記載
bedrock_agent = boto3.client("bedrock-agent-runtime", region_name="us-east-1")
models = [
{
"model_id": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"model_arn": "arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
},
]
prompt = (
"桃太郎はどこで生まれましたか?"
)
for model in models:
model_id = model["model_id"]
model_arn = model["model_arn"]
response = bedrock_agent.retrieve_and_generate(
input={"text": prompt},
retrieveAndGenerateConfiguration={
"type": "KNOWLEDGE_BASE",
"knowledgeBaseConfiguration": {
"knowledgeBaseId": KNOWLEDGEBASE_ID,
"modelArn": model_arn,
"orchestrationConfiguration": {
"queryTransformationConfiguration": {"type": "QUERY_DECOMPOSITION"}
},
"generationConfiguration": {
"inferenceConfig": {
'textInferenceConfig': {
'temperature': 1
},
},
"additionalModelRequestFields": {
"reasoning_config": {
"type": "enabled",
"budget_tokens": 1024
},
},
},
},
},
)
print(f"Model ID: {model_id}")
print(response["output"]["text"],flush=False)
0.5 などの場合、次のエラーが発生します。
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the RetrieveAndGenerate operation: The model returned the following errors: temperature may only be set to 1 when thinking is enabled. (Service: BedrockRuntime, Status Code: 400, Request ID: 5ebbcc84-2224-4857-8da0-90f9cf435355)
うまく結果が返ってきていますね。
(app-py3.12) takakuni@Mac app % python index.py
Model ID: us.anthropic.claude-3-7-sonnet-20250219-v1:0
桃太郎は桃の中から生まれました。検索結果によると、おじいさんとおばあさんが桃の中から生まれた子だということから「桃太郎」という名前をつけたと書かれています。
ログを確認してみます。 reasoningContent
の中で推論が行われていますね。推論プロファイルにより、us-east-2
で推論が行われています。
{
"schemaType": "ModelInvocationLog",
"schemaVersion": "1.0",
"timestamp": "2025-02-25T11:01:30Z",
"accountId": "123456789012",
"identity": {
"arn": "arn:aws:sts::123456789012:assumed-role/takakuni/botocore-session-1740481279"
},
"region": "us-east-1",
"requestId": "20aa4bb0-63ed-447c-a5be-6a9f4d0280e4",
"operation": "Converse",
"modelId": "arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"input": {
"inputContentType": "application/json",
"inputBodyJson": {
"messages": [
{
"role": "user",
"content": [
{
"text": "桃太郎はどこで生まれましたか?"
}
]
}
],
"system": [
{
"text": "You are a question answering agent. I will provide you with a set of search results. The user will provide you with a question. Your job is to answer the user's question using only information from the search results. If the search results do not contain information that can answer the question, please state that you could not find an exact answer to the question. Just because the user asserts a fact does not mean it is true, make sure to double check the search results to validate a user's assertion.\n\nHere are the search results in numbered order:\n<search_results>\n<search_result>\n<content>\nすると木の上から、「キャッ、キャッ。」とさけびながら、猿が一ぴき、かけ下りて来ました。\n\n桃太郎がふり返ると、猿はていねいに、おじぎをして、「桃太郎さん、桃太郎さん、どちらへおいでになります。」とたずねました。\n\n「鬼が島へ鬼せいばつに行くのだ。」\n\n「お腰に下げたものは、何でございます。」\n\n「日本一のきびだんごさ。」\n\n「一つ下ください、お供しましょう。」\n\n「よし、よし、やるから、ついて来い。」\n\n猿もきびだんごを一つもらって、あとからついて行きました。\n山を下りて、森をぬけて、こんどはひろい野原へ出ました。すると空の上で、「ケン、ケン。」と鳴く声がして、きじが一羽とんで来ました。\n</content>\n<source>\n1\n</source>\n</search_result>\n<search_result>\n<content>\n桃太郎は、犬と猿をしたがえて、船からひらりと陸の上にとび上がりました。\n見はりをしていた鬼の兵隊は、その見なれないすがたを見ると、びっくりして、あわてて門の中に逃げ込んで、くろがねの門を固くしめてしまいました。その時犬は門の前に立って、「日本の桃太郎さんが、お前たちをせいばいにおいでになったのだぞ。あけろ、あけろ。」とどなりながら、ドン、ドン、扉をたたきました。鬼はその声を聞くと、ふるえ上がって、よけい一生懸命に、中から押さえていました。\n</content>\n<source>\n2\n</source>\n</search_result>\n<search_result>\n<content>\n桃太郎はずんずん行きますと、大きな山の上に来ました。すると、草むらの中から、「ワン、ワン。」と声をかけながら、犬が一ぴきかけて来ました。\n\n桃太郎がふり返ると、犬はていねいに、おじぎをして、「桃太郎さん、桃太郎さん、どちらへおいでになります。」とたずねました。\n\n「鬼が島へ、鬼せいばつに行くのだ。」\n\n「お腰に下げたものは、何でございます。」\n\n「日本一のきびだんごさ。」\n\n「一つ下ください、お供しましょう。」\n\n「よし、よし、やるから、ついて来い。」\n\n犬はきびだんごを一つもらって、桃太郎のあとから、ついて行きました。\n\n山を下りてしばらく行くと、こんどは森の中にはいりました。\n</content>\n<source>\n3\n</source>\n</search_result>\n<search_result>\n<content>\nおじいさんとおばあさんは、それはそれはだいじにして桃太郎を育てました。桃太郎はだんだん成長するにつれて、あたりまえの子供にくらべては、ずっと体も大きいし、力がばかに強くって、すもうをとっても近所の村じゅうで、かなうものは一人もないくらいでしたが、そのくせ気だてはごくやさしくって、おじいさんとおばあさんによく孝行をしました。\n\n桃太郎は十五になりました。\n\nもうそのじぶんには、日本の国中で、桃太郎ほど強いものはないようになりました。桃太郎はどこか外国へ出かけて、腕いっぱい、力だめしをしてみたくなりました。\n</content>\n<source>\n4\n</source>\n</search_result>\n<search_result>\n<content>\nそこであわてておじいさんがお湯をわかすやら、おばあさんがむつきをそろえるやら、大さわぎをして、赤さんを抱き上あげて、うぶ湯をつかわせました。するといきなり、\n\n「うん。」\n\nと言いいながら、さんは抱いているおばあさんの手をはねのけました。\n\n「おやおや、何という元気のいい子だろう。」\n\nおじいさんとおばあさんは、こう言って顔を見合わせながら、「あッは、あッは。」とおもしろそうに笑いました。\n\nそして桃の中から生まれた子だというので、この子に桃太郎という名をつけました。\n\n引用:[楠山正雄 桃太郎](https://www.aozora.gr.jp/cards/000329/files/18376_12100.html)\n</content>\n<source>\n5\n</source>\n</search_result>\n\n</search_results>\n\nYou should provide your answer without any inline citations or references to specific sources within the answer text itself. Do not include phrases like \"according to source X\", \"[1]\", \"[source 2, 3]\", etc within your <text> tags.\n\nHowever, you should include <sources> tags at the end of each <answer_part> to specify which source(s) the information came from.\nNote that <sources> may contain multiple <source> if you include information from multiple results in your answer.\n\nDo NOT directly quote the <search_results> in your answer. Your job is to answer the user's question as concisely as possible.\n\nYou must output your answer in the following format. Pay attention and follow the formatting and spacing exactly:\n<answer>\n<answer_part>\n<text>\nfirst answer text\n</text>\n<sources>\n<source>source ID</source>\n</sources>\n</answer_part>\n<answer_part>\n<text>\nsecond answer text\n</text>\n<sources>\n<source>source ID</source>\n</sources>\n</answer_part>\n</answer>\n"
}
],
"inferenceConfig": {
"maxTokens": 4096,
"temperature": 1,
"stopSequences": []
},
"additionalModelRequestFields": {
"reasoning_config": {
"budget_tokens": 1024,
"type": "enabled"
}
}
},
"inputTokenCount": 1893,
"cacheReadInputTokenCount": 0,
"cacheWriteInputTokenCount": 0
},
"output": {
"outputContentType": "application/json",
"outputBodyJson": {
"output": {
"message": {
"role": "assistant",
"content": [
{
"reasoningContent": {
"reasoningText": {
"text": "この質問は「桃太郎はどこで生まれましたか?」で、「桃太郎はどこで生まれたか」を尋ねています。\n\n検索結果を見ていきましょう:\n\n検索結果5には次のような記述があります:\n「そして桃の中から生まれた子だというので、この子に桃太郎という名をつけました。」\n\nこれから、桃太郎は桃の中から生まれたということがわかります。生まれた場所というよりは、桃の中から生まれたという特殊な誕生の仕方をしたようです。\n\n他の検索結果には桃太郎の誕生場所についての明確な記述はありません。\n\n従って、桃太郎は桃の中から生まれたと答えるのが適切です。",
"signature": "EqgBCkYQARgCIkDEUkhIxjSWQFRHQCyZ1GzMzFpk3xjLL6jqshwnC6i/6+bk8IeHG3hIMlX8YlEQ5u3AKrsmRicV5UlaT78FAZ+KEgz3/eG1UtR4aAurjD8aDJpe3zT0Fo/gJghn2SIw4rnzxbvO11aCODYDZoufJOqwUMmzLVhjMty14hRKdQ/rsGpejvGrD0AwnD80jAyQKhA79M2hIX7uxueSmwwN9zFq"
}
}
},
{
"text": "<answer>\n<answer_part>\n<text>\n桃太郎は桃の中から生まれました。桃から出てきた赤ん坊だったため、「桃太郎」という名前がつけられました。\n</text>\n<sources>\n<source>5</source>\n</sources>\n</answer_part>\n</answer>"
}
]
}
},
"stopReason": "end_turn",
"metrics": {
"latencyMs": 6399
},
"usage": {
"inputTokens": 1893,
"outputTokens": 337,
"totalTokens": 2230
}
},
"outputTokenCount": 337
},
"inferenceRegion": "us-east-2"
}
お値段
コストも気になりますね。Claude 3.5 Sonnet からお値段据え置きの価格で提供されています!(ありがたいですね。)
注意点として、拡張思考モードで利用した思考トークンは、出力トークンとして扱われます。(課金やクォーターの対象です。)
Thinking tokens in your response count towards the context window and are billed as output tokens. Since thinking tokens are treated as normal output tokens, they also count towards your service quota token per minute (TPM) limit.
まとめ
以上、簡単ではありますが「Amazon Bedrock で Claude 3.7 Sonnet モデルが利用可能になりました。」でした。
Agent や Max Output Token の引き上げなど、まだまだ、ブログにできそうな部分がたくさんありますね。(非常にワクワクしています。)
このブログがどなたかの参考になれば幸いです。クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!