Slide 18
Slide 18 text
minamo
◆書き方はこんな感じ(toolの書き方が長い)
import { agent, RetryableError, tool } from "@minamojs/minamo";
import { bedrock } from "@minamojs/bedrock";
import { handle } from "@minamojs/lambda-df";
import { z } from "zod";
const support = agent({
name: "support",
model: bedrock("us.anthropic.claude-haiku-4-5-20251001-v1:0"),
instructions: "あなたはオンラインショップのカスタマーサポート担当です。",
tools: {
get_weather: tool({
description: "再配達の計画に使う、都市の天気予報を取得する。",
input: z.object({ city: z.string() }),
run: async ({ city }) => {
const response = await weather.forecast(city);
if (response.status === 503) throw new RetryableError("天気APIが一時的に使えません"); // 自動でリトライ
return response.body; // それ以外の例外はエラー結果としてモデルに返る
},
}),
issue_refund: tool({
description: "人間が承認したあとに、注文を返金する。",
input: z.object({ orderId: z.string(), amountYen: z.number().positive() }),
approval: { when: ({ amountYen }) => amountYen >= 10_000, timeout: { hours: 1 } }, // 1万円以上は承認が必要
run: async (input, { idempotencyKey }) => payments.refund({ ...input, idempotencyKey }),
}),
},
});
export const handler = handle(support, {
prompt: (event: { prompt: string }) => event.prompt,
onHumanRequest: request => slack.notify(request.summary), // 承認依頼を通知(トークンはサーバー側に残す)
});