You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Use `lwa_fastapi_middleware_bedrock_agent` middleware
* Add a comment about the middleware
* Add Zip version of Bedrock Agent FastAPI example
* Update file permission
This project demonstrates the integration of "Agents for Amazon Bedrock" with a FastAPI application on AWS Lambda. It showcases how to effectively build an Agents for Amazon Bedrock within an serverless FastAPI application environment.
4
+
5
+
The application can be deployed in an AWS account using the [Serverless Application Model](https://github.com/awslabs/serverless-application-model). The `template.yaml` file in the root folder contains the application definition.
6
+
7
+
## How does it work?
8
+
9
+
[Agents for Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/agents.html) offers you the ability to build and configure autonomous agents in your application.
10
+
11
+
Action groups define the tasks that you want your agent to help customers carry out. An action group consists of the following components that you set up.
12
+
13
+
- An OpenAPI schema that define the APIs that your action group should call. Your agent uses the API schema to determine the fields it needs to elicit from the customer to populate for the API request.
14
+
15
+
- A Lambda function that defines the business logic for the action that your agent will carry out.
16
+
17
+
In this example, we build a FastAPI app to query S3 buckets in the user's AWS account. The FastAPI apps automatically generate OpenAPI schema. And Lambda Web Adapter passes through the Bedrock Agent Action invocation payload to the FastAPI at path `/events` via Lambda Web Adapter's new non-http pass through feature. In the FastAPI app, a middleware intercepts the payload to `/evets` route, transforms it into a http request, and continues to invoke the correct FastAPI routes. In this way, developers can build a Bedrocket Agent Action Group with a single Lambda Function.
18
+
19
+
## Pre-requisites
20
+
21
+
The following tools should be installed and configured.
Navigate to the sample's folder and use the SAM CLI to build a container image
31
+
32
+
```shell
33
+
sam build --use-container
34
+
```
35
+
36
+
This command compiles the application and prepares a deployment package in the `.aws-sam` sub-directory.
37
+
38
+
To deploy the application in your AWS account, you can use the SAM CLI's guided deployment process and follow the instructions on the screen
39
+
40
+
```shell
41
+
sam deploy --guided
42
+
```
43
+
44
+
## Generate OpenAPI schema
45
+
46
+
Before you create your agent, you should set up action groups that you want to add to your agent. When you create an action group, you must define the APIs that the agent can invoke with an OpenAPI schema in JSON or YAML format. (see [reference](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-api-schema.html))
47
+
48
+
FastAPI can generate OpenAPI schema.
49
+
50
+
Please install the required dependency in a virtual environment first.
0 commit comments