API Reference
    Preparing search index...

    Resolver for AWS Bedrock Agent Function invocations.

    This resolver is designed to handle function invocations from Bedrock Agents.

    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);
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Resolve an incoming Bedrock Agent function invocation event.

      Parameters

      • event: unknown

        The incoming payload of the AWS Lambda function.

      • context: Context

        The context object provided by AWS Lambda, which contains information about the invocation, function, and execution environment.

      Returns Promise<BedrockAgentFunctionResponse>

      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.

      Type Parameters

      Parameters

      • fn: ToolFunction<TParams>

        The tool function

      • config: Configuration

        The configuration object for the tool

        Configuration for a tool in the Bedrock Agent Function Resolver.

        • Optionaldescription?: string

          A description of the tool, which is optional but highly recommended.

        • name: string

          The name of the tool, which must be unique across all registered tools.

      Returns undefined

      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);