AI System
Agent-based AI system for generating travel product content, parsing trip descriptions, and providing an interactive travel consultant. Built on laravel/ai with Gemini as default provider.
When to Use
Section titled “When to Use”- TCAI Chat Modal — Create or edit a SupplierTour with an interactive AI conversation that confirms destinations before generating (primary workflow)
- Parse raw trip text (e.g., “Asia India 9N - 2 Delhi - 3 Jaipur”) into itinerary-only data
- Refine individual product template fields with AI assistance (sparkles icons in admin)
- Interactive travel planning via the standalone Travel Consultant chat page
Configuration
Section titled “Configuration”Environment Variables (.env)
Section titled “Environment Variables (.env)”# Default provider is openrouter (configured in config/ai.php)OPENROUTER_API_KEY=your_keyOPENROUTER_BASE_URL=https://openrouter.ai/api/v1OPENROUTER_MODEL="openai/gpt-4o-mini"
# Alternative provider for image tasksGEMINI_API_KEY=your_keyConfig File: config/ai.php
The UsesConfiguredModel concern reads config('ai.model') which resolves to OPENROUTER_MODEL env var.
Source: backend/app/Ai/Concerns/UsesConfiguredModel.php
Architecture
Section titled “Architecture”All agents implement Laravel\Ai\Contracts\Agent and use the Promptable trait with the UsesConfiguredModel concern.
Agents
Section titled “Agents”| Agent | Type | Tokens | Temp | Timeout | Purpose |
|---|---|---|---|---|---|
TravelConsultantAgent | Conversational + Tools | 4000 | 0.7 | 120s | Interactive travel planning with multi-turn chat and tool use |
TripParserAgent | Structured | 16000 | 0.3 | 60s | Parse raw trip text into product template data |
TravelContentAgent | Structured | 4000 | 0.7 | 60s | Generate marketing content from a title |
FieldContentAgent | Structured | 2000 | 0.7 | 30s | Refine/generate a single form field |
HotelGeneratorAgent | Structured | 4000 | 0.7 | 120s | Generate hotel data |
TranslationAgent | Structured | 2800 | 0.3 | 120s | Translate travel product content |
Source: backend/app/Ai/Agents/
Tools (TravelConsultantAgent only)
Section titled “Tools (TravelConsultantAgent only)”| Tool | Purpose |
|---|---|
SearchDestinationsTool | Search POIs by keyword |
SearchHotelsTool | Search hotels by city |
GetExistingTemplatesTool | Find existing templates to avoid duplicates |
GenerateFormContentTool | Generate structured form data (title, descriptions, itinerary) for the TCAI chat modal — returns data without persisting to DB |
CreateProductTemplateTool | Create a ProductTemplate from trip description (standalone chat page) |
Source: backend/app/Ai/Tools/
Services
Section titled “Services”ProductTemplateAIService
Section titled “ProductTemplateAIService”Orchestrates content generation for product templates. All methods accept an optional TcaiProfile for style customization.
| Method | Agent Used | Description |
|---|---|---|
generateContent(title, profile?) | TravelContentAgent | Generate marketing fields from a product title |
generateFromRawInput(rawText, profile?, locale?) | TripParserAgent + TripContentAgent | Parse raw trip text into full template data with resolved itinerary. Used by GenerateFormContentTool in the TCAI chat flow. |
generateItineraryFromRawInput(rawText, profile?, locale?) | TripParserAgent | Generate itinerary-only data (no marketing content). Used by the standalone “Generate Itinerary” action. |
refineField(fieldName, currentValue, instructions, context, profile?) | FieldContentAgent | AI-assisted refinement for a single form field |
generateFromRawInput post-processes itineraries through ItineraryResolver to normalize the schema, ensure route continuity between days, and resolve city names to POI IDs via database lookup and Google Places. It includes a fallback parser for shorthand formats like 5N, 7D, and dash-separated N City patterns (e.g., 3 Bogota - 2 Medellin).
Source: backend/app/Services/ProductTemplateAIService.php
TravelConsultantService
Section titled “TravelConsultantService”Wraps TravelConsultantAgent with three modes:
| Method | Purpose |
|---|---|
prompt(message, profile?) | One-shot text response (standalone chat page) |
startConversation(message, user, profile?, locale?) | Start a new streaming conversation. Prepends locale context. Returns StreamableAgentResponse. |
continueConversation(message, conversationId, user, profile?, locale?) | Continue an existing conversation by ID. Returns StreamableAgentResponse. |
The streaming methods use RemembersConversations on the agent to maintain multi-turn chat history. Conversation state is tied to the authenticated user via forUser() / continue().
Source: backend/app/Services/TravelConsultantService.php
ItineraryResolver
Section titled “ItineraryResolver”Support class that bridges AI output and the itinerary data model:
normalizeRawItinerary()— converts AI raw output to proper schemaensureRouteContinuity()— fills gaps between days with connecting routesresolveItineraryLocations()— resolves city names to POI IDs via database/Google Places
Source: backend/app/Support/ItineraryResolver.php
TCAI Profiles
Section titled “TCAI Profiles”TCAI (Travel Consultant AI) Profiles store reusable personality and style configurations that customize agent behavior.
Table: tcai_profiles — columns: name, description, custom_instructions (text), is_default (boolean)
TcaiProfile::getDefault()returns the default profilemarkAsDefault()sets this profile as default (unsets others in a transaction)- Has many
ProductTemplaterecords viatcai_profile_idFK - Managed in admin at
/admin/tcai-profiles
Source: backend/app/Models/TcaiProfile.php
Admin Integration
Section titled “Admin Integration”TCAI Chatbox Modal (Supplier Tours)
Section titled “TCAI Chatbox Modal (Supplier Tours)”The primary TCAI workflow is an interactive chat modal embedded in the SupplierTour create/edit forms. When an admin pastes raw tour info and clicks “Generate with TCAI”:
- A Filament action modal opens containing the
TcaiChatLivewire component - The chat starts automatically — the agent analyzes the input, searches destinations/hotels, and proposes a city/nights plan
- The admin confirms or adjusts the plan through conversation
- Only after explicit confirmation does the agent call
GenerateFormContentTool, which generates structured form data (title, descriptions, itinerary) without persisting to DB - A green “Apply to Form” button appears — clicking it dispatches a
tcai-content-generatedevent - The
HandlesTcaiContenttrait (shared byCreateSupplierTourandEditSupplierTour) receives the event and populates all form fields including repeaters (itinerary, hotel assignments, activity assignments)
Key components:
TcaiChatLivewire component — manages chat state, streams AI responses viawire:stream, detectsGenerateFormContentTooloutput markersHandlesTcaiContenttrait — event listener that maps AI output to Filament form fields, handles UUID-keyed repeater stateGenerateFormContentTool— AI tool that wrapsProductTemplateAIService::generateFromRawInput(), returns data with__tcai_form_data__markers
Source: backend/app/Livewire/TcaiChat.php, backend/app/Filament/Resources/Suppliers/SupplierTours/Concerns/HandlesTcaiContent.php
Travel Consultant Chat Page (Standalone)
Section titled “Travel Consultant Chat Page (Standalone)”Chat-style Livewire page at /admin/ai/travel-consultant (nav group: “AI Tools”). Users select a TCAI Profile from a dropdown and interact with the TravelConsultantAgent. This page uses CreateProductTemplateTool which persists directly to the database (unlike the chatbox modal flow).
Permission required: use_travel_consultant
Per-Field Refinement (RefineFieldAction)
Section titled “Per-Field Refinement (RefineFieldAction)”Sparkles icon buttons on ProductTemplate form fields open a modal with an instructions textarea and TCAI profile selector. Calls ProductTemplateAIService::refineField() and updates the form field in place.
Permissions
Section titled “Permissions”| Permission | Scope |
|---|---|
view_tcai_profile | View TCAI profiles |
create_tcai_profile | Create TCAI profiles |
update_tcai_profile | Update TCAI profiles |
delete_tcai_profile | Delete TCAI profiles |
use_travel_consultant | Access Travel Consultant chat page |
Related
Section titled “Related”- Product Templates — AI content generation for templates
- Roles and Permissions — TCAI permissions
- Source:
backend/app/Ai/— all agents, tools, and concerns - Source:
backend/app/Services/ProductTemplateAIService.php - Source:
backend/app/Services/TravelConsultantService.php - Source:
backend/app/Livewire/TcaiChat.php - Source:
backend/app/Filament/Resources/Suppliers/SupplierTours/Concerns/HandlesTcaiContent.php - Source:
backend/app/Support/ItineraryResolver.php