329 lines
20 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"from autogenstudio import AgentWorkFlowConfig, AutoGenWorkFlowManager"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## AutoGen Studio Agent Workflow API Example\n",
"\n",
"This notebook focuses on demonstrating capabilities of the autogen studio workflow python api. \n",
"\n",
"- Declarative Specification of an Agent Workflow \n",
"- Loading the specification and running the resulting agent\n",
"\n",
"\n",
"> Note: The notebook currently demonstrates support for a two agent setup. Support for GroupChat is currently in development."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"userproxy (to primary_assistant):\n",
"\n",
"What is the height of the Eiffel Tower?. Dont write code, just respond to the question.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"primary_assistant (to userproxy):\n",
"\n",
"The Eiffel Tower is approximately 300 meters tall, not including antennas. With antennas, it reaches a height of about 330 meters. TERMINATE\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
}
],
"source": [
"# load an agent specification in JSON\n",
"agent_spec = json.load(open(\"agent_spec.json\"))\n",
"\n",
"# Creat a An AutoGen Workflow Configuration from the agent specification\n",
"agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)\n",
"\n",
"# # Create a Workflow from the configuration\n",
"agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config)\n",
"\n",
"# # Run the workflow on a task\n",
"task_query = \"What is the height of the Eiffel Tower?. Dont write code, just respond to the question.\"\n",
"agent_work_flow.run(message=task_query)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'recipient': 'primary_assistant',\n",
" 'sender': 'userproxy',\n",
" 'message': {'content': 'What is the height of the Eiffel Tower?. Dont write code, just respond to the question.',\n",
" 'role': 'user'},\n",
" 'timestamp': '2024-01-02T21:38:35.131849'},\n",
" {'recipient': 'userproxy',\n",
" 'sender': 'primary_assistant',\n",
" 'message': {'content': 'The Eiffel Tower is approximately 300 meters tall, not including antennas. With antennas, it reaches a height of about 330 meters. TERMINATE',\n",
" 'role': 'user'},\n",
" 'timestamp': '2024-01-02T21:38:35.136795'}]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"agent_work_flow.agent_history"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Group Chat Agent"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"userproxy (to group_chat_manager):\n",
"\n",
"plan a two day trip to Maui hawaii\n",
"\n",
"--------------------------------------------------------------------------------\n",
"local_assistant (to group_chat_manager):\n",
"\n",
"To plan a two-day trip to Maui, Hawaii, we'll need to consider a variety of activities that allow you to experience the island's natural beauty, culture, and cuisine. Here's a suggested itinerary:\n",
"\n",
"**Day 1: Exploring the Natural Beauty of Maui**\n",
"\n",
"- **Morning:**\n",
" - Start your day with a sunrise visit to Haleakalā National Park. Witnessing the sunrise from the summit of Haleakalā is a breathtaking experience. Remember to make a reservation in advance as it's required for sunrise viewing.\n",
" - After the sunrise, take a short hike in the park to explore the unique volcanic landscapes.\n",
"\n",
"- **Afternoon:**\n",
" - Head to the town of Paia for lunch. Paia is known for its laid-back atmosphere and has several local restaurants where you can try Hawaiian specialties.\n",
" - Visit Ho'okipa Beach Park to watch windsurfers and surfers, or if you're adventurous, take a surf lesson.\n",
"\n",
"- **Evening:**\n",
" - Drive to Lahaina, a historic whaling village, and stroll along Front Street. Here you can shop for local crafts and art.\n",
" - Have dinner at a traditional Hawaiian luau, where you can enjoy local food, music, and dance.\n",
"\n",
"**Day 2: Cultural and Relaxation Experience**\n",
"\n",
"- **Morning:**\n",
" - Visit Iao Valley State Park to see the Iao Needle and learn about the historical significance of this area to Hawaiian culture.\n",
" - Explore the Maui Tropical Plantation and take a tram tour to learn about the island's agriculture and taste some fresh tropical fruits.\n",
"\n",
"- **Afternoon:**\n",
" - Relax at one of Maui's beautiful beaches, such as Ka'anapali Beach or Wailea Beach. Take the opportunity to snorkel and see the vibrant marine life.\n",
" - Consider a visit to a local farm or a coffee plantation to learn more about the local produce.\n",
"\n",
"- **Evening:**\n",
" - Enjoy a sunset dinner cruise off the coast of Maui for a memorable end to your trip. This is a great way to see the island from a different perspective and often includes entertainment.\n",
"\n",
"Remember to book accommodations in advance, rent a car for easier travel around the island, and check for any travel restrictions or requirements. Also, be respectful of the local environment and culture, and try to participate in activities that support the local economy and conservation efforts.\n",
"\n",
"This plan includes a mix of natural, cultural, and relaxation activities that should give you a well-rounded experience of Maui in two days. If you have specific interests or preferences, the itinerary can be adjusted accordingly.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"language_assistant (to group_chat_manager):\n",
"\n",
"Regarding language or communication challenges, Hawaii is a part of the United States, so the primary language spoken is English. However, the Hawaiian language is also an official language of the state, and you will likely encounter Hawaiian words and place names during your visit.\n",
"\n",
"Here are some tips to address potential language or communication challenges in Maui:\n",
"\n",
"1. **Learn Basic Hawaiian Phrases**: While not necessary, learning a few basic Hawaiian phrases can be a sign of respect for the local culture. For example:\n",
" - Aloha - Hello/Goodbye\n",
" - Mahalo - Thank you\n",
" - 'Aina - Land\n",
" - Kai - Sea\n",
"\n",
"2. **Use Translation Apps**: If you come across Hawaiian words or phrases that you don't understand, you can use translation apps on your smartphone to help you understand their meanings.\n",
"\n",
"3. **Cultural Understanding**: Take some time to learn about Hawaiian culture and customs before your trip. This will help you communicate more effectively and respectfully with locals.\n",
"\n",
"4. **Ask for Help**: If you're unsure about pronunciation or meaning, don't hesitate to ask locals. People in Hawaii are generally friendly and willing to help.\n",
"\n",
"5. **Be Patient and Respectful**: Always be patient and respectful in your interactions. Remember that you are a guest in Hawaii, and showing respect for the local culture and language is important.\n",
"\n",
"Your travel plan should include these language tips to ensure smooth communication during your trip. If your plan already includes these tips, then it is satisfactory. If not, consider incorporating them to enhance your travel experience.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"primary_assistant (to group_chat_manager):\n",
"\n",
"Based on the suggestions from the local and language assistants, here is the complete two-day travel itinerary for Maui, Hawaii:\n",
"\n",
"**Day 1: Exploring the Natural Beauty of Maui**\n",
"\n",
"- **Morning:**\n",
" - Experience the sunrise at Haleakalā National Park (make a reservation in advance).\n",
" - Enjoy a short hike in the park to see the volcanic landscapes.\n",
"\n",
"- **Afternoon:**\n",
" - Have lunch in Paia and enjoy Hawaiian specialties.\n",
" - Visit Ho'okipa Beach Park for surfing or to watch the surfers.\n",
"\n",
"- **Evening:**\n",
" - Explore Lahaina and shop along Front Street.\n",
" - Attend a traditional Hawaiian luau for dinner with music and dance.\n",
"\n",
"**Day 2: Cultural and Relaxation Experience**\n",
"\n",
"- **Morning:**\n",
" - Visit Iao Valley State Park to see the Iao Needle.\n",
" - Take a tram tour at Maui Tropical Plantation and taste fresh tropical fruits.\n",
"\n",
"- **Afternoon:**\n",
" - Relax at Ka'anapali Beach or Wailea Beach and go snorkeling.\n",
" - Optionally, visit a local farm or coffee plantation.\n",
"\n",
"- **Evening:**\n",
" - Enjoy a sunset dinner cruise with entertainment.\n",
"\n",
"**Language and Communication Tips:**\n",
"\n",
"- Learn basic Hawaiian phrases such as \"Aloha\" (Hello/Goodbye) and \"Mahalo\" (Thank you).\n",
"- Use translation apps for any unfamiliar Hawaiian words or phrases.\n",
"- Educate yourself about Hawaiian culture and customs to communicate respectfully.\n",
"- Ask locals for help if you're unsure about pronunciation or meaning.\n",
"- Be patient and respectful in all interactions, honoring local culture and language.\n",
"\n",
"**Additional Travel Tips:**\n",
"\n",
"- Book accommodations and a car rental in advance.\n",
"- Check for any travel restrictions or requirements.\n",
"- Support local economy and conservation efforts.\n",
"- Be mindful of the environment and cultural sites.\n",
"\n",
"This itinerary provides a balanced mix of activities that showcase Maui's natural beauty, culture, and opportunities for relaxation. Remember to be respectful of the local environment and culture, and enjoy your two-day adventure in Maui, Hawaii.\n",
"\n",
"TERMINATE\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
}
],
"source": [
"# load an agent specification in JSON\n",
"agent_spec = json.load(open(\"groupchat_spec.json\"))\n",
"\n",
"# Creat a An AutoGen Workflow Configuration from the agent specification\n",
"agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)\n",
"\n",
"# Create a Workflow from the configuration\n",
"group_agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config)\n",
"\n",
"# Run the workflow on a task\n",
"task_query = \"plan a two day trip to Maui hawaii\"\n",
"group_agent_work_flow.run(message=task_query)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4 agent messages were involved in the conversation\n"
]
},
{
"data": {
"text/plain": [
"[{'recipient': 'local_assistant',\n",
" 'sender': 'group_chat_manager',\n",
" 'message': {'content': 'plan a two day trip to Maui hawaii',\n",
" 'name': 'userproxy',\n",
" 'role': 'user'},\n",
" 'timestamp': '2024-01-02T21:38:42.433093'},\n",
" {'recipient': 'language_assistant',\n",
" 'sender': 'group_chat_manager',\n",
" 'message': {'content': \"To plan a two-day trip to Maui, Hawaii, we'll need to consider a variety of activities that allow you to experience the island's natural beauty, culture, and cuisine. Here's a suggested itinerary:\\n\\n**Day 1: Exploring the Natural Beauty of Maui**\\n\\n- **Morning:**\\n - Start your day with a sunrise visit to Haleakalā National Park. Witnessing the sunrise from the summit of Haleakalā is a breathtaking experience. Remember to make a reservation in advance as it's required for sunrise viewing.\\n - After the sunrise, take a short hike in the park to explore the unique volcanic landscapes.\\n\\n- **Afternoon:**\\n - Head to the town of Paia for lunch. Paia is known for its laid-back atmosphere and has several local restaurants where you can try Hawaiian specialties.\\n - Visit Ho'okipa Beach Park to watch windsurfers and surfers, or if you're adventurous, take a surf lesson.\\n\\n- **Evening:**\\n - Drive to Lahaina, a historic whaling village, and stroll along Front Street. Here you can shop for local crafts and art.\\n - Have dinner at a traditional Hawaiian luau, where you can enjoy local food, music, and dance.\\n\\n**Day 2: Cultural and Relaxation Experience**\\n\\n- **Morning:**\\n - Visit Iao Valley State Park to see the Iao Needle and learn about the historical significance of this area to Hawaiian culture.\\n - Explore the Maui Tropical Plantation and take a tram tour to learn about the island's agriculture and taste some fresh tropical fruits.\\n\\n- **Afternoon:**\\n - Relax at one of Maui's beautiful beaches, such as Ka'anapali Beach or Wailea Beach. Take the opportunity to snorkel and see the vibrant marine life.\\n - Consider a visit to a local farm or a coffee plantation to learn more about the local produce.\\n\\n- **Evening:**\\n - Enjoy a sunset dinner cruise off the coast of Maui for a memorable end to your trip. This is a great way to see the island from a different perspective and often includes entertainment.\\n\\nRemember to book accommodations in advance, rent a car for easier travel around the island, and check for any travel restrictions or requirements. Also, be respectful of the local environment and culture, and try to participate in activities that support the local economy and conservation efforts.\\n\\nThis plan includes a mix of natural, cultural, and relaxation activities that should give you a well-rounded experience of Maui in two days. If you have specific interests or preferences, the itinerary can be adjusted accordingly.\",\n",
" 'name': 'local_assistant',\n",
" 'role': 'user'},\n",
" 'timestamp': '2024-01-02T21:39:33.989518'},\n",
" {'recipient': 'primary_assistant',\n",
" 'sender': 'group_chat_manager',\n",
" 'message': {'content': \"Regarding language or communication challenges, Hawaii is a part of the United States, so the primary language spoken is English. However, the Hawaiian language is also an official language of the state, and you will likely encounter Hawaiian words and place names during your visit.\\n\\nHere are some tips to address potential language or communication challenges in Maui:\\n\\n1. **Learn Basic Hawaiian Phrases**: While not necessary, learning a few basic Hawaiian phrases can be a sign of respect for the local culture. For example:\\n - Aloha - Hello/Goodbye\\n - Mahalo - Thank you\\n - 'Aina - Land\\n - Kai - Sea\\n\\n2. **Use Translation Apps**: If you come across Hawaiian words or phrases that you don't understand, you can use translation apps on your smartphone to help you understand their meanings.\\n\\n3. **Cultural Understanding**: Take some time to learn about Hawaiian culture and customs before your trip. This will help you communicate more effectively and respectfully with locals.\\n\\n4. **Ask for Help**: If you're unsure about pronunciation or meaning, don't hesitate to ask locals. People in Hawaii are generally friendly and willing to help.\\n\\n5. **Be Patient and Respectful**: Always be patient and respectful in your interactions. Remember that you are a guest in Hawaii, and showing respect for the local culture and language is important.\\n\\nYour travel plan should include these language tips to ensure smooth communication during your trip. If your plan already includes these tips, then it is satisfactory. If not, consider incorporating them to enhance your travel experience.\",\n",
" 'name': 'language_assistant',\n",
" 'role': 'user'},\n",
" 'timestamp': '2024-01-02T21:39:58.874159'},\n",
" {'recipient': 'primary_assistant',\n",
" 'sender': 'group_chat_manager',\n",
" 'message': {'content': 'Based on the suggestions from the local and language assistants, here is the complete two-day travel itinerary for Maui, Hawaii:\\n\\n**Day 1: Exploring the Natural Beauty of Maui**\\n\\n- **Morning:**\\n - Experience the sunrise at Haleakalā National Park (make a reservation in advance).\\n - Enjoy a short hike in the park to see the volcanic landscapes.\\n\\n- **Afternoon:**\\n - Have lunch in Paia and enjoy Hawaiian specialties.\\n - Visit Ho\\'okipa Beach Park for surfing or to watch the surfers.\\n\\n- **Evening:**\\n - Explore Lahaina and shop along Front Street.\\n - Attend a traditional Hawaiian luau for dinner with music and dance.\\n\\n**Day 2: Cultural and Relaxation Experience**\\n\\n- **Morning:**\\n - Visit Iao Valley State Park to see the Iao Needle.\\n - Take a tram tour at Maui Tropical Plantation and taste fresh tropical fruits.\\n\\n- **Afternoon:**\\n - Relax at Ka\\'anapali Beach or Wailea Beach and go snorkeling.\\n - Optionally, visit a local farm or coffee plantation.\\n\\n- **Evening:**\\n - Enjoy a sunset dinner cruise with entertainment.\\n\\n**Language and Communication Tips:**\\n\\n- Learn basic Hawaiian phrases such as \"Aloha\" (Hello/Goodbye) and \"Mahalo\" (Thank you).\\n- Use translation apps for any unfamiliar Hawaiian words or phrases.\\n- Educate yourself about Hawaiian culture and customs to communicate respectfully.\\n- Ask locals for help if you\\'re unsure about pronunciation or meaning.\\n- Be patient and respectful in all interactions, honoring local culture and language.\\n\\n**Additional Travel Tips:**\\n\\n- Book accommodations and a car rental in advance.\\n- Check for any travel restrictions or requirements.\\n- Support local economy and conservation efforts.\\n- Be mindful of the environment and cultural sites.\\n\\nThis itinerary provides a balanced mix of activities that showcase Maui\\'s natural beauty, culture, and opportunities for relaxation. Remember to be respectful of the local environment and culture, and enjoy your two-day adventure in Maui, Hawaii.\\n\\nTERMINATE',\n",
" 'role': 'assistant'},\n",
" 'timestamp': '2024-01-02T21:40:30.240153'}]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(len(group_agent_work_flow.agent_history), \"agent messages were involved in the conversation\")\n",
"group_agent_work_flow.agent_history"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "coral",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}