The Order System is the most complex service in Automatización Lurwis, powered by an AI agent that handles the complete food ordering flow via WhatsApp. Customers can browse the menu, select dishes, specify quantities and sizes, and confirm their orders through natural conversation.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/KevinhosUTP/Automatizacion-Lurwis/llms.txt
Use this file to discover all available pages before exploring further.
How It Works
When the Clasificador agent detects that a customer wants to order food (keywords like “pedido”, “pedir”, “comer”, “menú”), it routes the conversation to the Agente Pedidos (Orders Agent).Customer Intent Detection
The system recognizes ordering intent even with casual greetings:
- “Hola, quiero hacer un pedido” → Classified as PEDIDOS
- “Buenas noches, tienen delivery?” → Classified as PEDIDOS
- “Quiero 2 parihuelas” → Classified as PEDIDOS
Menu Consultation
Wilson (the AI assistant) uses three PostgreSQL tools to help customers navigate the menu:
- consultar_categorias: Lists available food categories
- consultar_platos: Shows dishes within a specific category
- verificar_plato: Validates dish availability, sizes, and calculates subtotals
Order Building
The agent helps customers build their order by:
- Collecting customer name and delivery address
- Selecting dishes with specific sizes (Personal, Familiar, Único)
- Calculating quantities and subtotals
- Choosing service type (Delivery or Recojo/Pickup)
- Selecting payment method (Yape, Plin, Efectivo, Tarjeta)
Confirmation Flow
The customer must explicitly type the confirmation word to finalize the order:
- Wilson presents a complete order summary with total
- Customer confirms by typing “confirmo” or “confirma” (regex:
/\bconfirm[oa]\b/i) - Order is saved to PostgreSQL database
- Confirmation message sent via WhatsApp
Both “confirmo” and “confirma” are accepted. The regex is case-insensitive and matches word boundaries.
Agent Capabilities
Menu Intelligence
The Orders Agent has exclusive access to menu-specific tools:consultar_categorias
consultar_categorias
Queries the
categorias table to show all active food categories:consultar_platos
consultar_platos
Retrieves dishes and their prices for a specific category:
verificar_plato
verificar_plato
Validates a specific dish selection and calculates the subtotal:
Order Modification
If a customer already has a pending order, the system:- Detects existing order: Checks PostgreSQL for orders with status NOT IN (‘entregado’, ‘cancelado’)
- Analyzes intent: Uses “Detector de pedidos” agent to determine if customer wants to:
- Modify/update their existing order
- Just check the order status
- Routes accordingly:
- Modification → Updates existing order in database
- Status inquiry → Sends current order status
The system maintains conversation context using MongoDB’s
historial_pedidos collection, allowing the agent to remember previous interactions within the same order session.Database Operations
Orders are stored in thepedidos_picanteria table with the following workflow:
New Order
Order Modification
Conversation Example
Sample Order Flow
Sample Order Flow
Customer: Hola, quiero hacer un pedidoWilson: ¡Hola! 👋 Encantado de ayudarte. Para empezar, déjame mostrarte nuestras categorías disponibles:
- Ceviches 🐟
- Chicharrones 🦐
- Sudados 🍲
- Arroces 🍚
-
Ceviche Clásico - Pescado fresco en leche de tigre
- Personal: S/ 25.00
- Familiar: S/ 45.00
-
Ceviche Mixto - Pescado, pulpo, calamar y camarones
- Personal: S/ 35.00
- Familiar: S/ 65.00
- 2x Ceviche Mixto (Personal): S/ 70.00
- Tu nombre completo
- ¿Delivery o Recojo?
- Método de pago (Yape, Plin, Efectivo, Tarjeta)
- 2x Ceviche Mixto (Personal)
Business Rules
Operating Hours
Before processing any order, the system verifies the current time (America/Lima timezone):- Open: 10:00 AM - 11:00 PM
- Closed: Automatic message sent with operating hours
Error Handling
The system includes comprehensive error management:- Database Errors: Sends error notification to customer with reference code
- Invalid Dishes: Agent validates against active menu items only
- Missing Data: Prompts customer for required information
- Failed Confirmations: Prevents order submission without explicit “confirmo”
Technical Details
Agent Model: Google Gemini (thinking model for complex order processing) Memory: MongoDB collectionhistorial_pedidos (25 message context window)
Database: PostgreSQL tables: categorias, platos, plato_precios, pedidos_picanteria
Response Time: Processes orders within the 10-second buffer window
See Also
- Procesador Workflow - Agent routing and classification
- PostgreSQL Integration - Database schema details
- MongoDB Integration - Conversation memory storage