mirror of https://github.com/microsoft/autogen.git
290 lines
27 KiB
Plaintext
290 lines
27 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"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 Team\n",
|
|
"- Loading the specification and running the resulting agent\n",
|
|
"\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/Users/victordibia/projects/hax/autogen/python/packages/autogen-core/src/autogen_core/_component_config.py:252: UserWarning: \n",
|
|
"⚠️ SECURITY WARNING ⚠️\n",
|
|
"Loading a FunctionTool from config will execute code to import the provided global imports and and function code.\n",
|
|
"Only load configs from TRUSTED sources to prevent arbitrary code execution.\n",
|
|
" instance = component_class._from_config(validated_config) # type: ignore\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"task_result=TaskResult(messages=[TextMessage(source='user', models_usage=None, metadata={}, content='What is the weather in New York?', type='TextMessage'), TextMessage(source='assistant_agent', models_usage=RequestUsage(prompt_tokens=86, completion_tokens=47), metadata={}, content=\"I'm unable to provide real-time weather information. I recommend checking a reliable weather website or app for the current weather in New York. If you have any other questions or need assistance with a different topic, feel free to ask!\", type='TextMessage'), TextMessage(source='assistant_agent', models_usage=RequestUsage(prompt_tokens=138, completion_tokens=5), metadata={}, content='TERMINATE', type='TextMessage')], stop_reason=\"Text 'TERMINATE' mentioned\") usage='' duration=1.734266996383667\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from autogenstudio.teammanager import TeamManager\n",
|
|
"\n",
|
|
"wm = TeamManager()\n",
|
|
"result = await wm.run(task=\"What is the weather in New York?\", team_config=\"team.json\")\n",
|
|
"print(result)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"source='user' models_usage=None metadata={} content='What is the weather in New York?' type='TextMessage'\n",
|
|
"source='assistant_agent' models_usage=RequestUsage(prompt_tokens=86, completion_tokens=34) metadata={} content=\"I currently don't have access to real-time weather data. You can check a reliable weather website or application for the most current information about the weather in New York.\" type='TextMessage'\n",
|
|
"source='llm_call_event' models_usage=None metadata={} content='{\"type\": \"LLMCall\", \"messages\": [{\"content\": \"You are a helpful assistant. Solve tasks carefully. When done, say TERMINATE.\", \"role\": \"system\"}, {\"content\": \"What is the weather in New York?\", \"role\": \"user\", \"name\": \"user\"}], \"response\": {\"id\": \"chatcmpl-B76eHFx8OqWQlbnNaK3W6CJtuznmR\", \"choices\": [{\"finish_reason\": \"stop\", \"index\": 0, \"logprobs\": null, \"message\": {\"content\": \"I currently don\\'t have access to real-time weather data. You can check a reliable weather website or application for the most current information about the weather in New York.\", \"refusal\": null, \"role\": \"assistant\", \"audio\": null, \"function_call\": null, \"tool_calls\": null}}], \"created\": 1741033553, \"model\": \"gpt-4o-mini-2024-07-18\", \"object\": \"chat.completion\", \"service_tier\": \"default\", \"system_fingerprint\": \"fp_06737a9306\", \"usage\": {\"completion_tokens\": 34, \"prompt_tokens\": 86, \"total_tokens\": 120, \"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}}}, \"prompt_tokens\": 86, \"completion_tokens\": 34, \"agent_id\": \"assistant_agent/3db465b4-fb0a-4ffd-80df-f4554605d4c0\"}'\n",
|
|
"source='assistant_agent' models_usage=RequestUsage(prompt_tokens=125, completion_tokens=5) metadata={} content='TERMINATE' type='TextMessage'\n",
|
|
"source='llm_call_event' models_usage=None metadata={} content='{\"type\": \"LLMCall\", \"messages\": [{\"content\": \"You are a helpful assistant. Solve tasks carefully. When done, say TERMINATE.\", \"role\": \"system\"}, {\"content\": \"What is the weather in New York?\", \"role\": \"user\", \"name\": \"user\"}, {\"content\": \"I currently don\\'t have access to real-time weather data. You can check a reliable weather website or application for the most current information about the weather in New York.\", \"role\": \"assistant\", \"name\": \"assistant_agent\"}], \"response\": {\"id\": \"chatcmpl-B76eIpGDvd7M2nxdgezZuRzOJTQR1\", \"choices\": [{\"finish_reason\": \"stop\", \"index\": 0, \"logprobs\": null, \"message\": {\"content\": \"TERMINATE\", \"refusal\": null, \"role\": \"assistant\", \"audio\": null, \"function_call\": null, \"tool_calls\": null}}], \"created\": 1741033554, \"model\": \"gpt-4o-mini-2024-07-18\", \"object\": \"chat.completion\", \"service_tier\": \"default\", \"system_fingerprint\": \"fp_06737a9306\", \"usage\": {\"completion_tokens\": 5, \"prompt_tokens\": 125, \"total_tokens\": 130, \"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}}}, \"prompt_tokens\": 125, \"completion_tokens\": 5, \"agent_id\": \"assistant_agent/3db465b4-fb0a-4ffd-80df-f4554605d4c0\"}'\n",
|
|
"task_result=TaskResult(messages=[TextMessage(source='user', models_usage=None, metadata={}, content='What is the weather in New York?', type='TextMessage'), TextMessage(source='assistant_agent', models_usage=RequestUsage(prompt_tokens=86, completion_tokens=34), metadata={}, content=\"I currently don't have access to real-time weather data. You can check a reliable weather website or application for the most current information about the weather in New York.\", type='TextMessage'), TextMessage(source='assistant_agent', models_usage=RequestUsage(prompt_tokens=125, completion_tokens=5), metadata={}, content='TERMINATE', type='TextMessage')], stop_reason=\"Text 'TERMINATE' mentioned\") usage='' duration=1.1263680458068848\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"result_stream = wm.run_stream(task=\"What is the weather in New York?\", team_config=\"team.json\")\n",
|
|
"async for response in result_stream:\n",
|
|
" print(response)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Load Directly Using the AgentChat API "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[<autogen_agentchat.agents._assistant_agent.AssistantAgent object at 0x1219d3850>]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json \n",
|
|
"from autogen_agentchat.teams import BaseGroupChat\n",
|
|
"team_config = json.load(open(\"team.json\")) \n",
|
|
"team = BaseGroupChat.load_component(team_config)\n",
|
|
"print(team._participants)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## AutoGen Studio Database API\n",
|
|
"\n",
|
|
"Api for creating objects and serializing to a database."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[32m2025-03-03 12:36:12.391\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mautogenstudio.database.db_manager\u001b[0m:\u001b[36minitialize_database\u001b[0m:\u001b[36m61\u001b[0m - \u001b[1mCreating database tables...\u001b[0m\n",
|
|
"\u001b[32m2025-03-03 12:36:12.425\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mautogenstudio.database.schema_manager\u001b[0m:\u001b[36m_initialize_alembic\u001b[0m:\u001b[36m154\u001b[0m - \u001b[1mAlembic initialization complete\u001b[0m\n",
|
|
"INFO [alembic.runtime.migration] Context impl SQLiteImpl.\n",
|
|
"INFO [alembic.runtime.migration] Will assume non-transactional DDL.\n",
|
|
"INFO [alembic.autogenerate.compare] Detected type change from NUMERIC() to UUID() on 'message.run_id'\n",
|
|
"INFO [alembic.autogenerate.compare] Detected type change from NUMERIC() to UUID() on 'run.id'\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Response(message='Database initialized successfully', status=True, data=None)"
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"from autogenstudio.database import DatabaseManager\n",
|
|
"import os\n",
|
|
"# delete database\n",
|
|
"# if os.path.exists(\"test.db\"):\n",
|
|
"# os.remove(\"test.db\")\n",
|
|
"\n",
|
|
"os.makedirs(\"test\", exist_ok=True)\n",
|
|
"# create a database\n",
|
|
"dbmanager = DatabaseManager(engine_uri=\"sqlite:///test.db\", base_dir=\"test\")\n",
|
|
"dbmanager.initialize_database()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Sample AgentChat Example (Python)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from autogen_agentchat.agents import AssistantAgent\n",
|
|
"from autogen_agentchat.conditions import TextMentionTermination, MaxMessageTermination\n",
|
|
"from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat\n",
|
|
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
|
|
"\n",
|
|
"planner_agent = AssistantAgent(\n",
|
|
" \"planner_agent\",\n",
|
|
" model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\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. Respond with a single sentence\",\n",
|
|
")\n",
|
|
"\n",
|
|
"local_agent = AssistantAgent(\n",
|
|
" \"local_agent\",\n",
|
|
" model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",
|
|
" description=\"A local assistant that can suggest local activities or places to visit.\",\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. Respond with a single sentence\",\n",
|
|
")\n",
|
|
"\n",
|
|
"language_agent = AssistantAgent(\n",
|
|
" \"language_agent\",\n",
|
|
" model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\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.Respond with a single sentence\",\n",
|
|
")\n",
|
|
"\n",
|
|
"travel_summary_agent = AssistantAgent(\n",
|
|
" \"travel_summary_agent\",\n",
|
|
" model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\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 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.Respond with a single sentence\",\n",
|
|
")\n",
|
|
"\n",
|
|
"termination = TextMentionTermination(\"TERMINATE\") | MaxMessageTermination(10)\n",
|
|
"group_chat = RoundRobinGroupChat(\n",
|
|
" [planner_agent, local_agent, language_agent, travel_summary_agent], termination_condition=termination\n",
|
|
")\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"source='user' models_usage=None metadata={} content='Plan a 3 day trip to Nepal.' type='TextMessage'\n",
|
|
"source='planner_agent' models_usage=RequestUsage(prompt_tokens=45, completion_tokens=64) metadata={} content='Sure, on your 3-day trip to Nepal, you could start by visiting historical landmarks and local markets in Kathmandu, hike for a day in the Annapurna region to experience breathtaking mountain views and end your trip by exploring the religious sites and wildlife in Lumbini and Chitwan respectively.' type='TextMessage'\n",
|
|
"source='local_agent' models_usage=RequestUsage(prompt_tokens=125, completion_tokens=86) metadata={} content=\"Absolutely, on the first day, feel free to explore Kathmandu's rich history and culture, visit temples like Swayambhunath and Pashupatinath. On the second day, take a spectacular mountain flight to view Mount Everest and then head to Pokhara to engage in adventure activities or relax by Phewa Lake. On the third day, explore the biodiversity at Chitwan National Park.\" type='TextMessage'\n",
|
|
"source='language_agent' models_usage=RequestUsage(prompt_tokens=241, completion_tokens=72) metadata={} content=\"While going through your itinerary, I don't see any specific strategies for dealing with language barriers. For Nepal, whilst Nepali is the most widely spoken language, English is understood by many, especially in urban areas and by those working in the travel and hospitality sectors. Carrying a phrasebook or using a translator app could be helpful in more rural areas.\" type='TextMessage'\n",
|
|
"source='travel_summary_agent' models_usage=RequestUsage(prompt_tokens=336, completion_tokens=220) metadata={} content=\"Your 3-day trip to Nepal is as follows:\\n\\nDay 1: Begin in Kathmandu, exploring the city's rich history and culture. Visit temples such as Swayambhunath and Pashupatinath. Immerse yourself in local markets to experience the vibrant local life.\\n\\nDay 2: As an early bird, embark on a spectacular mountain flight to witness Mount Everest's grandeur, followed by a trip to Pokhara. In Pokhara, you have the opportunity to partake in thrilling adventure activities or unwind by the serene Phewa Lake.\\n\\nDay 3: Dedicate your last day to exploring the biodiversity at Chitwan National Park, which offers an enchanting wildlife experience.\\n\\nLanguage considerations: While a substantial number of people in urban Nepal understand and communicate in English, particularly those in the tourism sector, having a phrasebook or using a translator app can be beneficial in rural regions.\\n\\nThis comprehensive plan ensures that you will enjoy the diversity of cultural, scenic, and wildlife experiences that Nepal has to offer in a short period. TERMINATE.\" type='TextMessage'\n",
|
|
"TaskResult(messages=[TextMessage(source='user', models_usage=None, metadata={}, content='Plan a 3 day trip to Nepal.', type='TextMessage'), TextMessage(source='planner_agent', models_usage=RequestUsage(prompt_tokens=45, completion_tokens=64), metadata={}, content='Sure, on your 3-day trip to Nepal, you could start by visiting historical landmarks and local markets in Kathmandu, hike for a day in the Annapurna region to experience breathtaking mountain views and end your trip by exploring the religious sites and wildlife in Lumbini and Chitwan respectively.', type='TextMessage'), TextMessage(source='local_agent', models_usage=RequestUsage(prompt_tokens=125, completion_tokens=86), metadata={}, content=\"Absolutely, on the first day, feel free to explore Kathmandu's rich history and culture, visit temples like Swayambhunath and Pashupatinath. On the second day, take a spectacular mountain flight to view Mount Everest and then head to Pokhara to engage in adventure activities or relax by Phewa Lake. On the third day, explore the biodiversity at Chitwan National Park.\", type='TextMessage'), TextMessage(source='language_agent', models_usage=RequestUsage(prompt_tokens=241, completion_tokens=72), metadata={}, content=\"While going through your itinerary, I don't see any specific strategies for dealing with language barriers. For Nepal, whilst Nepali is the most widely spoken language, English is understood by many, especially in urban areas and by those working in the travel and hospitality sectors. Carrying a phrasebook or using a translator app could be helpful in more rural areas.\", type='TextMessage'), TextMessage(source='travel_summary_agent', models_usage=RequestUsage(prompt_tokens=336, completion_tokens=220), metadata={}, content=\"Your 3-day trip to Nepal is as follows:\\n\\nDay 1: Begin in Kathmandu, exploring the city's rich history and culture. Visit temples such as Swayambhunath and Pashupatinath. Immerse yourself in local markets to experience the vibrant local life.\\n\\nDay 2: As an early bird, embark on a spectacular mountain flight to witness Mount Everest's grandeur, followed by a trip to Pokhara. In Pokhara, you have the opportunity to partake in thrilling adventure activities or unwind by the serene Phewa Lake.\\n\\nDay 3: Dedicate your last day to exploring the biodiversity at Chitwan National Park, which offers an enchanting wildlife experience.\\n\\nLanguage considerations: While a substantial number of people in urban Nepal understand and communicate in English, particularly those in the tourism sector, having a phrasebook or using a translator app can be beneficial in rural regions.\\n\\nThis comprehensive plan ensures that you will enjoy the diversity of cultural, scenic, and wildlife experiences that Nepal has to offer in a short period. TERMINATE.\", type='TextMessage')], stop_reason=\"Text 'TERMINATE' mentioned\")\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"result = group_chat.run_stream(task=\"Plan a 3 day trip to Nepal.\")\n",
|
|
"async for response in result:\n",
|
|
" print(response)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"source='user' models_usage=None metadata={} content='Plan a 3 day trip to Nepal.' type='TextMessage'\n",
|
|
"source='planner_agent' models_usage=RequestUsage(prompt_tokens=45, completion_tokens=74) metadata={} content='For a 3-day trip to Nepal, start your journey in Kathmandu, visit renowned UNESCO World Heritage Sites including Pashupatinath Temple and Boudhanath Stupa, day two explore the breathtaking city of Pokhara, and on the final day, hike the serene trails of Nagarkot to witness a captivating sunrise over the Himalayas.' type='TextMessage'\n",
|
|
"source='local_agent' models_usage=RequestUsage(prompt_tokens=135, completion_tokens=57) metadata={} content='Immerse yourself in the local lifestyle by visiting the bustling markets of Kathmandu, explore the ancient, history-rich city of Bhaktapur, take a day hike to the breathtaking monasteries in the mountains and wrap it up with an unforgettable traditional Nepalese dinner.' type='TextMessage'\n",
|
|
"source='language_agent' models_usage=RequestUsage(prompt_tokens=222, completion_tokens=34) metadata={} content='Consider packing a helpful language guide or translator app to communicate effectively with locals in Nepal since the primary language there is Nepali and not everyone might be fluent in English.' type='TextMessage'\n",
|
|
"source='travel_summary_agent' models_usage=RequestUsage(prompt_tokens=279, completion_tokens=207) metadata={} content='Your final travel plan for a 3-day trip to Nepal is as follows:\\n\\nDay 1: Arrive in Kathmandu, immerse yourself in the local lifestyle by visiting the bustling markets, Pashupatinath Temple, and Boudhanath Stupa, all renowned UNESCO World Heritage Sites.\\n\\nDay 2: Explore the breathtaking city of Pokhara and the ancient, history-rich city of Bhaktapur. \\n\\nDay 3: Hike the serene trails of Nagarkot to witness a captivating sunrise over the Himalayas, take a day hike to the breathtaking monasteries in the mountains.\\n\\nThroughout your journey, engage with locals and enjoy a traditional Nepalese dinner. As the primary language in Nepal is Nepali, consider packing a helpful language guide or translator app to communicate effectively.\\n\\nEnsure your plan is flexible to accommodate for any unexpected changes or opportunities that present themselves while exploring the wonders of Nepal, remembering that the essence of travel is to appreciate the journey as much as the destination.\\n\\nTERMINATE' type='TextMessage'\n",
|
|
"TaskResult(messages=[TextMessage(source='user', models_usage=None, metadata={}, content='Plan a 3 day trip to Nepal.', type='TextMessage'), TextMessage(source='planner_agent', models_usage=RequestUsage(prompt_tokens=45, completion_tokens=74), metadata={}, content='For a 3-day trip to Nepal, start your journey in Kathmandu, visit renowned UNESCO World Heritage Sites including Pashupatinath Temple and Boudhanath Stupa, day two explore the breathtaking city of Pokhara, and on the final day, hike the serene trails of Nagarkot to witness a captivating sunrise over the Himalayas.', type='TextMessage'), TextMessage(source='local_agent', models_usage=RequestUsage(prompt_tokens=135, completion_tokens=57), metadata={}, content='Immerse yourself in the local lifestyle by visiting the bustling markets of Kathmandu, explore the ancient, history-rich city of Bhaktapur, take a day hike to the breathtaking monasteries in the mountains and wrap it up with an unforgettable traditional Nepalese dinner.', type='TextMessage'), TextMessage(source='language_agent', models_usage=RequestUsage(prompt_tokens=222, completion_tokens=34), metadata={}, content='Consider packing a helpful language guide or translator app to communicate effectively with locals in Nepal since the primary language there is Nepali and not everyone might be fluent in English.', type='TextMessage'), TextMessage(source='travel_summary_agent', models_usage=RequestUsage(prompt_tokens=279, completion_tokens=207), metadata={}, content='Your final travel plan for a 3-day trip to Nepal is as follows:\\n\\nDay 1: Arrive in Kathmandu, immerse yourself in the local lifestyle by visiting the bustling markets, Pashupatinath Temple, and Boudhanath Stupa, all renowned UNESCO World Heritage Sites.\\n\\nDay 2: Explore the breathtaking city of Pokhara and the ancient, history-rich city of Bhaktapur. \\n\\nDay 3: Hike the serene trails of Nagarkot to witness a captivating sunrise over the Himalayas, take a day hike to the breathtaking monasteries in the mountains.\\n\\nThroughout your journey, engage with locals and enjoy a traditional Nepalese dinner. As the primary language in Nepal is Nepali, consider packing a helpful language guide or translator app to communicate effectively.\\n\\nEnsure your plan is flexible to accommodate for any unexpected changes or opportunities that present themselves while exploring the wonders of Nepal, remembering that the essence of travel is to appreciate the journey as much as the destination.\\n\\nTERMINATE', type='TextMessage')], stop_reason=\"Text 'TERMINATE' mentioned\")\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"# convert to config \n",
|
|
"config = group_chat.dump_component().model_dump()\n",
|
|
"# save as json \n",
|
|
"\n",
|
|
"with open(\"travel_team.json\", \"w\") as f:\n",
|
|
" json.dump(config, f, indent=4)\n",
|
|
"\n",
|
|
"# load from json\n",
|
|
"with open(\"travel_team.json\", \"r\") as f:\n",
|
|
" config = json.load(f)\n",
|
|
"\n",
|
|
"group_chat = RoundRobinGroupChat.load_component(config) \n",
|
|
"result = group_chat.run_stream(task=\"Plan a 3 day trip to Nepal.\") \n",
|
|
"async for response in result:\n",
|
|
" print(response)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "agnext",
|
|
"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.9"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|