Optional
options: ResolverOptionsResolve an incoming Bedrock Agent function invocation event.
The incoming payload of the AWS Lambda function.
The context object provided by AWS Lambda, which contains information about the invocation, function, and execution environment.
import {
BedrockAgentFunctionResolver
} from '@aws-lambda-powertools/event-handler/bedrock-agent';
const app = new BedrockAgentFunctionResolver();
app.tool(async (params) => {
const { name } = params;
return `Hello, ${name}!`;
}, {
name: 'greeting',
description: 'Greets a person by name',
});
export const handler = async (event, context) =>
app.resolve(event, context);
Register a tool function for the Bedrock Agent.
This method registers a function that can be invoked by a Bedrock Agent.
The tool function
The configuration object for the tool
Configuration for a tool in the Bedrock Agent Function Resolver.
Optional
description?: stringA description of the tool, which is optional but highly recommended.
The name of the tool, which must be unique across all registered tools.
import {
BedrockAgentFunctionResolver
} from '@aws-lambda-powertools/event-handler/bedrock-agent';
const app = new BedrockAgentFunctionResolver();
app.tool(async (params) => {
const { name } = params;
return `Hello, ${name}!`;
}, {
name: 'greeting',
description: 'Greets a person by name',
});
export const handler = async (event, context) =>
app.resolve(event, context);
If you know the function signature, you can also use a type parameter to specify the parameters of the tool function:
import {
BedrockAgentFunctionResolver,
} from '@aws-lambda-powertools/event-handler/bedrock-agent';
const app = new BedrockAgentFunctionResolver();
app.tool<{ name: string }>(async (params) => {
const { name } = params;
// ^ name: string
return `Hello, ${name}!`;
}, {
name: 'greeting',
description: 'Greets a person by name',
});
export const handler = async (event, context) =>
app.resolve(event, context);
When defining a tool, you can also access the original event
and context
objects from the Bedrock Agent function invocation.
This is useful if you need to access the session attributes or other context-specific information.
import {
BedrockAgentFunctionResolver
} from '@aws-lambda-powertools/event-handler/bedrock-agent';
const app = new BedrockAgentFunctionResolver();
app.tool(async (params, { event, context }) => {
const { name } = params;
// Access session attributes from the event
const sessionAttributes = event.sessionAttributes || {};
// You can also access the context if needed
sessionAttributes.requestId = context.awsRequestId;
return `Hello, ${name}!`;
}, {
name: 'greetingWithContext',
description: 'Greets a person by name',
});
export const handler = async (event, context) =>
app.resolve(event, context);
Resolver for AWS Bedrock Agent Function invocations.
This resolver is designed to handle function invocations from Bedrock Agents.
Example