|
| 1 | +# Amazon Bedrock Multi Agent with metadtafiltering |
| 2 | + |
| 3 | +This project demonstrates how to create an Amazon Bedrock Mult-Agent setup that can answer questions from multiple documents using a Lambda Action group, with separate agents handling different documents from the same Knowledgebase. The architecture utilized action groups to use RetrieveAndGenerate API call with metadata filtering. |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | + |
| 10 | +The solution consists of: |
| 11 | +- An Orchestrator Agent that routes queries to appropriate sub-agents |
| 12 | +- Two sub-agents (Agent1 and Agent2) handling different document years |
| 13 | +- A Lambda function acting a an Action Group in both sub agents, that processes queries using Bedrock Knowledge Base's RetrieveAndGenerate API call. |
| 14 | +- A Knowledge Base containing the shareholder letters and the metadata json file for each letter. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- AWS Account with appropriate permissions |
| 19 | +- Python 3.11 or later |
| 20 | +- AWS CLI configured with appropriate credentials |
| 21 | +- The following AWS services enabled: |
| 22 | + - Amazon Bedrock |
| 23 | + - AWS Lambda |
| 24 | + - IAM |
| 25 | + - Amazon S3 |
| 26 | + |
| 27 | +## Required Documents |
| 28 | + |
| 29 | +Place the following documents in your S3 bucket: |
| 30 | +- AMZN-2020-Shareholder-Letter.pdf |
| 31 | +- Amazon-com-Inc-2023-Shareholder-Letter.pdf |
| 32 | + |
| 33 | +* Note: The above documents will be downloaded via the data_source_creation.py script. |
| 34 | + |
| 35 | +## Setup Instructions |
| 36 | + |
| 37 | +1. Clone and install repository |
| 38 | +``` |
| 39 | +git clone https://github.com/awslabs/amazon-bedrock-agent-samples |
| 40 | +
|
| 41 | +cd amazon-bedrock-agent-samples |
| 42 | +
|
| 43 | +python3 -m venv .venv |
| 44 | +
|
| 45 | +source .venv/bin/activate |
| 46 | +
|
| 47 | +pip3 install -r src/requirements.txt |
| 48 | +
|
| 49 | +cd examples/multi_agent_collaboration/metadata_filtering/ |
| 50 | +
|
| 51 | +pip3 install -r requirements.txt |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +2. Create a bucket |
| 56 | +```aws s3 mb s3://<your bucket name>``` |
| 57 | + |
| 58 | +3. Download shareholder letters and copy them to the S3 bucket created |
| 59 | +```python data_source_creation.py``` |
| 60 | + |
| 61 | +```aws s3 cp ./data_sources/ s3://BUCKET_NAME/ --recursive``` |
| 62 | + |
| 63 | + |
| 64 | +4. Configure environment variables: |
| 65 | +``` |
| 66 | +export AWS_PROFILE=your-profile |
| 67 | +export AWS_REGION=your-region |
| 68 | +export S3_BUCKET_NAME=your-bucket-name |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +5. Deploy the solution: |
| 73 | +``` |
| 74 | +python setup_agents.py --bucket <your bucket name> --account-id <your account ID> |
| 75 | +``` |
| 76 | +Keep note of the orchestrator's ID and aliad ID since we will need to use it in the next step |
| 77 | + |
| 78 | +6. Test the Solution: |
| 79 | + |
| 80 | +``` |
| 81 | +python invoke_agent.py --agent-id <your agent ID> --agent-alias-id <your agent alias ID> --query "<your query>" |
| 82 | +``` |
| 83 | + |
| 84 | +Replace the agent Id and Agent Alias ID with the info returned in Step #3. |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +7. Project Structure |
| 89 | +. |
| 90 | +βββ README.md |
| 91 | +βββ requirements.txt |
| 92 | +βββ knowledge_base_helper.py |
| 93 | +βββ setup_agents.py |
| 94 | +βββ data_souoce_creation.py |
| 95 | +βββ openapi_schema.yaml |
| 96 | +|ββ invoke_agent.py/ |
| 97 | + |
| 98 | + |
| 99 | +## Clean up: |
| 100 | + |
| 101 | +To clean up ONLY the resources created, run the below command. |
| 102 | +``` |
| 103 | +python cleanup.py --delete-bucket <True or False> --bucket <your bucket> --account-id <your account ID> |
| 104 | +``` |
| 105 | + |
| 106 | +* Note --delete-bucket will be used to determine weather to delete the S3 bucket or not. |
| 107 | +* Note that the regions is set to the region you configure, to check your region run ```aws configure``` |
| 108 | + |
| 109 | + |
| 110 | +## Contributers: |
| 111 | +[x] Omar Elkharbotly |
| 112 | +[x] Anna Gruebler |
| 113 | +[x] Maira Ladeira Tanke |
0 commit comments