Skip to content

KumudithaSilva/multi-tool-chat-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

85 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’βœ¨ Multi-Tool Chat Assistant β€” Agentic Grocery AI System

🎯 Overview

The Multi-Tool Chat Assistant is an AI-powered chatbot system built specifically for modern grocery store operations. It goes beyond traditional Q&A chatbots by combining intelligent intent understanding with autonomous tool execution using OpenAI’s GPT-4 function-calling capabilities.

In real-world grocery environments, common operational challenges include:

  • Manual staff intervention for price checks
  • No automated quote generation
  • Inability to instantly create structured receipts
  • Poor handling of multi-step customer requests
  • Lack of autonomous decision-making

For example, when a customer says::

β€œGenerate a quote for 1 Oats and 2 milk packs and send it to my email.”

A typical chatbot may respond conversationally β€” but it cannot execute the full workflow.

The Multi-Tool Chat Assistant solves this by:

  • Understanding grocery-related customer queries
  • Performing multi-step reasoning
  • Automatically selecting and executing tools
  • Retrieving item prices
  • Generating customer quotes
  • Creating receipt PDFs
  • Sending emails to customers

The system is built using clean architecture principles with clear separation of concerns, making it maintainable, testable, and extensible and The assistant doesn’t just answer questions β€” it decides what action to take, executes it, and delivers results.

✨ Core Features

🧠 Agentic Capabilities

  • Intent detection
  • Multi-step reasoning
  • Autonomous tool selection
  • Recursive tool execution
  • Context-aware responses

πŸ›’ Grocery-Specific Functionalities

  • Item availability check
  • Price lookup
  • Inventory quantity retrieval
  • Quote generation
  • Receipt PDF generation
  • Email delivery

πŸ“Έ Chat Assistant App Output (UI Preview)

Chat Assistant Chat Output

image

Chat Assistant Generated Email Output

image

πŸ—οΈ Architecture

The system is follows a layered, interface-driven architecture, designed to ensure modularity, maintainability, and extensibility. Fundamental design principles include dependency injection, interface-based abstraction, separation of concerns, and a plugin-oriented tool architecture.

Key Architectural Highlights:

  • Dependencies are injected via a centralized container, promoting loose coupling and easy testing.
  • Core components define interfaces to enforcing contracts and enabling polymorphic behavior.
  • Tools are treated as modular plugins, supporting dynamic registration and execution without necessitating modifications to existing code.
  • Singleton patterns are used for global utilities like logging.
  • The architecture defines clear layers: UI/API, Components (business logic), Infrastructure (integrations), Interfaces (contracts), and Container (dependency management).
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       UI Layer (Streamlit)          β”‚
β”‚       Backend API (FastAPI)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Components (Business Logic)      β”‚
β”‚  β”œβ”€ Chat Completion Service         β”‚
β”‚  β”œβ”€ Chat Connection Service         β”‚
β”‚  └─ Chat Initialization Service     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Infrastructure (Integrations)    β”‚
β”‚  β”œβ”€ OpenAI Service                  β”‚
β”‚  β”œβ”€ Tool Handler & Executor         β”‚
β”‚  β”œβ”€ Chat History                    β”‚
β”‚  β”œβ”€ Environment & Configuration     β”‚
β”‚  └─ Custom Tools                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Interfaces (Contracts)           β”‚
β”‚  β”œβ”€ Chat Interfaces                 β”‚
β”‚  β”œβ”€ Tool Interfaces                 β”‚
β”‚  β”œβ”€ Infrastructure Interfaces       β”‚
β”‚  └─ Bot Interfaces                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Container (Dependency Injection) β”‚
β”‚    Dependency Wiring & Factory      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Core (Utilities & Patterns)      β”‚
β”‚    Singleton Meta-class             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Layer Responsibilities

  • UI/API Layer: Facilitates user interactions and exposes RESTful endpoints.
  • Components Layer: Orchestrates business logic and AI-driven chat operations.
  • Infrastructure Layer: Manages external integrations, tool execution, and system utilities.
  • Interfaces Layer: Defines abstract contracts to ensure modularity and testability.
  • Container LayerL: Oversees dependency injection and management of singleton instances.

πŸ“ Project Structure

