# awslabs/genai-bedrock-agent-chatbot architecture

> Architecture diagram of the GitHub repository awslabs/genai-bedrock-agent-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/awslabs/genai-bedrock-agent-chatbot
- Repository: https://github.com/awslabs/genai-bedrock-agent-chatbot

## Overview

This is an EC2-focused chatbot: a user asks through the Streamlit interface, which invokes a Lambda that calls a Bedrock Agent and returns an answer with sources. The Agent handles qualitative questions through a Knowledge Base and quantitative pricing questions through an action Lambda that builds text-to-SQL queries for Athena. The README also documents Glue data preparation and OpenSearch-backed retrieval. Several deployment and integration modules are unsampled, so those relationships are shown only where the README supports them.

Main entry points: [`code/streamlit-app/app.py`](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/streamlit-app/app.py) (Streamlit chat), [`code/lambdas/invoke-lambda/index.py`](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/invoke-lambda/index.py) (Agent invocation Lambda), [`code/lambdas/action-lambda/build_query_engine.py`](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/build_query_engine.py) (SQL query engine), [`code/lambdas/action-lambda/index.py`](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/index.py) (Text-to-SQL action)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat interface"]
  node_streamlit["Streamlit chat<br/>[app.py]"]
  node_frontend_connections["Lambda connection<br/>[connections.py]"]
end

subgraph group_agent["Agent routing"]
  node_invoke["Agent invocation Lambda<br/>[index.py]"]
  node_bedrock_agent{{"Bedrock Agent"}}
end

subgraph group_knowledge["Knowledge retrieval"]
  node_knowledge_base["Bedrock Knowledge Base"]
  node_opensearch[("OpenSearch vector store")]
  node_guide_docs["EC2 guide documents"]
  node_create_index["Vector index setup<br/>[index.py]"]
end

subgraph group_pricing["Pricing queries"]
  node_action_lambda["Text-to-SQL action<br/>[index.py]"]
  node_query_engine["SQL query engine"]
  node_query_prompts["SQL and response prompts"]
  node_athena[("Amazon Athena")]
end

subgraph group_data["Data preparation"]
  node_pricing_csv["EC2 pricing data"]
  node_glue["AWS Glue preparation"]
  node_post_deploy["Agent and data setup"]
  node_cdk_stack["AWS resource definitions<br/>[code_stack.py]"]
end

node_user(("Question asker"))

node_user -->|"asks"| node_streamlit
node_streamlit -->|"gets client"| node_frontend_connections
node_streamlit -->|"invokes"| node_invoke
node_invoke -->|"invokes"| node_bedrock_agent
node_bedrock_agent -->|"routes questions"| node_knowledge_base
node_bedrock_agent -->|"routes questions"| node_action_lambda
node_knowledge_base -->|"retrieves from"| node_opensearch
node_guide_docs -->|"provides content"| node_knowledge_base
node_create_index -->|"creates index"| node_opensearch
node_action_lambda -->|"uses"| node_query_engine
node_query_engine -->|"uses prompts"| node_query_prompts
node_query_engine -->|"executes queries"| node_athena
node_pricing_csv -->|"supplies pricing data"| node_athena
node_glue -->|"prepares data"| node_pricing_csv
node_post_deploy -->|"syncs data"| node_knowledge_base
node_cdk_stack -.->|"defines resources"| node_streamlit
node_invoke -->|"returns answer"| node_user

