継続は力なり

タイトル通り定期的な更新を心掛けるブログです。

Amazon Bedrock AgentCore CLI 1.0 でローカル実行からデプロイまで試したメモ✍

タダです.

Amazon Bedrock AgentCore CLI 1.0 が出たので,Strands のプロジェクトを生成してローカル実行から東京リージョンへのデプロイまで試したメモをまとめます.

aws.amazon.com

AgentCore CLI 1.0 でできること

AgentCore CLI は npm の @aws/agentcore として配布されているツールです.プロジェクトを作り,開発,デプロイ,呼び出し,ログやトレースの確認までを agentcore コマンドで扱います.

やりたいこと 主なコマンド
テンプレートからプロジェクトを作る create
プロジェクトにリソースを追加・削除する add, remove
Runtime のコードをローカルで動かす dev
ビルドして AWS にデプロイする build, deploy
デプロイ済みの構成を確認する status
Runtime,Harness,Gateway を呼び出す invoke
ログ・トレース・評価を扱う logs, traces, eval
既存のリソースを調べる・操作する runtime, harness, gateway, memory, identity, payment
Harness をコードとして取り出す・既存プロジェクトを移行する export, migrate

runtime や memory などのリソース別コマンドはプロジェクトの外からも使えるので,この CLI で作ったエージェント以外も調べられます.

github.com

インストール

@aws/agentcore の 1.0.0 で検証を行いました.前提は Node.js 20.12.0 以上で,Python のエージェントを動かすには Python 3.10 以上と uv が必要です.

npm install -g @aws/agentcore@1.0.0
agentcore --version

agentcore --help を実行すると,コマンドが Project,Resources,Settings に分かれて表示されます.

agentcore --help
Usage: agentcore [options] [command]

the platform for production AI agents

Options:
  --region <region>  AWS region
  --debug            debug logging (default: false)
  --json             JSON output (default: false)
  -h, --help         display help for command
  -V, --version      display the CLI version

Project:
  create             create a new project
  add                add project resources
  dev                develop and test project agents
  deploy             build and deploy project resources to an AWS target
  invoke             invoke a Runtime, harness, or Gateway
  status             inspect deployed project resources for an AWS target
  logs               stream or search logs for resources in the current project
  traces             inspect traces for resources in the current project
  export             convert project resources into editable code you own
  migrate            migrate an AgentCore CLI v0 project to the current project format, keeping its
                     deployed resources
  remove             remove a resource from the project
  build              build the project's deployable artifacts

Resources:
  harness            manage config-defined agents and their versions
  runtime            inspect hosted agent code, its endpoints, and versions
  gateway            inspect MCP tool gateways and their targets
  identity           manage API key and OAuth credential providers
  memory             inspect agent memory: sessions, events, and records
  eval               evaluate and optimize agents with evaluators and A/B tests
  payment            inspect payment managers, sessions, and instruments

Settings:
  feedback           send feedback about AgentCore to the team
  config             read/write global config values
  update             check for and install CLI updates

docs.aws.amazon.com

Strands のプロジェクトを生成する

agent-python-strands テンプレートからプロジェクトを作りました.

agentcore create \
  --name CliV1Strands \
  --template agent-python-strands \
  --skip-install \
  --skip-git \
  --json

生成された主なファイルが以下です.app/agent/ がエージェントのコード,agentcore/ がリソースの設定とデプロイ用の CDK アプリです.

CliV1Strands/
├── agentcore/
│   ├── agentcore.json
│   ├── aws-targets.json
│   ├── .env.local
│   └── cdk/
└── app/
    └── agent/
        ├── main.py
        ├── parse.py
        ├── model/load.py
        ├── memory/session.py
        └── pyproject.toml

agentcore/agentcore.json の Runtime の定義は以下で,コードを zip にして載せる構成です.

{
  "name": "agent",
  "build": "CodeZip",
  "modelProvider": "Bedrock",
  "entrypoint": "main.py",
  "codeLocation": "app/agent",
  "runtimeVersion": "PYTHON_3_14",
  "protocol": "HTTP"
}

あわせて agentMemory という Memory も定義され,イベント保持期間は 30 日,ストラテジーは SEMANTIC, USER_PREFERENCE, SUMMARIZATION, EPISODIC の 4 つでした.エージェントをひとつ試すつもりでも Memory までデプロイ対象に入るので,生成直後に agentcore.json を読んでおくのがポイントです.

モデルは model/load.py で global.anthropic.claude-sonnet-5-5 が指定されていました.入力は prompt を持つ JSON で,actorId は Memory のユーザー単位のスコープに使われます.