multi-tool-chat-assistant/
β”œβ”€β”€ backend/
β”‚   └── chatbot_fastapi.py          # FastAPI routes & server setup
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/                 # Business logic orchestration
β”‚   β”‚   β”œβ”€β”€ chat_completion.py      # Response generation with tools
β”‚   β”‚   β”œβ”€β”€ chat_connection.py      # OpenAI client management
β”‚   β”‚   └── chat_initialization.py  # Chat session setup
β”‚   β”‚
β”‚   β”œβ”€β”€ container/
β”‚   β”‚   └── chatbot_container.py    # Dependency injection factory
β”‚   β”‚
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   └── singleton_meta.py       # Singleton pattern implementation
β”‚   β”‚
β”‚   β”œβ”€β”€ infrastructure/             # External integrations
β”‚   β”‚   β”œβ”€β”€ openai_service.py       # OpenAI API client wrapper
β”‚   β”‚   β”œβ”€β”€ openai_client.py        # Low-level OpenAI integration
β”‚   β”‚   β”œβ”€β”€ openai_provider.py      # API key management
β”‚   β”‚   β”œβ”€β”€ tool_handler.py         # Tool execution engine
β”‚   β”‚   β”œβ”€β”€ tool_schema.py          # Function schema generation
β”‚   β”‚   β”œβ”€β”€ chat_history.py         # Conversation storage
β”‚   β”‚   β”œβ”€β”€ prompt.py               # System prompt management
β”‚   β”‚   β”œβ”€β”€ dotenv.py               # Environment loading
β”‚   β”‚   └── email_provider.py       # Email service setup
β”‚   β”‚
β”‚   β”œβ”€β”€ interfaces/                 # Abstract contracts
β”‚   β”‚   β”œβ”€β”€ bot/                    # AI client interfaces
β”‚   β”‚   β”œβ”€β”€ chat/                   # Chat service interfaces
β”‚   β”‚   β”œβ”€β”€ infra/                  # Infrastructure interfaces
β”‚   β”‚   β”œβ”€β”€ logging/                # Logger interface
β”‚   β”‚   └── tools/                  # Tool execution interfaces
β”‚   β”‚
β”‚   β”œβ”€β”€ logs/
β”‚   β”‚   └── logger_singleton.py     # Singleton logger instance
β”‚   β”‚
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   └── grocery/                # Grocery-specific tools
β”‚   β”‚       β”œβ”€β”€ tool_call_count.py         # Get item count
β”‚   β”‚       β”œβ”€β”€ tool_call_price.py         # Get item price
β”‚   β”‚       β”œβ”€β”€ tool_call_availability.py  # Check stock
β”‚   β”‚       β”œβ”€β”€ tool_call_quote.py         # Generate quote
β”‚   β”‚       β”œβ”€β”€ too_call_pdf_generator.py  # Create PDF receipts
β”‚   β”‚       β”œβ”€β”€ tool_call_email.py         # Send emails
β”‚   β”‚       └── grocery_data.py            # Product database
β”‚   β”‚
β”‚   └── utils/                      # Utility functions
β”‚       β”œβ”€β”€ email_service.py        # Email operations
β”‚       β”œβ”€β”€ email_template.py       # Email HTML templates
β”‚       β”œβ”€β”€ pdf_generator.py        # PDF creation
β”‚       β”œβ”€β”€ item_price.py           # Price lookup utilities
β”‚       β”œβ”€β”€ item_count.py           # Count utilities
β”‚       β”œβ”€β”€ item_existence.py       # Availability checks
β”‚       β”œβ”€β”€ generate_quote.py       # Quote generation
β”‚       └── config_loader.py        # Configuration reading
β”‚
β”œβ”€β”€ ui/
β”‚   └── app.py                      # Streamlit chatbot interface
β”‚
β”œβ”€β”€ config.json                     # Shop configuration (name, contact)
β”œβ”€β”€ setup.py                        # Package configuration
β”œβ”€β”€ requirement.txt                 # Python dependencies
└── README.md                       # This file

πŸ”„ How It Works

Request Flow

User Input (Streamlit UI)
        β”‚
        β–Ό
FastAPI Backend (/chat/send_request)
        β”‚
        β–Ό
ChatCompletionService
        β”‚
        β”œβ”€β–Ί Tool Schema Generator
        β”‚   (Creates function definitions)
        β”‚
        β”œβ”€β–Ί OpenAI Service
        β”‚   (Sends messages + tools to GPT-4)
        β”‚
        β–Ό
AI Model Response
        β”‚
        β”œβ”€ If tool call requested:
        β”‚  β”‚
        β”‚  β”œβ”€β–Ί GroceryToolExecutor
        β”‚  β”‚   (Parses tool call & arguments)
        β”‚  β”‚
        β”‚  β”œβ”€β–Ί Tool Registry
        β”‚  β”‚   (Gets matching tool)
        β”‚  β”‚
        β”‚  β”œβ”€β–Ί Execute Tool
        β”‚  β”‚   (Calls tool with arguments)
        β”‚  β”‚
        β”‚  β”œβ”€β–Ί Add Result to Messages
        β”‚  β”‚   (Send response back to AI)
        β”‚  β”‚
        β”‚  └─► Recursive Call
        β”‚      (AI generates next response)
        β”‚
        └─ If response generated:
           β”‚
           └─► Return to UI
               (Display to user)

🀝 Contributing

We welcome contributions related to:

  • Additional grocery tools
  • Database integration for inventory
  • Additional language support
  • AI & Prompt Engineering
  • Architecture Improvements
  • Backend Enhancements
  • UI Improvements
  • Testing & Quality Assurance

Contribution Steps

  1. 🍴 Fork the repository
  2. 🌿 Create a feature/* branch
  3. πŸ› οΈ Commit changes with clear messages
  4. πŸ“€ Open a Pull Request

πŸ”€ Git Flow Workflow

The project follows a Git Flow–inspired workflow:

  • 🌿 master β€” Stable, production-ready releases
  • 🌱 develop β€” Active development branch
  • ✨ feature/* β€” New feature branches

Typical Workflow

  1. Pull latest changes from develop
  2. Create a feature/* branch
  3. Implement and test changes
  4. Open PR β†’ Merge into develop
  5. Release from develop β†’ Merge into master

This ensures stability while enabling safe feature development.


About

Multi-tool AI chat assistant for grocery stores | Answer item questions, check stock & quantities, generate quotes, and send via tool calls, leveraging Python, GPT-4, LLM tool calls, FPDF, Mailtrap and FastAPI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages