Team termination condition sets in the constructor (#4042)

* Termination condition as part of constructor

* Update doc

* Update notebooks
This commit is contained in:
Eric Zhu
2024-11-01 15:49:37 -07:00
committed by GitHub
parent 7d1857dae6
commit 4fec22ddc5
13 changed files with 134 additions and 97 deletions

View File

@@ -260,7 +260,8 @@
" system_message=\"You are a helpful assistant that can generate a comprehensive report on a given topic based on search and stock analysis. When you done with generating the report, reply with TERMINATE.\",\n",
")\n",
"\n",
"team = RoundRobinGroupChat([search_agent, stock_analysis_agent, report_agent])"
"termination = TextMentionTermination(\"TERMINATE\")\n",
"team = RoundRobinGroupChat([search_agent, stock_analysis_agent, report_agent], termination_condition=termination)"
]
},
{
@@ -400,9 +401,7 @@
}
],
"source": [
"result = await team.run(\n",
" \"Write a financial report on American airlines\", termination_condition=TextMentionTermination(\"TERMINATE\")\n",
")\n",
"result = await team.run(\"Write a financial report on American airlines\")\n",
"print(result)"
]
}
@@ -423,7 +422,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,

View File

@@ -328,11 +328,13 @@
" system_message=\"You are a helpful assistant. Your task is to synthesize data extracted into a high quality literature review including CORRECT references. You MUST write a final report that is formatted as a literature review with CORRECT references. Your response should end with the word 'TERMINATE'\",\n",
")\n",
"\n",
"team = RoundRobinGroupChat(participants=[google_search_agent, arxiv_search_agent, report_agent])\n",
"termination = TextMentionTermination(\"TERMINATE\")\n",
"team = RoundRobinGroupChat(\n",
" participants=[google_search_agent, arxiv_search_agent, report_agent], termination_condition=termination\n",
")\n",
"\n",
"result = await team.run(\n",
" task=\"Write a literature review on no code tools for building multi agent ai systems\",\n",
" termination_condition=TextMentionTermination(\"TERMINATE\"),\n",
")"
]
}
@@ -353,7 +355,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,

View File

@@ -194,10 +194,11 @@
}
],
"source": [
"group_chat = RoundRobinGroupChat([planner_agent, local_agent, language_agent, travel_summary_agent])\n",
"result = await group_chat.run(\n",
" task=\"Plan a 3 day trip to Nepal.\", termination_condition=TextMentionTermination(\"TERMINATE\")\n",
"termination = TextMentionTermination(\"TERMINATE\")\n",
"group_chat = RoundRobinGroupChat(\n",
" [planner_agent, local_agent, language_agent, travel_summary_agent], termination_condition=termination\n",
")\n",
"result = await group_chat.run(task=\"Plan a 3 day trip to Nepal.\")\n",
"print(result)"
]
}

View File

@@ -81,12 +81,10 @@
")\n",
"\n",
"# add the agent to a team\n",
"agent_team = RoundRobinGroupChat([weather_agent])\n",
"termination = MaxMessageTermination(max_messages=2)\n",
"agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n",
"# Note: if running in a Python file directly you'll need to use asyncio.run(agent_team.run(...)) instead of await agent_team.run(...)\n",
"result = await agent_team.run(\n",
" task=\"What is the weather in New York?\",\n",
" termination_condition=MaxMessageTermination(max_messages=2),\n",
")\n",
"result = await agent_team.run(task=\"What is the weather in New York?\")\n",
"print(\"\\n\", result)"
]
},
@@ -110,7 +108,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "agnext",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
@@ -124,7 +122,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.5"
}
},
"nbformat": 4,

View File

@@ -251,10 +251,14 @@
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\"),\n",
" system_message=\"You are a travel assistant.\",\n",
")\n",
"\n",
"termination = TextMentionTermination(\"TERMINATE\")\n",
"team = SelectorGroupChat(\n",
" [user_proxy, flight_broker, travel_assistant], model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\")\n",
" [user_proxy, flight_broker, travel_assistant],\n",
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\"),\n",
" termination_condition=termination,\n",
")\n",
"await team.run(\"Help user plan a trip and book a flight.\", termination_condition=TextMentionTermination(\"TERMINATE\"))"
"await team.run(\"Help user plan a trip and book a flight.\")"
]
}
],
@@ -274,7 +278,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,

View File

@@ -103,10 +103,9 @@
}
],
"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",
")"
"termination = MaxMessageTermination(max_messages=1)\n",
"round_robin_team = RoundRobinGroupChat([tool_use_agent, writing_assistant_agent], termination_condition=termination)\n",
"round_robin_team_result = await round_robin_team.run(\"Write a Haiku about the weather in Paris\")"
]
},
{
@@ -173,12 +172,12 @@
}
],
"source": [
"llm_team = SelectorGroupChat([tool_use_agent, writing_assistant_agent], model_client=model_client)\n",
"termination = MaxMessageTermination(max_messages=2)\n",
"llm_team = SelectorGroupChat(\n",
" [tool_use_agent, writing_assistant_agent], model_client=model_client, termination_condition=termination\n",
")\n",
"\n",
"llm_team_result = await llm_team.run(\n",
" \"What is the weather in paris right now? Also write a haiku about it.\",\n",
" termination_condition=MaxMessageTermination(max_messages=2),\n",
")"
"llm_team_result = await llm_team.run(\"What is the weather in paris right now? Also write a haiku about it.\")"
]
},
{
@@ -209,7 +208,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,

View File

@@ -56,9 +56,7 @@
" name=\"writing_assistant_agent\",\n",
" system_message=\"You are a helpful assistant that solve tasks by generating text responses and code.\",\n",
" model_client=model_client,\n",
")\n",
"\n",
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent])"
")"
]
},
{
@@ -110,10 +108,9 @@
}
],
"source": [
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent])\n",
"round_robin_team_result = await round_robin_team.run(\n",
" \"Write a unique, Haiku about the weather in Paris\", termination_condition=MaxMessageTermination(max_messages=3)\n",
")"
"max_msg_termination = MaxMessageTermination(max_messages=3)\n",
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent], termination_condition=max_msg_termination)\n",
"round_robin_team_result = await round_robin_team.run(\"Write a unique, Haiku about the weather in Paris\")"
]
},
{
@@ -174,12 +171,10 @@
" model_client=model_client,\n",
")\n",
"\n",
"text_termination = TextMentionTermination(\"TERMINATE\")\n",
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent], termination_condition=text_termination)\n",
"\n",
"round_robin_team = RoundRobinGroupChat([writing_assistant_agent])\n",
"\n",
"round_robin_team_result = await round_robin_team.run(\n",
" \"Write a unique, Haiku about the weather in Paris\", termination_condition=TextMentionTermination(\"TERMINATE\")\n",
")"
"round_robin_team_result = await round_robin_team.run(\"Write a unique, Haiku about the weather in Paris\")"
]
}
],
@@ -199,7 +194,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.11.5"
}
},
"nbformat": 4,