Skip to content

Commit

Permalink
docs: Optimize notebook (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Jan 29, 2025
1 parent 86a1ff8 commit cedb330
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions examples/how-tos/multi-agent-multi-turn-convo-functional.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "aa4bdbff-9461-46cc-aee9-8a22d3c3d9ec",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -233,19 +233,29 @@
"}, async (messages: BaseMessageLike[]) => { \n",
" let callActiveAgent = callTravelAdvisor;\n",
" let agentMessages: BaseMessage[];\n",
" let currentMessages = messages;\n",
" while (true) {\n",
" agentMessages = await callActiveAgent(messages);\n",
" messages = addMessages(messages, agentMessages);\n",
" agentMessages = await callActiveAgent(currentMessages);\n",
" \n",
" // Find the last AI message\n",
" // If one of the handoff tools is called, the last message returned\n",
" // by the agent will be a ToolMessage because we set them to have\n",
" // by the agent will be a ToolMessages because we set them to have\n",
" // \"returnDirect: true\". This means that the last AIMessage will\n",
" // have tool calls.\n",
" // Otherwise, the last returned message will be an AIMessage with\n",
" // no tool calls, which means we are ready for new input.\n",
" const aiMsg = [...agentMessages].reverse()\n",
" .find((m): m is AIMessage => m.getType() === \"ai\");\n",
" const reversedMessages = [...agentMessages].reverse();\n",
" const aiMsgIndex = reversedMessages\n",
" .findIndex((m): m is AIMessage => m.getType() === \"ai\");\n",
" \n",
" const aiMsg: AIMessage = reversedMessages[aiMsgIndex];\n",
" \n",
" // We append all messages up to the last AI message to the current messages.\n",
" // This may include ToolMessages (if the handoff tool was called)\n",
" const messagesToAdd = reversedMessages.slice(0, aiMsgIndex + 1).reverse();\n",
"\n",
" // Add the agent's responses\n",
" currentMessages = addMessages(currentMessages, messagesToAdd);\n",
"\n",
" if (!aiMsg?.tool_calls?.length) {\n",
" const userInput = await interrupt(\"Ready for user input.\");\n",
Expand All @@ -255,7 +265,7 @@
" if (userInput.toLowerCase() === \"done\") {\n",
" break;\n",
" }\n",
" messages = addMessages(messages, [{\n",
" currentMessages = addMessages(currentMessages, [{\n",
" role: \"human\",\n",
" content: userInput,\n",
" }]);\n",
Expand All @@ -274,7 +284,7 @@
"\n",
" return entrypoint.final({\n",
" value: agentMessages[agentMessages.length - 1],\n",
" save: messages,\n",
" save: currentMessages,\n",
" });\n",
"});"
]
Expand Down Expand Up @@ -316,16 +326,17 @@
" }\n",
"]\n",
"\n",
"callTravelAdvisor: Based on the recommendations, Aruba would be an excellent choice for your Caribbean getaway! Aruba is known as \"One Happy Island\" and offers:\n",
"- Consistently warm weather year-round with very little rainfall\n",
"- Beautiful white sand beaches like Eagle Beach and Palm Beach\n",
"- Crystal clear waters perfect for swimming and snorkeling\n",
"- A mix of luxury resorts and boutique hotels\n",
"- Diverse dining options and vibrant nightlife\n",
"- Safe and tourist-friendly environment\n",
"- Great shopping and cultural experiences\n",
"callTravelAdvisor: Based on the recommendations, Turks and Caicos would be an excellent choice for your Caribbean getaway! This British Overseas Territory is known for its stunning white-sand beaches, crystal-clear turquoise waters, and year-round warm weather. Grace Bay Beach in Providenciales is consistently rated as one of the world's best beaches.\n",
"\n",
"Would you like me to help you find suitable accommodations in Aruba? I can connect you with our hotel advisor who can recommend specific hotels based on your preferences.\n",
"You can enjoy:\n",
"- World-class snorkeling and diving\n",
"- Luxury resorts and spas\n",
"- Fresh seafood cuisine\n",
"- Water sports like kayaking and paddleboarding\n",
"- Beautiful coral reefs\n",
"- Average temperatures between 75-85°F (24-29°C) year-round\n",
"\n",
"Would you like me to connect you with our hotel advisor to help you find the perfect place to stay in Turks and Caicos?\n",
"\n",
"--- Conversation Turn 2 ---\n",
"\n",
Expand All @@ -334,21 +345,13 @@
" \"goto\": []\n",
"}\n",
"\n",
"callHotelAdvisor: Based on the recommendations, I can highlight two excellent options in different areas:\n",
"callHotelAdvisor: I can recommend two excellent options in Turks and Caicos:\n",
"\n",
"1. The Ritz-Carlton in Palm Beach: \n",
"- Located in the high-rise hotel district of Palm Beach\n",
"- This area is known for its vibrant atmosphere, numerous restaurants, and shopping\n",
"- Perfect for those who want to be in the heart of the action\n",
"- Palm Beach is one of Aruba's most popular beaches with calm waters\n",
"1. Grace Bay Club - This luxury resort is located on the world-famous Grace Bay Beach in Providenciales (often called \"Provo\"). This area is the most developed and popular island in Turks and Caicos, known for its 12-mile stretch of pristine beach, excellent restaurants, and shopping. The resort offers all-oceanfront suites and is perfect if you want to be close to amenities while enjoying luxury beachfront accommodations.\n",
"\n",
"2. Bucuti & Tara Beach Resort in Eagle Beach:\n",
"- Located on Eagle Beach, known as one of the best beaches in the Caribbean\n",
"- This area is more laid-back and less crowded than Palm Beach\n",
"- Perfect for those seeking a more serene, romantic atmosphere\n",
"- Eagle Beach is wider and more pristine than Palm Beach\n",
"2. COMO Parrot Cay - This is an exclusive private island resort located on Parrot Cay, a secluded island accessible by boat from Providenciales. This is the ultimate luxury escape if you're looking for privacy and seclusion. The resort is set on 1,000 unspoiled acres with pristine white beaches. This location is perfect for those who want to truly get away from it all while enjoying world-class service and amenities.\n",
"\n",
"Would you like more specific information about either of these areas or hotels?\n",
"Would you like more specific information about either of these properties or their locations?\n",
"\n",
"--- Conversation Turn 3 ---\n",
"\n",
Expand All @@ -357,16 +360,31 @@
" \"goto\": []\n",
"}\n",
"\n",
"callTravelAdvisor: While connecting you with the travel advisor, here are some popular activities near the Ritz-Carlton in Palm Beach that you might enjoy:\n",
"callHotelAdvisor: Grace Bay Club is perfectly situated to enjoy many activities in Providenciales! Since the hotel is located on Grace Bay Beach in Provo, here are some excellent activities nearby:\n",
"\n",
"1. Beach Activities (right at your doorstep):\n",
"- Swimming and sunbathing on Grace Bay Beach\n",
"- Snorkeling right off the beach\n",
"- Beach walks along the pristine 12-mile stretch\n",
"\n",
"2. Within Walking Distance:\n",
"- Salt Mills Plaza (shopping center with local boutiques and restaurants)\n",
"- Graceway Gourmet (upscale grocery store)\n",
"- Several beachfront restaurants and bars\n",
"\n",
"3. Very Close By (5-10 minute drive):\n",
"- Princess Alexandra National Park (great for snorkeling)\n",
"- Leeward Marina (for boat tours and fishing trips)\n",
"- Provo Golf Club (18-hole championship golf course)\n",
"- Thursday Night Fish Fry at Bight Park (local culture and food)\n",
"\n",
"1. Paseo Herencia Mall - A beautiful open-air shopping center within walking distance\n",
"2. Stellaris Casino - Connected to the Ritz-Carlton\n",
"3. Water Sports at Palm Beach - Including jet skiing, parasailing, and sailing\n",
"4. The Palm Beach Strip - Known for restaurants, bars, and nightlife\n",
"5. The California Lighthouse - A short drive away with spectacular views\n",
"6. Bubali Bird Sanctuary - Great for nature lovers\n",
"4. Water Activities (operators will pick you up):\n",
"- Snorkeling or diving trips to the barrier reef\n",
"- Sunset sailing cruises\n",
"- Half-day trips to Iguana Island\n",
"- Whale watching (in season - January to April)\n",
"\n",
"Would you like specific details about any of these activities or would you like to explore other options in the area?\n"
"Would you like me to connect you with our travel advisor for more specific activity recommendations or help with booking any excursions?\n"
]
}
],
Expand Down

0 comments on commit cedb330

Please sign in to comment.