旅行规划#

在这个例子中,我们将使用 AgentChat 创建一个复杂的旅行规划系统的过程。我们的旅行规划器将利用多个 AI 代理,每个代理都有特定的角色,协作创建全面的旅行行程。

首先,让我们导入必要的模块。

from autogen_agentchat.agents import CodingAssistantAgent
from autogen_agentchat.task import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient

定义代理#

在下一节中,我们将定义将在旅行规划团队中使用的代理。

model_client = OpenAIChatCompletionClient(
    model="gpt-4o",
    temperature=1,
    api_key="sk-", # Optional if you have an OPENAI_API_KEY env variable set.
)

planner_agent = CodingAssistantAgent(
    "planner_agent",
    model_client=model_client,
    description="A helpful assistant that can plan trips.",
    system_message="You are a helpful assistant that can suggest a travel plan for a user based on their request.",
)

local_agent = CodingAssistantAgent(
    "local_agent",
    model_client=model_client,
    description="A local assistant that can suggest local activities or places to visit.",
    system_message="You are a helpful assistant that can suggest authentic and interesting local activities or places to visit for a user and can utilize any context information provided.",
)

language_agent = CodingAssistantAgent(
    "language_agent",
    model_client=model_client,
    description="A helpful assistant that can provide language tips for a given destination.",
    system_message="You are a helpful assistant that can review travel plans, providing feedback on important/critical tips about how best to address language or communication challenges for the given destination. If the plan already includes language tips, you can mention that the plan is satisfactory, with rationale.",
)

