aws-strands について
aws-strandsは、Strands Agents SDKでエージェントを構築するためのモデル非依存フレームワークスキルです。ツール、マルチエージェントのオーケストレーション、会話管理、ストリーミングを扱い、既定のモデルプロバイダーはAWS Bedrockです。
主な機能
- 01モデルプロバイダーの設定
- 02カスタムおよび組み込みツール
- 03SwarmとGraphによるオーケストレーション
- 04スライディングウィンドウによる会話管理
- 05非同期レスポンスのストリーミング
活用シーン
- 01独自の呼び出し可能な関数を使ったエージェント構築
- 02専門エージェント間でのタスク委任
- 03決定的なマルチエージェントパイプラインの作成
- 04エージェント出力の非同期ストリーミング
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ hoodini/ ai-agents-skills --skill aws-strandsインストール後、Claude Code で/aws-strandsを入力して読み込まれたか確認します。
詳細
Strands Agents SDK
エージェントのロジック、つまり「頭脳」を記述するオープンソースのフレームワークです。モデルに依存せず、デフォルトでは AWS Bedrock を使用します。ノート PC、コンテナ、Lambda、EC2 など、どこでも実行できます。
他の AWS スキルとの関係: Strands はフレームワーク(エージェントが何をするか)です。AWS 上で Strands エージェントをホストしてデプロイするには、aws-harness(AgentCore ランタイム)を使用します。両者は連携します。Strands で記述し、AgentCore でデプロイします。AWS へのデプロイなしで Strands を実行することもできます。
インストール
pip install strands-agents strands-agents-tools
(TypeScript SDK もあります。ドキュメントを参照してください。以下の例は Python です。)
クイックスタート
from strands import Agent
agent = Agent() # defaults to Bedrock, Claude 4 Sonnet
print(agent("What is the capital of France?"))
agent(...) は AgentResult を返します。str(result) でテキストを取得でき、result.message は構造化された dict(role と content)です。
モデルの設定
Bedrock はデフォルトのプロバイダーなので、モデル引数は不要です。Strands はリージョンに適した Claude 4 Sonnet を選択します。別のモデルを指定するには、モデル ID 文字列または BedrockModel プロバイダーを渡します。
from strands import Agent
from strands.models import BedrockModel
# Simple: a Bedrock model id (copy the exact id from the Bedrock model catalog)
agent = Agent(model="<your-bedrock-model-id>")
# Full control:
agent = Agent(model=BedrockModel(
model_id="<your-bedrock-model-id>",
temperature=0.3,
region_name="us-west-2",
))
Strands はモデルに依存しません。ほかのプロバイダー(Anthropic の直接利用、OpenAI など)も、それぞれのプロバイダークラスから利用できます。model-providers のドキュメントを参照してください。
カスタムツール
@tool デコレーターを使うと、関数をモデルから呼び出せるようになります。モデルは docstring を読み取ります(最初の段落が説明になり、Args: がパラメーターの説明になります)。
from strands import Agent, tool
@tool
def word_count(text: str) -> str:
"""Count the number of words in a piece of text.
Args:
text: The text to analyze.
"""
return f"{len(text.split())} words"
agent = Agent(tools=[word_count])
失敗した場合は、例外を送出するのではなく、復旧可能な文字列("Error: ... ask the user to rephrase")を返してください。モデルは戻り値を読み取り、復旧できます。
事前構築済みのツール
from strands_tools import calculator # from the strands-agents-tools package
agent = Agent(tools=[calculator])
マルチエージェントのパターン
検証済みのパターンは 3 つあります。まずは エージェントをツールとして利用する方法(最も簡単な委譲)から始めてください。エージェントを @tool でラップします。
from strands import Agent, tool
researcher = Agent(system_prompt="You research topics thoroughly.")
@tool
def research(query: str) -> str:
"""Delegate a research question to the research specialist."""
return str(researcher(query)) # str(AgentResult) = the text output
coordinator = Agent(tools=[research])
coordinator("Research the history of espresso and summarize it.")
構造化されたオーケストレーションには、Swarm(エージェント同士が動的に処理を引き継ぐ)または Graph(あるノードの出力を次のノードに渡す決定論的な DAG)を使用します。
from strands.multiagent import Swarm, GraphBuilder
# Swarm - dynamic handoffs
swarm = Swarm([researcher, writer, editor])
swarm("Draft and polish an article about espresso.")
# Graph - deterministic pipeline
builder = GraphBuilder()
builder.add_node(researcher, "research")
builder.add_node(writer, "write")
builder.add_edge("research", "write") # research output -> writer input
graph = builder.build()
graph("Write an article about espresso.")
Graph/Swarm API の全容については、マルチエージェントのドキュメントを参照してください。
会話の管理(コンテキストウィンドウ)
Strands が会話ウィンドウを管理します(これは長期記憶ではありません)。デフォルトではスライディングウィンドウを使用します。
from strands import Agent
from strands.agent.conversation_manager import SlidingWindowConversationManager
agent = Agent(conversation_manager=SlidingWindowConversationManager(window_size=20))
セッションをまたいで保持される永続的なメモリには、AgentCore Memory(aws-harness を参照)または strands-agents-tools のメモリツールを使用してください。
ストリーミング
async for event in agent.stream_async("Explain quantum computing"):
print(event)
AWS へのデプロイ
Strands はどこでも実行できます。管理されたメモリ、ID、可観測性を備えたサーバーレスエンドポイントとして AWS 上で Strands エージェントを実行するには、AgentCore ハーネスの aws-harness を使用してください。
リソース
- Strands のドキュメント:https://strandsagents.com/
- Python クイックスタート:https://strandsagents.com/docs/user-guide/quickstart/python/
- マルチエージェントのパターン:https://strandsagents.com/docs/user-guide/concepts/multi-agent/multi-agent-patterns/
- モデルプロバイダー:https://strandsagents.com/docs/user-guide/concepts/model-providers/
- GitHub:https://github.com/strands-agents/sdk-python