Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs update for PR #1 on Promptless/autogen-test #14

Open
wants to merge 17 commits into
base: frances/test_promptless_4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
" ToolUseAssistantAgent,\n",
")\n",
"from autogen_agentchat.base import Response\n",
"from autogen_agentchat.messages import ChatMessage, StopMessage, TextMessage\n",
"from autogen_agentchat.task import StopMessageTermination\n",
"from autogen_agentchat.messages import ChatMessage, TextMessage\n",
"from autogen_agentchat.task import TextMentionTermination\n",
"from autogen_agentchat.teams import SelectorGroupChat\n",
"from autogen_core.base import CancellationToken\n",
"from autogen_core.components.tools import FunctionTool\n",
Expand All @@ -59,7 +59,7 @@
"metadata": {},
"source": [
"## Defining Agents\n",
"The `UserProxyAgent` allows the user to input messages directly. This agent waits for user input and returns a text message or a stop message if the user decides to terminate the conversation."
"The `UserProxyAgent` allows the user to input messages directly. This agent waits for user input and returns a text message. If the user inputs \"TERMINATE\", the conversation is considered terminated."
]
},
{
Expand All @@ -74,11 +74,30 @@
"\n",
" @property\n",
" def produced_message_types(self) -> List[type[ChatMessage]]:\n",
" return [TextMessage, StopMessage]\n",
" return [TextMessage]\n",
"\n",
" async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:\n",
" user_input = await asyncio.get_event_loop().run_in_executor(None, input, \"Enter your response: \")\n",
" if \"TERMINATE\" in user_input:\n",
" return Response(chat_message=TextMessage(content=\"User has terminated the conversation.\", source=self.name))\n",
" return Response(chat_message=TextMessage(content=user_input, source=self.name))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"async def flight_search(start: str, destination: str, date: str) -> str:\n",
" return \"\\n\".join(\n",
" [\n",
" f\"AC24 from {start} to {destination} on {date} is $500\",\n"
]
}
]
}
" if \"TERMINATE\" in user_input:\n",
" return Response(chat_message=StopMessage(content=\"User has terminated the conversation.\", source=self.name))\n",
" return Response(chat_message=TextMessage(content=user_input, source=self.name))"
]
Expand Down Expand Up @@ -159,6 +178,18 @@
"Great choice! Toronto is a vibrant city with a lot to offer. Now, could you please provide the following additional details to help me assist you better?\n",
"\n",
"1. What are your travel dates (departure and return)?\n",
"\n",
"Once I have this information, I can help you find the best options!\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T20:35:59.701486], User:\u001b[0m\n",
"\n",
"Traveling to toronto from new york\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T20:36:02.325330], TravelAssistant:\u001b[0m\n",
"\n",
"Great choice! Toronto is a vibrant city with a lot to offer. Now, could you please provide the following additional details to help me assist you better?\n",
"\n",
"1. What are your travel dates (departure and return)?\n",
"2. How many travelers will be going, and what are their ages?\n",
"3. Do you have a budget for the flight and accommodations?\n",
"4. Are there any specific activities or attractions you’re interested in while in Toronto?\n",
Expand Down Expand Up @@ -215,6 +246,20 @@
" - **Date:** December 7, 2023\n",
"\n",
"- **Return:** Toronto to New York\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T20:36:45.875280], User:\u001b[0m\n",
"\n",
"that's it\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-08T20:36:50.925624], FlightBroker:\u001b[0m\n",
"\n",
"Your flights have been successfully booked! Here are the details:\n",
"\n",
"- **Departure:** New York to Toronto\n",
" - **Flight:** AL21\n",
" - **Date:** December 7, 2023\n",
"\n",
"- **Return:** Toronto to New York\n",
" - **Flight:** AL21\n",
" - **Date:** December 12, 2023\n",
"\n",
Expand All @@ -226,7 +271,48 @@
{
"data": {
"text/plain": [
"TeamRunResult(messages=[TextMessage(source='user', content='Help user plan a trip and book a flight.'), TextMessage(source='User', content=''), TextMessage(source='TravelAssistant', content=\"I'd be happy to help you plan your trip! To get started, could you please provide me with the following details:\\n\\n1. Your departure city and the destination city.\\n2. Your travel dates (departure and return).\\n3. The number of travelers and their ages (if any children are involved).\\n4. Your budget for flights and accommodations, if you have one in mind.\\n5. Any specific activities or attractions you're interested in at the destination.\\n\\nOnce I have this information, I can help you find the best options!\"), TextMessage(source='User', content='Traveling to toronto from new york'), TextMessage(source='TravelAssistant', content='Great choice! Toronto is a vibrant city with a lot to offer. Now, could you please provide the following additional details to help me assist you better?\\n\\n1. What are your travel dates (departure and return)?\\n2. How many travelers will be going, and what are their ages?\\n3. Do you have a budget for the flight and accommodations?\\n4. Are there any specific activities or attractions you’re interested in while in Toronto?\\n\\nOnce I have this information, I can help you find the best flights and suggestions for your trip!'), TextMessage(source='User', content='leaving on december 7 and returning on 12'), TextMessage(source='TravelAssistant', content=\"Thank you for the details! Here's what I have so far:\\n\\n- **Departure City:** New York\\n- **Destination City:** Toronto\\n- **Departure Date:** December 7\\n- **Return Date:** December 12\\n\\nNow, could you please provide:\\n\\n1. The number of travelers and their ages.\\n2. Your budget for flights and accommodations (if applicable).\\n3. Any specific activities or attractions you're interested in while in Toronto.\\n\\nThis will help me provide more tailored options for your trip!\"), TextMessage(source='User', content='just myself one adult'), TextMessage(source='FlightBroker', content=\"Thanks for the information! Here's what I have:\\n\\n- **Departure City:** New York\\n- **Destination City:** Toronto\\n- **Departure Date:** December 7\\n- **Return Date:** December 12\\n- **Number of Travelers:** 1 Adult\\n\\nCould you let me know if you have a budget for flights and accommodations? Additionally, are there any specific activities or attractions you're interested in while in Toronto? This will help me provide the best options for your trip!\"), TextMessage(source='User', content=\"that's it\"), StopMessage(source='FlightBroker', content='Your flights have been successfully booked! Here are the details:\\n\\n- **Departure:** New York to Toronto\\n - **Flight:** AL21\\n - **Date:** December 7, 2023\\n\\n- **Return:** Toronto to New York\\n - **Flight:** AL21\\n - **Date:** December 12, 2023\\n\\nIf you need help with accommodations, activities, or anything else for your trip, feel free to let me know! \\n\\nTERMINATE'), StopMessage(source='StopMessageTermination', content='Stop message received')])"
{
"data": {
"text/plain": [
"TeamRunResult(messages=[TextMessage(source='user', content='Help user plan a trip and book a flight.'), TextMessage(source='User', content=''), TextMessage(source='TravelAssistant', content=\"I'd be happy to help you plan your trip! To get started, could you please provide me with the following details:\\n\\n1. Your departure city and the destination city.\\n2. Your travel dates (departure and return).\\n3. The number of travelers and their ages (if any children are involved).\\n4. Your budget for flights and accommodations, if you have one in mind.\\n5. Any specific activities or attractions you're interested in at the destination.\\n\\nOnce I have this information, I can help you find the best options!\"), TextMessage(source='User', content='Traveling to toronto from new york'), TextMessage(source='TravelAssistant', content='Great choice! Toronto is a vibrant city with a lot to offer. Now, could you please provide the following additional details to help me assist you better?\\n\\n1. What are your travel dates (departure and return)?\\n2. How many travelers will be going, and what are their ages?\\n3. Do you have a budget for the flight and accommodations?\\n4. Are there any specific activities or attractions you’re interested in while in Toronto?\\n\\nOnce I have this information, I can help you find the best flights and suggestions for your trip!'), TextMessage(source='User', content='leaving on december 7 and returning on 12'), TextMessage(source='TravelAssistant', content=\"Thank you for the details! Here's what I have so far:\\n\\n- **Departure City:** New York\\n- **Destination City:** Toronto\\n- **Departure Date:** December 7\\n- **Return Date:** December 12\\n\\nNow, could you please provide:\\n\\n1. The number of travelers and their ages.\\n2. Your budget for flights and accommodations (if applicable).\\n3. Any specific activities or attractions you're interested in while in Toronto.\\n\\nThis will help me provide more tailored options for your trip!\"), TextMessage(source='User', content='just myself one adult'), TextMessage(source='FlightBroker', content=\"Thanks for the information! Here's what I have:\\n\\n- **Departure City:** New York\\n- **Destination City:** Toronto\\n- **Departure Date:** December 7\\n- **Return Date:** December 12\\n- **Number of Travelers:** 1 Adult\\n\\nCould you let me know if you have a budget for flights and accommodations? Additionally, are there any specific activities or attractions you're interested in while in Toronto? This will help me provide the best options for your trip!\"), TextMessage(source='User', content=\"that's it\"), TextMessage(source='FlightBroker', content='Your flights have been successfully booked! Here are the details:\\n\\n- **Departure:** New York to Toronto\\n - **Flight:** AL21\\n - **Date:** December 7, 2023\\n\\n- **Return:** Toronto to New York\\n - **Flight:** AL21\\n - **Date:** December 12, 2023\\n\\nIf you need help with accommodations, activities, or anything else for your trip, feel free to let me know! \\n\\nTERMINATE'), TextMessage(source='TextMentionTermination', content='Termination message received')])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
```
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "selector-group-chat",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"user_proxy = UserProxyAgent(\"User\")\n",
"flight_broker = ToolUseAssistantAgent(\n",
" \"FlightBroker\",\n",
" description=\"An assistant for booking flights\",\n",
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\"),\n",
" registered_tools=[\n",
" FunctionTool(flight_search, description=\"Search for flights\"),\n",
" FunctionTool(flight_booking, description=\"Book a flight\"),\n",
" ],\n",
")\n",
"travel_assistant = CodingAssistantAgent(\n",
" \"TravelAssistant\",\n",
" description=\"A travel assistant\",\n",
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\"),\n",
" system_message=\"You are a travel assistant.\",\n",
")\n",
"team = SelectorGroupChat(\n",
" [user_proxy, flight_broker, travel_assistant], model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\")\n",
")\n",
"await team.run(\"Help user plan a trip and book a flight.\", termination_condition=TextMentionTermination(\"TERMINATE\"))"
]
},
"execution_count": 4,
Expand Down Expand Up @@ -254,7 +340,7 @@
"team = SelectorGroupChat(\n",
" [user_proxy, flight_broker, travel_assistant], model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\")\n",
")\n",
"await team.run(\"Help user plan a trip and book a flight.\", termination_condition=StopMessageTermination())"
"await team.run(\"Help user plan a trip and book a flight.\", termination_condition=TextMentionTermination(\"TERMINATE\"))"
]
}
],
Expand All @@ -279,4 +365,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"from autogen_agentchat import EVENT_LOGGER_NAME\n",
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",
"from autogen_agentchat.logging import ConsoleLogHandler\n",
"from autogen_agentchat.task import MaxMessageTermination\n",
"from autogen_agentchat.task import MaxMessageTermination, TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat\n",
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
"from autogen_core.components.tools import FunctionTool\n",
Expand Down Expand Up @@ -75,6 +75,38 @@
"A team where agents take turns sending messages (in a round robin fashion) until a termination condition is met. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-20T09:01:04.692283]:\u001b[0m\n",
"\n",
"Write a Haiku about the weather in Paris\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-20T09:01:05.961670], tool_use_agent:\u001b[0m\n",
"\n",
"Golden sun above, \n"
]
}
],
"source": [
"team = RoundRobinGroupChat(participants=[writing_assistant_agent, tool_use_agent])\n",
"result = await team.run(\n",
" \"Write a Haiku about the weather in Paris\",\n",
" termination_condition=TextMentionTermination(\"TERMINATE\"),\n",
")\n",
"print(result)"
]
}
]
}
{
"cell_type": "code",
"execution_count": 2,
Expand Down Expand Up @@ -105,7 +137,7 @@
"source": [
"round_robin_team = RoundRobinGroupChat([tool_use_agent, writing_assistant_agent])\n",
"round_robin_team_result = await round_robin_team.run(\n",
" \"Write a Haiku about the weather in Paris\", termination_condition=MaxMessageTermination(max_messages=1)\n",
" \"Write a Haiku about the weather in Paris\", termination_condition=TextMentionTermination(\"TERMINATE\")\n",
")"
]
},
Expand All @@ -120,33 +152,11 @@
" code_executor_agent = CodeExecutorAgent(\n",
" \"code_executor\", code_executor=code_executor)\n",
" code_execution_team = RoundRobinGroupChat([writing_assistant_agent, code_executor_agent])\n",
" code_execution_team_result = await code_execution_team.run(\"Create a plot of NVDIA and TSLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png\", termination_condition=MaxMessageTermination(max_messages=12))\n",
" code_execution_team_result = await code_execution_team.run(\"Create a plot of NVDIA and TSLA stock returns YTD from 2024-01-01 and save it to 'nvidia_tesla_2024_ytd.png\", termination_condition=TextMentionTermination(\"TERMINATE\"))\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### SelectorGroupChat\n",
"\n",
"A team where a generative model (LLM) is used to select the next agent to send a message based on the current conversation history.\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-20T09:01:05.967894]:\u001b[0m\n",
"\n",
"What is the weather in paris right now? Also write a haiku about it.\n",
}
"What is the weather in paris right now? Also write a haiku about it.\n",
"--------------------------------------------------------------------------- \n",
"\u001b[91m[2024-10-20T09:01:07.214716], tool_use_agent:\u001b[0m\n",
"\n",
Expand Down Expand Up @@ -214,4 +224,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading