🧠bedrock
- プラグイン
- aws-dev-toolkit
- ソース
- GitHub で見る ↗
説明
Amazon Bedrockに関する詳細な解説を提供します。対象領域はモデル選定、agent、ナレッジベース、ガードレール、プロンプトエンジニアリング、コストモデリングです。 次のような場合に使用: ユーザーが「Bedrockで構築する」「Bedrockのモデルを選ぶ」「Bedrock agentを設計する」「ナレッジベースをセットアップする」「ガードレールを設定する」「Bedrockのコストを見積もる」「Bedrockの料金を最適化する」「プロンプトキャッシングを使う」「Bedrockのモデルを比較する」と尋ねた場合、またはAmazon Bedrock、基盤モデル、AWS上のRAG、AWS上の生成AIについて言及した場合。
原文を表示
Deep-dive into Amazon Bedrock — model selection, agents, knowledge bases, guardrails, prompt engineering, and cost modeling. This skill should be used when the user asks to "build with Bedrock", "select a Bedrock model", "design a Bedrock agent", "set up a knowledge base", "configure guardrails", "estimate Bedrock costs", "optimize Bedrock pricing", "use prompt caching", "compare Bedrock models", or mentions Amazon Bedrock, foundation models, RAG on AWS, or generative AI on AWS.
ユースケース
- ✓Bedrockのモデルを選定するとき
- ✓Bedrock agentを設計するとき
- ✓ナレッジベースをセットアップするとき
- ✓ガードレールを設定するとき
- ✓Bedrockのコストを見積もるとき
本文(日本語訳)
Amazon Bedrock に特化した専門ガイダンス。 モデル選定、Agent 設計、ナレッジベース、ガードレール、プロンプトエンジニアリング、バッチ推論、コスト最適化を網羅。
プロセス
- ワークロードを把握する: 何を構築するか、誰が利用するか、どの品質基準が求められるか
awsknowledgeMCP ツール(mcp__plugin_aws-dev-toolkit_awsknowledge__aws___search_documentation、mcp__plugin_aws-dev-toolkit_awsknowledge__aws___read_documentation、mcp__plugin_aws-dev-toolkit_awsknowledge__aws___recommend)を使用して、Bedrock の最新モデル提供状況・料金・機能を確認する(これらは頻繁に変わる)- タスクの複雑さ・レイテンシー・コストに基づいて適切なモデルを選定する
- アーキテクチャを設計する: 直接呼び出し、RAG、Agent、またはマルチ Agent
- ユーザー向け画面にガードレールを設定する
references/cost-modeling.mdテンプレートを使ってコストを試算する- モニタリングとコスト管理策を提案する
モデル選定
モデルの選択は、コストと品質の両面で最も重要な意思決定です。まずここを正しく決めてください。
| 用途 | 推奨モデル | 理由 |
|---|---|---|
| 分類・ルーティング・抽出 | Nova Micro または Claude Haiku | 構造化タスクに対して高速・低コスト・高精度 |
| 汎用 Q&A・要約 | Nova Lite または Nova Pro | 品質とコストのバランスが優秀 |
| マルチモーダル(画像+テキスト) | Nova Lite | Sonnet 価格を使わずにコスト効率よくビジョン処理が可能 |
| 複雑な推論・高度な生成 | Claude Sonnet | 能力とコストの最良バランス |
| 最難度の問題・最高品質が必要な場面 | Claude Opus | Sonnet が力不足な場合に限定して使用 |
| 埋め込み | Titan Embed v2 | Cohere より安価で、大半のユースケースに十分な品質 |
| コード生成 | Claude Sonnet | Opus 価格を使わずに高いコード品質を実現 |
注意: モデルの提供状況と料金は頻繁に変わります。最終的な推奨を行う前に、awsknowledge MCP ツール(mcp__plugin_aws-dev-toolkit_awsknowledge__aws___search_documentation、mcp__plugin_aws-dev-toolkit_awsknowledge__aws___read_documentation、mcp__plugin_aws-dev-toolkit_awsknowledge__aws___recommend)で最新情報を必ず確認してください。
モデル選定の原則
- まず動く可能性がある最小モデルから始め、不足が証明されたときだけアップグレードする
- 汎用ベンチマークではなく実データでベンチマークを取る。小さくてもプロンプトが適切に設計されたモデルが、大きな汎用モデルを上回ることは多い
- Bedrock のインテリジェントプロンプトルーティングを活用し、リクエストを適切なモデル階層に自動ルーティングする
- サードパーティモデルをデフォルトにする前に Nova ファミリーを評価する。Nova Pro は多くのタスクで Claude Sonnet と同等の品質を大幅に低いトークン単価で提供し、Nova Lite/Micro は完全な推論能力が不要な分類・ルーティングタスクで 100ms 未満のレイテンシーを実現する。また Nova モデルはクロスプロバイダーのデータ転送料金が発生せず、Bedrock ネイティブ機能(ガードレール、ナレッジベース、Flows)との統合もより深い
Bedrock Agents
設計原則
- 1 Agent、1 つの役割。Agent の説明に「かつ(and)」が含まれる場合は分割を検討する
- ツールが少ない = 推論ステップが少ない = 高速かつ低コスト。ツール数は 3〜5 個がスイートスポット
- シンプルなタスクには直接
InvokeModelを使う。すべてに Agent が必要なわけではない
アーキテクチャパターン
ルーター+スペシャリスト: 軽量な分類器(Nova Micro)がスペシャリスト Agent にルーティングする。各スペシャリストは絞られたツールセットと最適化済みプロンプトを持つ。ツールを 20 個抱えた巨大 1 Agent よりこちらが優れている。
ナレッジベース+ガードレール:
顧客向け Q&A の場合 — KB で検索し、ガードレールで安全性を担保し、モデル呼び出し 1 回で生成する。Agent オーケストレーションは不要で、RetrieveAndGenerate API を直接使用する。
セッションメモリ付き Agent: マルチターン会話の場合 — AgentCore のセッションとメモリを使用する。会話履歴をプロンプトに詰め込む代わりに、Agent がターンをまたいでコンテキストを保持するようにする。
アクショングループ
- 複雑なロジックには Lambda バックのアクショングループを使用する
- クライアント側のツール実行には Return Control を使用する(Agent をステートレスに保ち、Lambda コストを回避できる)
- OpenAPI スキーマは厳密に定義する — 曖昧なスキーマはモデルの誤推測を招く
ナレッジベース
チャンキング戦略
- 固定サイズチャンキング(デフォルト): 良い出発点。300〜500 トークン、10〜20% のオーバーラップを推奨
- セマンティックチャンキング: 品質は高いが埋め込みコストも高い。高価値・異種混合ドキュメントに使用する
- 階層的チャンキング: 明確な構造を持つ長文ドキュメント(マニュアル・法律文書など)に最適
- データソースを丁寧にキュレーションする — RAG では「ゴミを入れればゴミが出る」原則が 2 倍の威力で適用される
ベクトルストアの選定
- OpenSearch Serverless: デフォルトの選択肢。マネージド、スケーラブル、ネイティブ統合。最低コストは
references/cost-modeling.mdを参照 - Aurora PostgreSQL(pgvector): すでに Aurora を運用中の場合に有効 — インフラを集約できる
- Pinecone / Redis: これらのストアへの既存投資がある場合
- PoC では複数の KB で単一の OpenSearch Serverless コレクションを共有してコストを最小化する
検索チューニング
- ハイブリッド検索(セマンティック+キーワード)から始める — 大半のワークロードで純粋なセマンティック検索より高性能
- 取得チャンク数(デフォルト 5)を調整する。チャンクが多い = コンテキストが多い = 入力トークンが多い。良い回答が得られる最小値を見つける
- メタデータフィルタリングで検索範囲を絞る — ドキュメントカテゴリが判明している場合は全件検索を避ける
Bedrock におけるプロンプトエンジニアリング
プロンプトキャッシング
- Bedrock は対応モデルに対して繰り返しのシステムプロンプトを自動的にキャッシュする
- プロンプトの構造: 長くて安定したシステムプロンプト+短い可変ユーザープロンプト
- キャッシュされた入力トークンは最大 90% 安くなる — キャッシュヒットを最大化するようにプロンプトを設計する
プロンプト管理
- Bedrock のプロンプト管理機能でバージョン管理と運用を行う
- プロンプトをコードと同様に扱う — バージョン管理し、テストし、変更をレビューする
- 動的コンテンツには文字列結合ではなくプロンプト変数を使用する
構造化出力
- 明示的なスキーマを持つ JSON をリクエストして出力トークンの無駄を減らす
- 構造化抽出には Converse API のツール使用機能を活用する — プロンプトで JSON を要求するより信頼性が高い
バッチ推論
- 対応モデルではオンデマンドと比べて 50% 安くなる
- 次のような場合に使用: ドキュメント処理、大量分類、データセットのエンリッチメント、評価実行
- 次のような場合には不向き: リアルタイムのユーザー向けリクエスト(レイテンシーは数分〜数時間)
- S3 の入出力経由でジョブを投入する — データパイプラインに自然に組み込める
ガードレール
- ユーザー向けの入力・出力に適用する。内部の Agent 推論ステップはスキップして構わない
- コンテンツフィルターは拒否トピックポリシーより安価 — 広いカテゴリにはフィルターを、特定の制限には拒否トピックを使う
- コンテキストグラウンディングチェックは推論時にハルシネーションを検出する — RAG アプリケーションに有効
- PII 検出・マスキングは組み込み済み — カスタム正規表現を自作せずに活用する
診断用 CLI コマンド
リソースの作成は IaC で行うこと。テンプレートは iac-scaffold スキルを使用してください。
# リージョン内で利用可能なモデルを一覧表示
aws bedrock list-foundation-models \
--query 'modelSummaries[].{id:modelId,name:modelName,provider:providerName}' --output table
# モデルの簡易テスト(invoke-model より推奨される Converse API を使用)
aws bedrock-runtime converse \
--model-id amazon.nova-micro-v1:0 \
--messages '[{"role":"user","content":[{"text":"Hello"}]}]'
# Agent の一覧表示
aws bedrock-agent list-agents --output table
# ナレッジベースの一覧表示
aws bedrock-agent list-knowledge-bases --output table
# ガードレールの一覧表示
aws bedrock list-guardrails --output table
# モデル呼び出しログの設定状況を確認
aws bedrock get-model-invocation-logging-configuration
アンチパターン
- 「念のため」最大モデルをデフォルトにする — 小さく始めて、証拠があればアップグレードする
- 1 回の InvokeModel で済むのに Agent を構築する — Agent はターンごとにコストが積み重なる
- ナレッジベースを使わずドキュメント全体をプロンプトに詰め込む — RAG の方が安価で保守性も高い
- プロンプトキャッシングを無視する — 対応モデルでは自動的に機能する。プロンプトを正しく構造化するだけでよい
- バッチ処理できる大量処理をオンデマンドで実行する — 50% のコスト削減機会を逃す
- スコープが絞られたキュレーション済みコレクションではなく、1 つの巨大なナレッジベースにまとめる — 検索品質の低下とコスト増加を招く
- ユーザー向けアプリでガードレールを省略する — 「後で追加する」は必ずセキュリティインシデントになる
- トークン使用量を監視しない — 特に Agent を使う反復開発中はコストが急速に膨らむ
参考資料
参照ファイル
詳細なコストモデリングと試算については以下を参照してください:
references/cost-modeling.md— 料金モデルの内訳、コストモデリングテンプレート、最適化戦略、モニタリング設定、コスト試算の出力フォーマット
関連スキル
cost-check— Bedrock を超えた幅広い AWS コスト分析iac-scaffold— Bedrock リソース作成用の IaC テンプレートsecurity-review— Bedrock 設定とガードレールポリシーのセキュリティ監査
出力フォーマット
Bedrock ソリューションについてアドバイスする際は以下の形式を使用してください:
| コンポーネント | 選択 | 根拠 |
|---|---|---|
| プライマリモデル | Claude Sonnet | 複雑な推論が必要、品質基準に対してコスト効率が高い |
| ルーティングモデル | Nova Micro | リクエストトリアージ |
原文(English)を表示
Specialist guidance for Amazon Bedrock. Covers model selection, agent design, knowledge bases, guardrails, prompt engineering, batch inference, and cost optimization.
Process
- Understand the workload: what is being built, who consumes it, and what quality bar is required
- Use the
awsknowledgeMCP tools (mcp__plugin_aws-dev-toolkit_awsknowledge__aws___search_documentation,mcp__plugin_aws-dev-toolkit_awsknowledge__aws___read_documentation,mcp__plugin_aws-dev-toolkit_awsknowledge__aws___recommend) to verify current Bedrock model availability, pricing, and features (these change frequently) - Select the right model(s) based on task complexity, latency, and cost
- Design the architecture: direct invocation, RAG, agent, or multi-agent
- Configure guardrails for user-facing surfaces
- Estimate costs using the
references/cost-modeling.mdtemplate - Recommend monitoring and cost controls
Model Selection
The model choice is the single biggest cost and quality decision. Get this right first.
| Need | Recommended Model | Why |
|---|---|---|
| Classification, routing, extraction | Nova Micro or Claude Haiku | Fast, cheap, accurate for structured tasks |
| General Q&A, summarization | Nova Lite or Nova Pro | Strong quality-to-cost ratio |
| Multimodal (image + text) | Nova Lite | Cost-effective vision without Sonnet pricing |
| Complex reasoning, nuanced generation | Claude Sonnet | Best balance of capability and cost |
| Hardest problems, highest quality bar | Claude Opus | Reserve for tasks where Sonnet falls short |
| Embeddings | Titan Embed v2 | Cheaper than Cohere, solid quality for most use cases |
| Code generation | Claude Sonnet | Strong code quality without Opus pricing |
Note: Model availability and pricing change frequently. Verify current options via awsknowledge MCP tools (mcp__plugin_aws-dev-toolkit_awsknowledge__aws___search_documentation, mcp__plugin_aws-dev-toolkit_awsknowledge__aws___read_documentation, mcp__plugin_aws-dev-toolkit_awsknowledge__aws___recommend) before making final recommendations.
Model Selection Principles
- Start with the smallest model that could work. Upgrade only when evidence shows it falls short.
- Benchmark on real data, not generic benchmarks. A smaller well-prompted model often beats a larger general one.
- Use Bedrock's intelligent prompt routing to auto-route requests to the right model tier.
- Evaluate the Nova family before defaulting to third-party models — Nova Pro offers comparable quality to Claude Sonnet for many tasks at significantly lower cost per token, and Nova Lite/Micro provide sub-100ms latency for classification and routing tasks where you don't need full reasoning capability. Nova models also have no cross-provider data transfer fees and deeper native Bedrock integration (Guardrails, Knowledge Bases, Flows).
Bedrock Agents
Design Principles
- One agent, one job. If the agent description contains "and", consider splitting.
- Fewer tools = fewer reasoning steps = faster + cheaper. 3-5 tools is the sweet spot.
- Use direct
InvokeModelfor simple tasks. Not everything needs an agent.
Architecture Patterns
Router + Specialists: A lightweight classifier (Nova Micro) routes to specialized agents. Each specialist has a focused tool set and optimized prompt. This beats one mega-agent with 20 tools.
Knowledge Base + Guardrails: For customer-facing Q&A — KB for retrieval, guardrails for safety, single model call for generation. No agent orchestration needed; use RetrieveAndGenerate API directly.
Agent with Session Memory: For multi-turn conversations — use AgentCore sessions with memory. Let the agent maintain context across turns instead of stuffing history into the prompt each time.
Action Groups
- Use Lambda-backed action groups for complex logic
- Use Return Control for client-side tool execution (keeps agent stateless, avoids Lambda cost)
- Define OpenAPI schemas tightly — vague schemas cause the model to guess (and guess wrong)
Knowledge Bases
Chunking Strategy
- Fixed-size chunking (default): Good starting point. 300-500 tokens with 10-20% overlap.
- Semantic chunking: Better quality, higher embedding cost. Use for high-value, heterogeneous documents.
- Hierarchical chunking: Best for long documents with clear structure (manuals, legal docs).
- Curate the data source — garbage in, garbage out applies doubly to RAG.
Vector Store Selection
- OpenSearch Serverless: Default choice. Managed, scales, integrates natively. See
references/cost-modeling.mdfor minimum costs. - Aurora PostgreSQL (pgvector): Good if already running Aurora — consolidates infrastructure.
- Pinecone / Redis: If existing investments in these stores.
- For PoCs, share a single OpenSearch Serverless collection across multiple KBs to minimize cost.
Retrieval Tuning
- Start with hybrid search (semantic + keyword) — outperforms pure semantic for most workloads
- Tune retrieved chunk count (default 5). More chunks = more context = more input tokens. Find the minimum that gives good answers.
- Use metadata filtering to scope retrieval — avoid searching everything when the document category is known.
Prompt Engineering on Bedrock
Prompt Caching
- Bedrock caches repeated system prompts automatically for supported models
- Structure prompts: long, stable system prompt + short, variable user prompt
- Cached input tokens are up to 90% cheaper — structure prompts to maximize cache hits
Prompt Management
- Use Bedrock's Prompt Management to version and manage prompts
- Treat prompts like code — version them, test them, review changes
- Use prompt variables for dynamic content instead of string concatenation
Structured Output
- Request JSON with explicit schemas to reduce output token waste
- Use the Converse API with tool use for structured extraction — more reliable than asking for JSON in the prompt
Batch Inference
- 50% cheaper than on-demand for supported models
- Use for: document processing, bulk classification, dataset enrichment, eval runs
- Not for: real-time user-facing requests (latency is minutes to hours)
- Submit jobs via S3 input/output — fits naturally into data pipelines
Guardrails
- Apply to user-facing inputs and outputs. Skip for internal agent reasoning steps.
- Content filters are cheaper than denied topic policies — use filters for broad categories, denied topics for specific restrictions.
- Contextual grounding checks catch hallucination at inference time — useful for RAG apps.
- PII detection/redaction is built in — use it instead of building custom regex.
Diagnostic CLI Commands
Resource creation belongs in IaC. Use the iac-scaffold skill for templates.
# List available models in the region
aws bedrock list-foundation-models \
--query 'modelSummaries[].{id:modelId,name:modelName,provider:providerName}' --output table
# Quick model test (Converse API — preferred over invoke-model)
aws bedrock-runtime converse \
--model-id amazon.nova-micro-v1:0 \
--messages '[{"role":"user","content":[{"text":"Hello"}]}]'
# List agents
aws bedrock-agent list-agents --output table
# List knowledge bases
aws bedrock-agent list-knowledge-bases --output table
# List guardrails
aws bedrock list-guardrails --output table
# Check model invocation logging status
aws bedrock get-model-invocation-logging-configuration
Anti-Patterns
- Defaulting to the biggest model "just to be safe" — start small, upgrade with evidence
- Building an agent when a single InvokeModel call would do — agents compound cost per turn
- Stuffing entire documents into prompts instead of using Knowledge Bases — RAG is cheaper and more maintainable
- Ignoring prompt caching — it is automatic for supported models, just structure prompts correctly
- Using on-demand for bulk processing that could be batch — 50% savings left on the table
- One massive Knowledge Base instead of scoped, curated collections — hurts retrieval quality and costs more
- Skipping guardrails on user-facing apps — "we'll add them later" becomes a security incident
- Not monitoring token usage — costs sneak up fast during iteration, especially with agents
Additional Resources
Reference Files
For detailed cost modeling and estimation, consult:
references/cost-modeling.md— Pricing model breakdown, cost modeling template, optimization strategies, monitoring setup, and cost estimation output format
Related Skills
cost-check— Broader AWS cost analysis beyond Bedrockiac-scaffold— IaC templates for Bedrock resource creationsecurity-review— Security audit for Bedrock configurations and guardrail policies
Output Format
When advising on a Bedrock solution:
| Component | Choice | Rationale |
|---|---|---|
| Primary model | Claude Sonnet | Complex reasoning required, cost-effective for the quality bar |
| Routing model | Nova Micro | Cheap classifier for request triage |
| Architecture | Router + Specialist agents | 3 focused agents vs 1 mega-agent |
| Knowledge Base | OpenSearch Serverless, hybrid search | Best retrieval quality, managed infrastructure |
| Guardrails | Content filters + PII redaction | Customer-facing surface |
| Estimated monthly cost | $X,XXX | See references/cost-modeling.md for breakdown |
Include cost profile and watch-out-for items specific to the use case.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。