Trip Planner Agent
agentsllmsvector-databaselancedbgptopenaiAImultimodal-aimachine-learningembeddingsfine-tuningTrip_planner_swarm_style_agentexamplesdeep-learninggpt-4-visionllama-indexragmultimodallangchainlancedb-recipes
Export
Swarm-Style Agent Tutorial with LanceDB for Retrieval
In this tutorial, we are using an MSwarm-style agent system, where multiple agents communicate with each other to collaboratively generate answers. LanceDB is used for efficient information retrieval, including full-text search (FTS) and other advanced query capabilities.

Key Features
🚀 Multi-Agent Collaboration – Specialized agents work together, seamlessly passing context to one another.
🔧 Customizable Handoff Tools – Built-in mechanisms for smooth communication between agents.
📂 LanceDB for Data Retrieval – High-performance vector search and full-text search for accurate and fast information retrieval.
🌍 Travel Agent Use Case – Agents collaborate to handle different aspects of travel planning, ensuring efficient and context-aware responses.
Importing the relevant libraires
[ ]
[ ]
Files downloaded and loaded successfully!
[ ]
/usr/local/lib/python3.11/dist-packages/huggingface_hub/utils/_auth.py:94: UserWarning: The secret `HF_TOKEN` does not exist in your Colab secrets. To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session. You will be able to reuse this secret in all of your notebooks. Please note that authentication is recommended but still optional to access public models or datasets. warnings.warn(
modules.json: 0%| | 0.00/349 [00:00<?, ?B/s]
config_sentence_transformers.json: 0%| | 0.00/116 [00:00<?, ?B/s]
README.md: 0%| | 0.00/10.5k [00:00<?, ?B/s]
sentence_bert_config.json: 0%| | 0.00/53.0 [00:00<?, ?B/s]
config.json: 0%| | 0.00/612 [00:00<?, ?B/s]
model.safetensors: 0%| | 0.00/90.9M [00:00<?, ?B/s]
tokenizer_config.json: 0%| | 0.00/350 [00:00<?, ?B/s]
vocab.txt: 0%| | 0.00/232k [00:00<?, ?B/s]
tokenizer.json: 0%| | 0.00/466k [00:00<?, ?B/s]
special_tokens_map.json: 0%| | 0.00/112 [00:00<?, ?B/s]
config.json: 0%| | 0.00/190 [00:00<?, ?B/s]
prosessing user query to strctured data
[ ]
[ ]
[ ]
Flight Query Result: {'messages': [HumanMessage(content='I need a flight from Bangalore to Mumbai tomorrow', additional_kwargs={}, response_metadata={}, id='e26ff013-6a20-4b6e-ab42-a69a9bc06445'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_pG6xNJ4lsXNP9g3eReIxQ2I9', 'function': {'arguments': '{\n "query": "flights from Bangalore to Mumbai on 2025-03-09"\n}', 'name': 'search_flights'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 30, 'prompt_tokens': 451, 'total_tokens': 481, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4-0613', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, name='flight_assistant', id='run-7b828d97-3571-46ad-abbb-7f98a6eb18e5-0', tool_calls=[{'name': 'search_flights', 'args': {'query': 'flights from Bangalore to Mumbai on 2025-03-09'}, 'id': 'call_pG6xNJ4lsXNP9g3eReIxQ2I9', 'type': 'tool_call'}], usage_metadata={'input_tokens': 451, 'output_tokens': 30, 'total_tokens': 481, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}), ToolMessage(content='{"total_results": 5, "flights": [{"flight_number": "AK132", "airline": "Akasa Air", "origin": "Ahmedabad", "destination": "Mumbai", "departure": "9:30", "price": "8590.63", "details": {"flight_info": "AK132 - Akasa Air", "route": "Ahmedabad (AMD - Sardar Vallabhbhai Patel Intl) → Mumbai (BOM - Chhatrapati Shivaji Intl)", "timing": "Departure: 9:30, Arrival: 11:30, Duration: 2h 00m", "price_seats": "₹8590.63, 22 seats left", "class": "Class: Business"}}, {"flight_number": "SP364", "airline": "SpiceJet", "origin": "Goa", "destination": "Kolkata", "departure": "13:30", "price": "7902.01", "details": {"flight_info": "SP364 - SpiceJet", "route": "Goa (GOI - Goa Dabolim Airport) → Kolkata (CCU - Netaji Subhas Chandra Bose Intl)", "timing": "Departure: 13:30, Arrival: 16:30, Duration: 3h 15m", "price_seats": "₹7902.01, 89 seats left", "class": "Class: Economy"}}, {"flight_number": "SP436", "airline": "SpiceJet", "origin": "Goa", "destination": "Kolkata", "departure": "7:00", "price": "10768.75", "details": {"flight_info": "SP436 - SpiceJet", "route": "Goa (GOI - Goa Dabolim Airport) → Kolkata (CCU - Netaji Subhas Chandra Bose Intl)", "timing": "Departure: 7:00, Arrival: 9:00, Duration: 2h 00m", "price_seats": "₹10768.75, 84 seats left", "class": "Class: Economy"}}, {"flight_number": "GO365", "airline": "Go First", "origin": "Kolkata", "destination": "Chennai", "departure": "22:45", "price": "11365.27", "details": {"flight_info": "GO365 - Go First", "route": "Kolkata (CCU - Netaji Subhas Chandra Bose Intl) → Chennai (MAA - Chennai Intl)", "timing": "Departure: 22:45, Arrival: 23:45, Duration: 1h 45m", "price_seats": "₹11365.27, 88 seats left", "class": "Class: Economy"}}, {"flight_number": "AI507", "airline": "AirAsia India", "origin": "Kolkata", "destination": "Bangalore", "departure": "23:00", "price": "9273.71", "details": {"flight_info": "AI507 - AirAsia India", "route": "Kolkata (CCU - Netaji Subhas Chandra Bose Intl) → Bangalore (BLR - Kempegowda Intl)", "timing": "Departure: 23:00, Arrival: 0:00, Duration: 1h 45m", "price_seats": "₹9273.71, 28 seats left", "class": "Class: Business"}}]}', name='search_flights', id='942a1c96-3c4d-4046-b115-7eaa5c1a2d06', tool_call_id='call_pG6xNJ4lsXNP9g3eReIxQ2I9'), AIMessage(content="I'm sorry, but it seems there has been a mistake in the search. I was unable to find direct flights from Bangalore to Mumbai for tomorrow. Could you please confirm the locations or do you want to retry with different search criteria?", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1243, 'total_tokens': 1292, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4-0613', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, name='flight_assistant', id='run-2dd5f8e6-2259-462b-98e5-8e058c860368-0', usage_metadata={'input_tokens': 1243, 'output_tokens': 49, 'total_tokens': 1292, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}
We are using the same thread_id to maintain continuity in memory for streaming purposes.
[ ]
================================ Human Message ================================= can you check delhi hotels ================================= Tool Message ================================= Name: transfer_to_hotel_assistant Successfully transferred to hotel_assistant ================================== Ai Message ================================== Name: hotel_assistant Here are some hotels in Delhi and nearby areas: **Delhi** 1. [Hotel Delhi Residency, Saket](link) - Price per night: ₹16368.2 - Guest rating: 4.2/5 - Amenities: Free Wi-Fi, Fitness Center, Airport Shuttle, Room Service - Neighborhood: Saket **Nearby cities** 1. [Luxury Ahmedabad Inn, Ahmedabad](link) - Price per night: ₹2450.96 - Guest rating: 4.5/5 - Amenities: Free Wi-Fi, Restaurant, Spa, Parking, Swimming Pool, Laundry Service - Neighborhood: CG Road 2. [The Ahmedabad Residency, Ahmedabad](link) - Price per night: ₹9278.69 - Guest rating: 3.2/5 - Amenities: Room Service, Conference Room, Swimming Pool, Bar, Restaurant - Neighborhood: Satellite 3. [Luxury Ahmedabad Palace, Ahmedabad](link) - Price per night: ₹11028.44 - Guest rating: 5/5 - Amenities: Airport Shuttle, Room Service, Business Center, Breakfast Included, Swimming Pool, Conference Room, Laundry Service - Neighborhood: Satellite 4. [Comfort Chennai Plaza, Chennai](link) - Price per night: ₹9773.18 - Guest rating: 5/5 - Amenities: Swimming Pool, Spa, Parking, Laundry Service, Restaurant, Room Service - Neighborhood: Mylapore Please let me know if you would like more details on any of these options or if you have different criteria for your search.
[ ]
================================ Human Message ================================= give me pune hotels ================================== Ai Message ================================== Name: hotel_assistant Here are some hotels in Pune: 1. [Hotel Pune Resort, Baner](link) - Price per night: ₹10486.14 - Guest rating: 3.9/5 - Amenities: Restaurant, Conference Room, Laundry Service, Swimming Pool, Bar, Parking, Business Center - Neighborhood: Baner 2. [Luxury Pune Plaza, Baner](link) - Price per night: ₹3236.25 - Guest rating: 4.7/5 - Amenities: Breakfast Included, Business Center, Laundry Service, Spa - Neighborhood: Baner 3. [The Pune Hotel, Hinjewadi](link) - Price per night: ₹11987.88 - Guest rating: 4.8/5 - Amenities: Concierge, Fitness Center, Parking, Bar, Business Center, Conference Room - Neighborhood: Hinjewadi 4. [Luxury Pune Resort, Viman Nagar](link) - Price per night: ₹6429.43 - Guest rating: 3.8/5 - Amenities: Conference Room, Laundry Service, Concierge - Neighborhood: Viman Nagar 5. [Grand Pune Resort, Baner](link) - Price per night: ₹11043.21 - Guest rating: 3.7/5 - Amenities: Free Wi-Fi, Conference Room, Breakfast Included, Swimming Pool - Neighborhood: Baner Please let me know if you would like more details on any of these options or if you have different criteria for your search.
[ ]
================================ Human Message ================================= now check flights from pune to delhi ================================= Tool Message ================================= Name: transfer_to_flight_assistant Successfully transferred to flight_assistant ================================== Ai Message ================================== Name: flight_assistant I found some flights from Pune to Delhi for you: 1. Flight SP992 by SpiceJet - Departure: 21:45 - Duration: 2h 00m - Price: ₹6563.82 - Seats Left: 66 - Class: Economy Would you like to proceed with this flight or see more options?