travel_summary_agent = CodingAssistantAgent(
    "travel_summary_agent",
    model_client=model_client,
    description="A helpful assistant that can summarize the travel plan.",
    system_message="You are a helpful assistant that can take in all of the suggestions and advice from the other agents and provide a detailed tfinal travel plan. You must ensure th b at the final plan is integrated and complete. YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN. When the plan is complete and all perspectives are integrated, you can respond with TERMINATE.",
)
termination = TextMentionTermination("TERMINATE")
group_chat = RoundRobinGroupChat(
    [planner_agent, local_agent, language_agent, travel_summary_agent], termination_condition=termination
)
result = await group_chat.run(task="Plan a 3 day trip to Nepal.")
print(result)
TaskResult(messages=[TextMessage(source='user', models_usage=None, content='Plan a 3 day trip to Nepal.'), TextMessage(source='planner_agent', models_usage=RequestUsage(prompt_tokens=40, completion_tokens=679), content='Planning a 3-day trip to Nepal can be an exciting adventure, as the country offers a rich tapestry of culture, history, and natural beauty. Here’s a suggested itinerary that covers some highlights:\n\n### Day 1: Kathmandu\n\n**Morning:**\n- **Pashupatinath Temple**: Start your day by visiting the sacred Hindu temple complex of Pashupatinath, located on the banks of the Bagmati River. It’s a UNESCO World Heritage Site and offers a fascinating insight into Nepalese culture and traditions.\n- **Boudhanath Stupa**: Head to Boudhanath, one of the largest stupas in Nepal. Walk around the stupa, spin the prayer wheels, and enjoy the peaceful ambiance.\n\n**Afternoon:**\n- **Swayambhunath (Monkey Temple)**: Visit this ancient religious complex atop a hill in the Kathmandu Valley. Enjoy panoramic views of the city and observe the diverse architectural styles and intricate carvings.\n\n**Evening:**\n- **Thamel**: Explore the bustling streets of Thamel, Kathmandu’s tourist hub. Shop for souvenirs, enjoy local cuisine at one of the restaurants, and experience the vibrant nightlife.\n\n### Day 2: Patan and Bhaktapur\n\n**Morning:**\n- **Patan Durbar Square**: Start your day exploring Patan (Lalitpur), known for its rich cultural heritage and impressive Newari architecture. Visit Patan Durbar Square and its array of temples and the Patan Museum.\n\n**Afternoon:**\n- **Bhaktapur Durbar Square**: Head to Bhaktapur, another UNESCO World Heritage Site. Wander through its well-preserved medieval streets and visit attractions such as the 55-Window Palace, Nyatapola Temple, and Dattatreya Temple.\n\n**Evening:**\n- **Local Cuisine**: Try traditional Newari dishes at a local restaurant in Bhaktapur. Don’t miss out on the famous “king curd” or “Juju Dhau.”\n\n### Day 3: Nagarkot\n\n**Morning:**\n- **Travel to Nagarkot**: An early morning drive to Nagarkot, about 1–2 hours from Kathmandu, known for its stunning sunrise views over the Himalayas, including Mount Everest on a clear day.\n\n**Daytime:**\n- **Hiking and Trekking**: Enjoy hiking the trails around Nagarkot. There are several options, such as the hike to Changu Narayan, another ancient temple and UNESCO World Heritage Site.\n\n**Afternoon:**\n- **Leisure and Relaxation**: Relax in your hotel or guesthouse, enjoying the serene environment and stunning mountain vistas.\n\n**Evening:**\n- **Sunset View**: Conclude your trip by witnessing a breathtaking sunset over the Himalayas before heading back to Kathmandu.\n\n### Additional Tips:\n- **Travel Insurance**: Ensure you have adequate travel insurance before your trip.\n- **Local Transport**: Consider hiring a local guide or driver for convenience and to make the most of your time.\n- **Cultural Sensitivity**: Respect local customs, especially in temples and religious sites where modest clothing is expected.\n\nThis itinerary provides a taste of the diverse experiences Nepal has to offer. Adjustments can be made based on your preferences, fitness level, and interest areas. Enjoy your trip!'), TextMessage(source='local_agent', models_usage=RequestUsage(prompt_tokens=735, completion_tokens=551), content='For a 3-day trip to Nepal, the itinerary suggested offers a comprehensive experience of both cultural and natural wonders. Here\'s how you can enjoy your short visit:\n\n### Day 1: Discover Kathmandu\n\n**Morning:**\n- **Pashupatinath Temple**: Begin your journey with a visit to one of the most sacred Hindu shrines. Observe the rituals and ceremonies by the Bagmati River.\n- **Boudhanath Stupa**: Explore the spiritual heart of Kathmandu, with its immense stupa and vibrant prayer flags.\n\n**Afternoon:**\n- **Swayambhunath (Monkey Temple)**: Ascend the steps to this iconic site for panoramic city views. The blend of Hindu and Buddhist symbolism here is captivating.\n\n**Evening:**\n- **Explore Thamel**: Dive into the lively streets filled with shops, eateries, and cultural vibes. Sample some local dishes or shop for souvenirs.\n\n### Day 2: Cultural Heritage in Patan and Bhaktapur\n\n**Morning:**\n- **Patan Durbar Square**: Discover the artistry and architecture of the Newars as you visit Patan\'s historical square and museum.\n\n**Afternoon:**\n- **Bhaktapur Durbar Square**: Wander through this well-preserved medieval city. Don\'t miss the intricacies of the Nyatapola Temple and the richness of the local culture.\n\n**Evening:**\n- **Taste Newari Cuisine**: Enjoy a sumptuous dinner in Bhaktapur, including "Juju Dhau," the celebrated yogurt.\n\n### Day 3: Natural Retreat in Nagarkot\n\n**Morning:**\n- **Sunrise in Nagarkot**: Depart early to catch the sunrise, with potential views of the distant Himalayas.\n\n**Daytime:**\n- **Trekking and Nature Walks**: Spend your day exploring the trails around Nagarkot. A trek to Changu Narayan provides both exercise and cultural enrichment.\n\n**Afternoon:**\n- **Relaxation and Scenic Views**: Unwind at your accommodation or explore more on foot, soaking in the serene landscapes.\n\n**Evening:**\n- **Sunset View and Return**: Cap off your day with a sunset view before making your way back to Kathmandu for your departure.\n\n### Practical Advice:\n- **Accommodation**: Consider staying in centrally located hotels for easy access to attractions.\n- **Transport**: Hire a private vehicle or guide for comfort and local insights.\n- **Cultural Respect**: Dress modestly, adhere to local customs, and be respectful during temple visits.\n\nThis itinerary provides a balanced snapshot of Nepal’s cultural heritage and natural beauty, making the most of your brief stay. Enjoy your adventure amidst the cultural and natural richness of Nepal!'), TextMessage(source='language_agent', models_usage=RequestUsage(prompt_tokens=1317, completion_tokens=295), content="The travel plan for your 3-day trip to Nepal is well-structured, covering both the cultural sites of Kathmandu and its surroundings, as well as the natural beauty of Nagarkot. Here are a few language and communication tips to complement your journey:\n\n1. **Language Basics**: While many people in Nepal speak English, especially in tourist areas, knowing a few phrases in Nepali can enrich your experience:\n   - **Namaste** (Hello)\n   - **Dhanyavaad** (Thank you)\n   - **Maaph garnus** (Sorry/Excuse me)\n   - **Kati ho?** (How much is it?)\n\n2. **Guides and Signage**: Most major sites in Kathmandu will have English-speaking guides and bilingual signage. Hiring a local guide can provide deeper insights and assist with any language barriers.\n\n3. **Apps and Translation Tools**: Consider downloading a translation app on your phone to help with communication in areas where English might not be as commonly spoken. This can be particularly useful in more remote places like Nagarkot.\n\n4. **Politeness and Gestures**: Even if you're not proficient in the language, a smile and polite gestures go a long way. Nepalese people are generally welcoming and will appreciate your effort to engage in their language.\n\nOverall, your plan provides a great balance of cultural immersion and natural exploration. These language tips should further enhance your experience in Nepal. Enjoy your trip!"), TextMessage(source='travel_summary_agent', models_usage=RequestUsage(prompt_tokens=1636, completion_tokens=771), content='Here\'s a complete and detail-rich 3-day travel plan for your journey to Nepal, integrating cultural exploration, natural beauty, helpful travel advice, and essential language tips.\n\n### Day 1: Kathmandu - Cultural Immersion\n\n**Morning:**\n- **Pashupatinath Temple**: Begin your cultural journey by visiting the sacred Pashupatinath Temple. Observe the Hindu religious practices and engage with the spiritual atmosphere along the Bagmati River.\n  \n- **Boudhanath Stupa**: Spend some time walking around the massive stupa, taking in the sights of prayer flags and the smell of incense. Join other pilgrims in spinning the prayer wheels and enjoy the peace.\n\n**Afternoon:**\n- **Swayambhunath (Monkey Temple)**: Climb the steps to this iconic site. You\'ll be rewarded with stunning panoramic views of Kathmandu and a closer look at its Buddhist and Hindu symbols.\n\n**Evening:**\n- **Thamel**: Wander through Thamel\'s vibrant streets. Engage in some shopping, enjoy traditional Nepali food, like momos or dal bhat, at local eateries, and soak in the lively atmosphere.\n\n### Day 2: Explore Historic Patan and Bhaktapur\n\n**Morning:**\n- **Patan Durbar Square**: Explore the beautiful Patan Durbar Square, a testament to the Newar architectural prowess. Visit the Patan Museum, housed in a beautiful palace, for insights into Nepalese art.\n\n**Afternoon:**\n- **Bhaktapur Durbar Square**: Revel in the medieval charm as you explore Bhaktapur, renowned for its well-preserved heritage. The 55-Window Palace and Nyatapola Temple are must-see landmarks.\n\n**Evening:**\n- **Newari Cuisine**: Dine on authentic Newari food in Bhaktapur. Make sure to try "Juju Dhau," the legendary sweetened yogurt, known as the "king curd."\n\n### Day 3: Nature\'s Retreat in Nagarkot\n\n**Early Morning:**\n- **Nagarkot Sunrise**: Set out early for Nagarkot to witness one of the most stunning sunrises over the Himalayan range. On clear days, Mount Everest can be seen in the distance.\n\n**Daytime:**\n- **Hiking to Changu Narayan**: Engage in a scenic hike to the ancient Changu Narayan Temple, another UNESCO World Heritage Site, traveling through rural landscapes and local villages.\n\n**Afternoon:**\n- **Relaxation**: Rest at your hotel or guesthouse, enjoying the tranquil mountain air and views. \n\n**Evening:**\n- **Sunset and Return**: Witness the sunset before you return to Kathmandu, concluding your enriching trip.\n\n### Practical Travel Advice:\n- **Accommodation**: Stay at centrally located hotels in Kathmandu and cozy guesthouses in Nagarkot.\n- **Transport**: Consider hiring a local driver or guide for seamless travel and insights.\n- **Cultural Etiquette**: Dress modestly in religious sites and respect local customs, showing gratitude with a simple "Dhanyavaad" (Thank you).\n\n### Language Tips to Enhance Your Experience:\n- Learn basic Nepali phrases for more authentic interactions: \n  - **Namaste** (Hello)\n  - **Dhanyavaad** (Thank you)\n  - **Maaph garnus** (Excuse me/Sorry)\n  - **Yo kati ho?** (How much is this?)\n\n- Use translation apps for less common interactions and rely on gestures and smiles to bridge language gaps, reflecting the warmth of the Nepalese people.\n\nThis comprehensive plan ensures you get a well-rounded experience of Nepal\'s vibrant culture and serene nature within your short visit. Enjoy your adventure and embrace the unique spirit of Nepal! \n\n**TERMINATE**')], stop_reason="Text 'TERMINATE' mentioned")