Skip to content

Commit 2fc1fe2

Browse files
authored
Metadata filtering Example in Multi Agent Orchestration architecture (#119)
* Added an example for metadata filtering using Action groups in a multi-agent orchestration setup * Adding an example for metadatafiltering in a mult-agent architecture via action groups * Adding architecture diagram * Adding the release to RELEASE_NOTES.md * Polishin the code to reuse existing scripts * Adjusting the project structure
1 parent fad6395 commit 2fc1fe2

File tree

10 files changed

+1551
-2
lines changed

10 files changed

+1551
-2
lines changed

β€ŽRELEASE_NOTES.mdβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@ Adding [Agent with access to house security camera in cloudformation](/examples/
117117

118118
## 04/07/2025
119119

120-
**[Investment Research Agent](/examples/multi_agent_collaboration/investment_research_agent/)**
120+
**[Investment Research Agent](/examples/multi_agent_collaboration/investment_research_agent/)**
121+
122+
## 18/04/2025
123+
**[Metadata filtering](/examples/multi_agent_collaboration/metadata_filtering)**

β€Žexamples/multi_agent_collaboration/README.mdβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ collaborator.
3434

3535
- **[Voyage Virtuoso Agent](./voyage_virtuoso_agent/)** Dream big with the Voyage Virtuoso, a supervisor agent that is built for high net worth individuals that need help picking the most expensive and elaborate destinations given a theme ("I want to ski on expert slopes, and I need a ski-on/ski-off resort with great night life. Don't disappoint!").
3636

37-
- **[Investment Research Agent](./investment_research_agent/)** The Investment Research Agent has three collaborators: the Smart Summarizer, the Quantitative Analysis Agent, and the News Agent. These specialists are orchestrated to perform investment analysis for a given stock ticker using multimodal financial data, including fetching news from financial documents and the web, analyzing recent stock price movements, and using portfolio optimiation logic.
37+
- **[Investment Research Agent](./investment_research_agent/)** The Investment Research Agent has three collaborators: the Smart Summarizer, the Quantitative Analysis Agent, and the News Agent. These specialists are orchestrated to perform investment analysis for a given stock ticker using multimodal financial data, including fetching news from financial documents and the web, analyzing recent stock price movements, and using portfolio optimiation logic.
38+
39+
- **[Metadata Filtering](./metadata_filtering/)** This project showcases an advanced multi-agent architecture that intelligently routes and filters document queries using metadata-based filtering in Amazon Bedrock Knowledge Bases. By implementing an orchestrator agent that delegates to specialized sub-agents, each handling documents from specific time periods, the solution demonstrates how to build an efficient document retrieval system. The implementation leverages Lambda Action Groups to perform targeted RetrieveAndGenerate API calls, ensuring that only the most relevant documents are processed. This approach significantly improves response accuracy, reduces processing overhead, and enables more precise information retrieval when dealing with large document collections like shareholder letters from different years.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
![Architecture](./metadatafiltering.png)
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

Comments
Β (0)