Skip to content

Commit

Permalink
travel planning example with autogen and sambanova
Browse files Browse the repository at this point in the history
  • Loading branch information
snova-rodrigom committed Jan 18, 2025
1 parent b9543c1 commit ff3efa1
Showing 1 changed file with 169 additions and 0 deletions.
169 changes: 169 additions & 0 deletions integrations/autogen/travel-planning.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<picture>\n",
"<a href=\"https://sambanova.ai/\"\\>\n",
"<source media=\"(prefers-color-scheme: dark)\" srcset=\"../../images/SambaNova-light-logo-1.png\" height=\"60\">\n",
"<img alt=\"SambaNova logo\" src=\"../../images/SambaNova-dark-logo-1.png\" height=\"60\">\n",
"</picture>\n",
"</a>\n",
"\n",
"# Travel Planning \n",
"\n",
"In this example, we'll walk through the process of creating a sophisticated travel planning system using [SambaNova Cloud](https://cloud.sambanova.ai/apis) and [Autogen AgentChats](https://microsoft.github.io/autogen/dev//user-guide/agentchat-user-guide/index.html). Our travel planner will utilize multiple AI agents, each with a specific role, to collaboratively create a comprehensive travel itinerary. \n",
"\n",
"First, let us import the necessary modules. Please, create a `.env` file and include `SAMBANOVA_URL` and `SAMBANOVA_API_KEY` after creating your [SambaNova Cloud API key](https://cloud.sambanova.ai/apis)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from autogen_agentchat.agents import AssistantAgent\n",
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"from dotenv import load_dotenv\n",
"load_dotenv('../../.env')\n",
"\n",
"import os\n",
"api_url = os.getenv(\"SAMBANOVA_URL\") # It has to be like this `https://api.sambanova.ai/v1`\n",
"api_key = os.getenv(\"SAMBANOVA_API_KEY\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Defining Agents \n",
"\n",
"In the next section we will define the agents that will be used in the travel planning team."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"planner_agent = AssistantAgent(\n",
" \"planner_agent\",\n",
" model_client=OpenAIChatCompletionClient(\n",
" model=\"Meta-Llama-3.1-70B-Instruct\", \n",
" base_url=api_url, \n",
" api_key=api_key, \n",
" model_info={\n",
" 'json_output': False, \n",
" 'function_calling': True, \n",
" 'family': 'unknown', \n",
" 'vision': False\n",
" }),\n",
" description=\"A helpful assistant that can plan trips.\",\n",
" system_message=\"You are a helpful assistant that can suggest a travel plan for a user based on their request.\",\n",
")\n",
"\n",
"local_agent = AssistantAgent(\n",
" \"local_agent\",\n",
" model_client=OpenAIChatCompletionClient(\n",
" model=\"Meta-Llama-3.1-70B-Instruct\", \n",
" base_url=api_url, \n",
" api_key=api_key, \n",
" model_info={\n",
" 'json_output': False, \n",
" 'function_calling': True, \n",
" 'family': 'unknown', \n",
" 'vision': False\n",
" }),\n",
" 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.\",\n",
")\n",
"\n",
"language_agent = AssistantAgent(\n",
" \"language_agent\",\n",
" model_client=OpenAIChatCompletionClient(\n",
" model=\"Meta-Llama-3.1-70B-Instruct\", \n",
" base_url=api_url, \n",
" api_key=api_key, \n",
" model_info={\n",
" 'json_output': False, \n",
" 'function_calling': True, \n",
" 'family': 'unknown', \n",
" 'vision': False\n",
" }),\n",
" description=\"A helpful assistant that can provide language tips for a given destination.\",\n",
" 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.\",\n",
")\n",
"\n",
"travel_summary_agent = AssistantAgent(\n",
" \"travel_summary_agent\",\n",
" model_client=OpenAIChatCompletionClient(\n",
" model=\"Meta-Llama-3.1-70B-Instruct\", \n",
" base_url=api_url, \n",
" api_key=api_key, \n",
" model_info={\n",
" 'json_output': False, \n",
" 'function_calling': True, \n",
" 'family': 'unknown', \n",
" 'vision': False\n",
" }),\n",
" description=\"A helpful assistant that can summarize the travel plan.\",\n",
" 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 final travel plan. You must ensure that 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.\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, we create our agents team and specify the task."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"termination = TextMentionTermination(\"TERMINATE\")\n",
"group_chat = RoundRobinGroupChat(\n",
" [planner_agent, local_agent, language_agent, travel_summary_agent], termination_condition=termination\n",
")\n",
"await Console(group_chat.run_stream(task=\"Plan a 3 day trip to Peru.\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "autogen_venv",
"language": "python",
"name": "autogen_venv"
},
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit ff3efa1

Please sign in to comment.