15
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Bedrock AgentCoreのデプロイツールがTypeScriptに対応! 宇宙最速で試してみた

Last updated at Posted at 2026-01-21

これを試します。

プロジェクトの初期化

以下コマンドを実行して、プロジェクトを初期化します。

# Node.jsプロジェクトの初期化
npm init -y
npm pkg set type=module

# 依存パッケージの追加
npm i express @strands-agents/sdk @opentelemetry/auto-instrumentations-node
npm i -D typescript tsx @types/node @types/express

# TypeScript設定の初期化
npx tsc --init --outDir dist

# npmスクリプトの追加
npm pkg set scripts.build="tsc"
npm pkg set scripts.start="node dist/index.js"

# デプロイ前にローカルパッケージを削除
rm -rf node_modules

# AIエージェント用スクリプトの作成
touch index.ts

上記によって作成される package.jsontsconfig.json の存在をもって、後続のAgentCoreツールキットがTypeScriptプロジェクトだと判定してくれるようになります。

AIエージェントの開発

メインのAIエージェントをTypeScriptで作成します。

Strands AgentsのTypeScript版を、AgentCoreランタイムの要件に従ってExpress.jsでAPIサーバー化しています。

index.ts
import * as strands from '@strands-agents/sdk'
import express from 'express'

// AIエージェントとAPIサーバーを作成
const agent = new strands.Agent()
const app = express()

// ヘルスチェック用エンドポイントを作成
app.get('/ping', (_, res) => res.sendStatus(200))

// エージェント呼び出し用エンドポイントを作成
const rawBody = express.raw({ type: '*/*' })
app.post('/invocations', rawBody, async (req, res) => {
    // プロンプトを取り出してAIエージェントを呼び出し
    const prompt = new TextDecoder().decode(req.body)
    const result = await agent.invoke(prompt)
    res.json({ result })
})

// APIサーバーを起動
app.listen(8080)

デプロイ

スターターツールキットを試してみましょう。こいつ自体はPythonのままですw

# AWS認証
aws login

# ツールキットを最新化
pip install --upgrade bedrock-agentcore-starter-toolkit awscrt

# 設定ファイルを作成
agentcore configure

# ビルドしてデプロイ
agentcore deploy

デプロイ完了したら、呼び出してみましょう!

agentcore invoke '{"prompt": "元気?"}'

ちゃんとClaudeからレスポンスが来ました🎉

Response:
{"result":{"type":"agentResult","stopReason":"endTurn","lastMessage":{"type":"message","role":"assistant","content":
[{"type":"textBlock","text":"{\"response\": 
\"はい、元気です!ありがとうございます。あなたはいかがですか?😊\"}"}]}}}

おまけ

StrandsとかAgentCoreがそもそもよく分からない方は、こちらから!

15
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?