click node_streamlit "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/streamlit-app/app.py"
click node_frontend_connections "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/streamlit-app/connections.py"
click node_invoke "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/invoke-lambda/index.py"
click node_guide_docs "https://github.com/awslabs/genai-bedrock-agent-chatbot/tree/main/assets/knowledgebase_data_source"
click node_create_index "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/create-index-lambda/index.py"
click node_action_lambda "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/index.py"
click node_query_engine "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/build_query_engine.py"
click node_query_prompts "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/prompt_templates.py"
click node_pricing_csv "https://github.com/awslabs/genai-bedrock-agent-chatbot/tree/main/assets/data_query_data_source/ec2_pricing"
click node_post_deploy "https://github.com/awslabs/genai-bedrock-agent-chatbot/tree/main/code/lambdas/update-lambda"
click node_cdk_stack "https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/code_stack.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_streamlit,node_frontend_connections toneBlue
class node_invoke,node_bedrock_agent toneAmber
class node_knowledge_base,node_opensearch,node_guide_docs,node_create_index toneMint
class node_action_lambda,node_query_engine,node_query_prompts,node_athena toneRose
class node_pricing_csv,node_glue,node_post_deploy,node_cdk_stack,node_user toneIndigo
```

## Components

### Chat interface

- [Streamlit chat](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/streamlit-app/app.py): `code/streamlit-app/app.py`
- [Lambda connection](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/streamlit-app/connections.py): `code/streamlit-app/connections.py`

### Agent routing

- [Agent invocation Lambda](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/invoke-lambda/index.py): `code/lambdas/invoke-lambda/index.py`
- **Bedrock Agent**

### Knowledge retrieval

- **Bedrock Knowledge Base**
- **OpenSearch vector store**
- [EC2 guide documents](https://github.com/awslabs/genai-bedrock-agent-chatbot/tree/main/assets/knowledgebase_data_source): `assets/knowledgebase_data_source`
- [Vector index setup](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/create-index-lambda/index.py): `code/lambdas/create-index-lambda/index.py`

### Pricing queries

- [Text-to-SQL action](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/index.py): `code/lambdas/action-lambda/index.py`
- [SQL query engine](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/build_query_engine.py): `code/lambdas/action-lambda/build_query_engine.py`
- [SQL and response prompts](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/lambdas/action-lambda/prompt_templates.py): `code/lambdas/action-lambda/prompt_templates.py`
- **Amazon Athena**

### Data preparation

- [EC2 pricing data](https://github.com/awslabs/genai-bedrock-agent-chatbot/tree/main/assets/data_query_data_source/ec2_pricing): `assets/data_query_data_source/ec2_pricing`
- **AWS Glue preparation**
- [Agent and data setup](https://github.com/awslabs/genai-bedrock-agent-chatbot/tree/main/code/lambdas/update-lambda): `code/lambdas/update-lambda`
- [AWS resource definitions](https://github.com/awslabs/genai-bedrock-agent-chatbot/blob/main/code/code_stack.py): `code/code_stack.py`

### Other components

- **Question asker**

## Connections

- Question asker → Streamlit chat: asks (evidence: `README.md`)
- Streamlit chat → Lambda connection: gets client (evidence: `code/streamlit-app/app.py`)
- Streamlit chat → Agent invocation Lambda: invokes (evidence: `code/streamlit-app/app.py`)
- Agent invocation Lambda → Bedrock Agent: invokes (evidence: `code/lambdas/invoke-lambda/index.py`)
- Bedrock Agent → Bedrock Knowledge Base: routes questions (evidence: `README.md`)
- Bedrock Agent → Text-to-SQL action: routes questions (evidence: `README.md`)
- Bedrock Knowledge Base → OpenSearch vector store: retrieves from (evidence: `README.md`)
- EC2 guide documents → Bedrock Knowledge Base: provides content (evidence: `README.md`)
- Vector index setup → OpenSearch vector store: creates index (evidence: `README.md`)
- Text-to-SQL action → SQL query engine: uses (evidence: `README.md`)
- SQL query engine → SQL and response prompts: uses prompts (evidence: `code/lambdas/action-lambda/build_query_engine.py`)
- SQL query engine → Amazon Athena: executes queries (evidence: `code/lambdas/action-lambda/build_query_engine.py`)
- EC2 pricing data → Amazon Athena: supplies pricing data (evidence: `README.md`)
- AWS Glue preparation → EC2 pricing data: prepares data (evidence: `README.md`)
- Agent and data setup → Bedrock Knowledge Base: syncs data (evidence: `code/lambdas/update-lambda/trigger_data_source_sync.py`)
- AWS resource definitions → Streamlit chat: defines resources
- Agent invocation Lambda → Question asker: returns answer (evidence: `code/lambdas/invoke-lambda/index.py`)