Strands をローカルで動かす

依存関係を入れて dev で起動しました.

cd CliV1Strands
(cd app/agent && uv sync)
(cd agentcore/cdk && npm install)

export AWS_REGION=ap-northeast-1
agentcore dev --agent agent --port 18082

dev は headless が既定で,ブラウザの Agent Inspector を使う場合は --mode browser を付けます.別のターミナルから呼び出しました.

agentcore invoke \
  --runtime agent \
  --local \
  --port 18082 \
  --payload '{"prompt":"3 と 5 を足してください","actorId":"blog-test-user"}'

応答は Server-Sent Events で返ってきます.テンプレートの main.py に定義された add_numbers ツールをモデルが呼んでから回答していました.

data: {"event": {"contentBlockStart": {"start": {"toolUse": {"toolUseId": "...", "name": "add_numbers", "type": "tool_use"}}, "contentBlockIndex": 0}}}
...
data: {"event": {"contentBlockDelta": {"delta": {"text": "8** です。"}, "contentBlockIndex": 0}}}
data: {"event": {"messageStop": {"stopReason": "end_turn"}}}

status=200 content-type=text/event-stream; charset=utf-8 runtime-session-id=fc0ea2cf-... complete=true bytes=1658

ローカルでもモデルは Bedrock を呼ぶので,手元の認証情報が使われます.Memory は MEMORY_AGENTMEMORY_ID がないと使われない作りなので,ローカルでは会話が保存されません.

東京リージョンにデプロイする

deploy は CDK でリソースを作るので,bootstrap やスタック操作,iam:PassRole などの権限が必要です.

docs.aws.amazon.com

agentcore deploy

実際の出力が以下です.

created default deployment target: account 123456789012, region ap-northeast-1 (agentcore/aws-targets.json)
verifying AWS account 123456789012
synthesizing CloudFormation templates
enabling CloudWatch Transaction Search
bootstrapping aws://123456789012/ap-northeast-1
deploying AgentCore-CliV1Strands-default (usually takes a few minutes)
deployed project 'CliV1Strands' to target 'default'
next step:
  agentcore invoke

デプロイ先のターゲットが aws-targets.json に書き込まれ,CDK の bootstrap と CloudWatch Transaction Search の有効化まで処理に含まれていました.Transaction Search はアカウント側の設定なので,不要なら事前に agentcore config transactionSearch false で外しておけます.デプロイは 4 分ほどで完了しました.

agentcore status --json では Runtime agent と Memory agentMemory が deployed になっていて,Runtime の環境変数には MEMORY_AGENTMEMORY_ID が設定されていました.デプロイ後は追加の設定なしで Memory が使われます.

なお,deploy に --dry-run はなく,承認待ちなしで作成・更新が進むので注意です.

デプロイ先を呼び出す

--local を外すと,デプロイした Runtime が呼ばれます.

agentcore invoke \
  --runtime agent \
  --payload '{"prompt":"3 と 5 を足してください","actorId":"blog-test-user"}'

ローカルと同じく add_numbers を経由して「3 と 5 を足すと 8 です。」が返ってきました.

ログとトレースを確認する

ログも agentcore から取得できます.以下は出力をメッセージ部分に絞ったものです.

agentcore logs runtime --name agent --since 30m
Created session: 98f9d05d-... with event: ...
Retrieved 0 memories from namespace: /users/blog-test-user/preferences
Retrieved 0 memories from namespace: /users/blog-test-user/facts
Tool #1: add_numbers
Created event: ...
Found credentials from IAM Role: execution_role

渡した actorId が Memory の名前空間に入り,会話がイベントとして書き込まれていました.モデルの呼び出しは Runtime の実行ロールに切り替わっています.

agentcore traces runtime list --name agent
TRACE ID                          TIMESTAMP             SESSION ID
6ae54f0c5ce1fd567f220c46770041c3  2026-10-31 02:14:46Z  98f9d05d-736f-4548-8769-0d6dabd295ed

invoke のセッション ID からログとトレースまで,コンソールに移らずに辿れるのが良いです.Memory はストラテジーが 4 つ有効な状態でデプロイされるので,本番で使う際は必要なストラテジーと実行ロールの権限を見直しておくとよさそうです.

aws.amazon.com

まとめ

AgentCore CLI 1.0 で Strands のプロジェクトを生成し,ローカル実行から東京リージョンへのデプロイ,ログとトレースの確認までを試しました.