Skip to content

jesamkim/agentic-kb-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Agentic RAG Chatbot

A ReAct (Reasoning and Acting) pattern-based AI chatbot that leverages Amazon Bedrock Knowledge Base for document retrieval and citation generation with enhanced multi-stage search capabilities.

πŸš€ Quick Start

Simple Execution

python run_app.py

Manual Execution

streamlit run ui/app_improved_safe_final.py --server.port 8501 --server.address 0.0.0.0

Then open your browser and navigate to http://localhost:8501

✨ Key Features

  • Enhanced ReAct Agent Pattern: Advanced reasoning and acting cycles with intent analysis
  • Multi-Stage Search: Intent-based additional searches for comprehensive results
  • Real-time Progress Tracking: Live UI updates during processing stages
  • Advanced Citation Management: Accurate citation extraction with proper filename display
  • Token-Limited Response Generation: Safe 3000-token response generation with fallback
  • MCP Tool Call Tracking: Real-time tool execution monitoring
  • Session Management: Persistent conversation context across interactions

πŸ—οΈ Architecture

Enhanced System Flow

graph TB
    User[User Query] --> Intent[Intent Analysis]
    Intent --> Primary[Primary KB Search - 50 results]
    Primary --> Additional[Additional Searches - 1-5 times]
    Additional --> Integration[Result Integration]
    Integration --> Response[3000 Token Response]
    Response --> Citations[Citation Display]
    
    subgraph "Real-time UI Updates"
        Progress[Progress Tracking]
        Status[Status Messages]
        Metrics[Quality Metrics]
    end
    
    Intent -.-> Progress
    Primary -.-> Progress
    Additional -.-> Progress
    Response -.-> Progress
Loading

Core Components

  • ReAct Agent (react_agent_improved_safe.py): Main orchestration with enhanced error handling
  • Intent Analyzer (intent_analyzer.py): Query classification and search strategy planning
  • Multi-Stage Search (multi_stage_search.py): Comprehensive search execution
  • Orchestration Agent (orchestration_improved.py): Enhanced query analysis
  • Action Agent (action_improved.py): Search execution with tool tracking
  • Response Agent (response_improved_safe.py): Safe response generation with token limits
  • Citation Display (citation_display.py): Advanced citation rendering

πŸ“ Project Structure

β”œβ”€β”€ ui/                                    # User Interface
β”‚   β”œβ”€β”€ app_improved_safe_final.py        # Main Streamlit application
β”‚   └── citation_display.py               # Citation display components
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agents/                           # AI Agents
β”‚   β”‚   β”œβ”€β”€ react_agent_improved_safe.py  # Main ReAct orchestrator
β”‚   β”‚   β”œβ”€β”€ intent_analyzer.py            # Query intent analysis
β”‚   β”‚   β”œβ”€β”€ orchestration_improved.py     # Enhanced query planning
β”‚   β”‚   β”œβ”€β”€ action_improved.py            # Search execution
β”‚   β”‚   β”œβ”€β”€ response_improved_safe.py     # Safe response generation
β”‚   β”‚   └── multi_stage_search.py         # Multi-stage search engine
β”‚   β”œβ”€β”€ mcp/                              # MCP Integration
β”‚   β”‚   β”œβ”€β”€ server.py                     # MCP server
β”‚   β”‚   β”œβ”€β”€ kb_client.py                  # Knowledge Base client
β”‚   β”‚   β”œβ”€β”€ rerank_client.py              # ReRank service client
β”‚   β”‚   └── tool_call_tracker.py          # Tool execution tracking
β”‚   └── utils/                            # Utilities
β”‚       β”œβ”€β”€ citation.py                   # Citation processing
β”‚       β”œβ”€β”€ session.py                    # Session management
β”‚       └── logger.py                     # Logging utilities
β”œβ”€β”€ config/                               # Configuration
β”‚   └── settings.py                       # Application settings
β”œβ”€β”€ tests/                                # Test suites
β”œβ”€β”€ archive/                              # Archived development files
β”‚   β”œβ”€β”€ ui/                              # Previous UI versions
β”‚   β”œβ”€β”€ agents/                          # Previous agent versions
β”‚   β”œβ”€β”€ docs/                            # Development documentation
β”‚   └── logs/                            # Historical logs
β”œβ”€β”€ run_app.py                           # Simple execution script
└── requirements.txt                     # Dependencies

πŸ”§ Enhanced Features

Intent-Based Multi-Stage Search

  • Primary Search: Hybrid search returning up to 50 results
  • Intent Analysis: Automatic classification of query types (절차_문의, κ·œμ •_확인, 기술_질문, etc.)
  • Additional Searches: 1-5 targeted searches based on intent analysis
  • Result Integration: Smart deduplication and quality scoring

Real-Time Progress Tracking

  • 🧠 Intent Analysis: "μ‚¬μš©μž μ˜λ„ 뢄석 쀑..."
  • πŸ” KB Search: "1μ°¨ KB 검색 μ‹€ν–‰ 쀑... (μ΅œλŒ€ 50개 κ²°κ³Ό)"
  • πŸ” Multi-Stage: "μΆ”κ°€ 검색 2/3 μ‹€ν–‰ 쀑..."
  • πŸ“ Response: "포괄적 응닡 생성 쀑... (3000 토큰 이내)"
  • βœ… Complete: "처리 μ™„λ£Œ!"

Safe Token Management

  • Primary: tiktoken library for accurate token counting
  • Fallback: Character-based estimation when tiktoken unavailable
  • Limit: 3000 token maximum for response generation
  • Quality: Maintains response quality within token constraints

πŸ› οΈ Installation

Prerequisites

  • Python 3.9+
  • AWS Account with Bedrock access
  • Configured AWS credentials

Setup

  1. Clone the repository:
git clone https://github.com/jesamkim/agentic-kb-chat.git
cd agentic-kb-chat
  1. Create virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure settings:
cp config/settings.py.example config/settings.py
# Edit config/settings.py with your AWS and Knowledge Base settings

βš™οΈ Configuration

Knowledge Base Settings

Update config/settings.py:

class KnowledgeBaseSettings:
    kb_id = "YOUR_KB_ID"  # Replace with your actual KB ID
    region = "us-west-2"
    max_results = 50
    search_type = "HYBRID"

Model Settings

class ModelSettings:
    primary_model_id = "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
    region = "us-west-2"
    temperature = 0.0

πŸ§ͺ Testing

Run the test suite:

pytest tests/

πŸ“Š Performance Improvements

Search Quality Enhancement

  • 30% reduction in information omission through multi-stage search
  • Intelligent query expansion based on intent analysis
  • Quality scoring for search results and responses

User Experience

  • Real-time progress tracking eliminates waiting uncertainty
  • Comprehensive citation display with original filenames
  • Error resilience with fallback mechanisms

πŸ—‚οΈ Archive

Development history and intermediate versions are preserved in the archive/ directory:

  • archive/ui/: Previous UI implementations
  • archive/agents/: Earlier agent versions
  • archive/docs/: Development documentation
  • archive/logs/: Historical execution logs

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Amazon Bedrock Knowledge Base RAG Chatbot with ReAct pattern

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages