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.
- Intent detection
- Multi-step reasoning
- Autonomous tool selection
- Recursive tool execution
- Context-aware responses
- Item availability check
- Price lookup
- Inventory quantity retrieval
- Quote generation
- Receipt PDF generation
- Email delivery
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 β
βββββββββββββββββββββββββββββββββββββββ
- 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.
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
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)
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
- π΄ Fork the repository
- πΏ Create a
feature/*branch - π οΈ Commit changes with clear messages
- π€ Open a Pull Request
The project follows a Git Flowβinspired workflow:
- πΏ
masterβ Stable, production-ready releases - π±
developβ Active development branch - β¨
feature/*β New feature branches
- Pull latest changes from
develop - Create a
feature/*branch - Implement and test changes
- Open PR β Merge into
develop - Release from
developβ Merge intomaster
This ensures stability while enabling safe feature development.