Slide 10
Slide 10 text
Lambda実装を確認しよう
// importは割愛
const app = new BedrockAgentFunctionResolver({ logger }); // Bedrock Agent – Lambda間のリゾルバ
// Toolsの定義(searchBooks)
app.tool<{ keywords: string, author: string }>(
async ({ keywords, author }, { event }) => {
try {
// Tool logic
const books = await searchBooks(keywords, author, 10);
return books.map(book => ({ ...book }));
} catch (error) {
logger.error('error search books', { error });
const {sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration} = event;
return new BedrockFunctionResponse({
responseState: 'FAILURE',
body: 'Error search books',
sessionAttributes,
promptSessionAttributes,
knowledgeBasesConfiguration,
});
}
},
{
// BedrockAgentFunctionResolverが、Tool useとして識別するメタデータ
name: 'searchBooks',
description: 'Search for books by author or keywords',
}
);
export const handler = async (event: unknown, context: Context) => {
return app.resolve(event as BedrockAgentFunctionEvent, context);
};
まずミニマム版から