mirror of https://github.com/microsoft/autogen.git
Team termination condition sets in the constructor (#4042)
* Termination condition as part of constructor * Update doc * Update notebooks
This commit is contained in:
parent
7d1857dae6
commit
4fec22ddc5
|
@ -33,5 +33,5 @@ class TaskRunner(Protocol):
|
|||
cancellation_token: CancellationToken | None = None,
|
||||
) -> AsyncGenerator[InnerMessage | ChatMessage | TaskResult, None]:
|
||||
"""Run the task and produces a stream of messages and the final result
|
||||
as the last item in the stream."""
|
||||
:class:`TaskResult` as the last item in the stream."""
|
||||
...
|
||||
|
|
|
@ -33,6 +33,7 @@ class BaseGroupChat(Team, ABC):
|
|||
self,
|
||||
participants: List[ChatAgent],
|
||||
group_chat_manager_class: type[BaseGroupChatManager],
|
||||
termination_condition: TerminationCondition | None = None,
|
||||
):
|
||||
if len(participants) == 0:
|
||||
raise ValueError("At least one participant is required.")
|
||||
|
@ -41,6 +42,7 @@ class BaseGroupChat(Team, ABC):
|
|||
self._participants = participants
|
||||
self._team_id = str(uuid.uuid4())
|
||||
self._base_group_chat_manager_class = group_chat_manager_class
|
||||
self._termination_condition = termination_condition
|
||||
|
||||
@abstractmethod
|
||||
def _create_group_chat_manager_factory(
|
||||
|
@ -72,12 +74,12 @@ class BaseGroupChat(Team, ABC):
|
|||
task: str,
|
||||
*,
|
||||
cancellation_token: CancellationToken | None = None,
|
||||
termination_condition: TerminationCondition | None = None,
|
||||
) -> TaskResult:
|
||||
"""Run the team and return the result. The base implementation uses
|
||||
:meth:`run_stream` to run the team and then returns the final result."""
|
||||
async for message in self.run_stream(
|
||||
task, cancellation_token=cancellation_token, termination_condition=termination_condition
|
||||
task,
|
||||
cancellation_token=cancellation_token,
|
||||
):
|
||||
if isinstance(message, TaskResult):
|
||||
return message
|
||||
|
@ -88,10 +90,9 @@ class BaseGroupChat(Team, ABC):
|
|||
task: str,
|
||||
*,
|
||||
cancellation_token: CancellationToken | None = None,
|
||||
termination_condition: TerminationCondition | None = None,
|
||||
) -> AsyncGenerator[InnerMessage | ChatMessage | TaskResult, None]:
|
||||
"""Run the team and produces a stream of messages and the final result
|
||||
as the last item in the stream."""
|
||||
of the type :class:`TaskResult` as the last item in the stream."""
|
||||
# Create the runtime.
|
||||
runtime = SingleThreadedAgentRuntime()
|
||||
|
||||
|
@ -131,7 +132,7 @@ class BaseGroupChat(Team, ABC):
|
|||
group_topic_type=group_topic_type,
|
||||
participant_topic_types=participant_topic_types,
|
||||
participant_descriptions=participant_descriptions,
|
||||
termination_condition=termination_condition,
|
||||
termination_condition=self._termination_condition,
|
||||
),
|
||||
)
|
||||
# Add subscriptions for the group chat manager.
|
||||
|
|
|
@ -50,7 +50,8 @@ class RoundRobinGroupChat(BaseGroupChat):
|
|||
|
||||
Args:
|
||||
participants (List[BaseChatAgent]): The participants in the group chat.
|
||||
tools (List[Tool], optional): The tools to use in the group chat. Defaults to None.
|
||||
termination_condition (TerminationCondition, optional): The termination condition for the group chat. Defaults to None.
|
||||
Without a termination condition, the group chat will run indefinitely.
|
||||
|
||||
Raises:
|
||||
ValueError: If no participants are provided or if participant names are not unique.
|
||||
|
@ -65,7 +66,7 @@ class RoundRobinGroupChat(BaseGroupChat):
|
|||
from autogen_ext.models import OpenAIChatCompletionClient
|
||||
from autogen_agentchat.agents import AssistantAgent
|
||||
from autogen_agentchat.teams import RoundRobinGroupChat
|
||||
from autogen_agentchat.task import StopMessageTermination
|
||||
from autogen_agentchat.task import TextMentionTermination
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
@ -79,8 +80,9 @@ class RoundRobinGroupChat(BaseGroupChat):
|
|||
model_client=model_client,
|
||||
tools=[get_weather],
|
||||
)
|
||||
team = RoundRobinGroupChat([assistant])
|
||||
stream = team.run_stream("What's the weather in New York?", termination_condition=StopMessageTermination())
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = RoundRobinGroupChat([assistant], termination_condition=termination)
|
||||
stream = team.run_stream("What's the weather in New York?")
|
||||
async for message in stream:
|
||||
print(message)
|
||||
|
||||
|
@ -95,7 +97,7 @@ class RoundRobinGroupChat(BaseGroupChat):
|
|||
from autogen_ext.models import OpenAIChatCompletionClient
|
||||
from autogen_agentchat.agents import AssistantAgent
|
||||
from autogen_agentchat.teams import RoundRobinGroupChat
|
||||
from autogen_agentchat.task import StopMessageTermination
|
||||
from autogen_agentchat.task import TextMentionTermination
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
@ -103,8 +105,9 @@ class RoundRobinGroupChat(BaseGroupChat):
|
|||
|
||||
agent1 = AssistantAgent("Assistant1", model_client=model_client)
|
||||
agent2 = AssistantAgent("Assistant2", model_client=model_client)
|
||||
team = RoundRobinGroupChat([agent1, agent2])
|
||||
stream = team.run_stream("Tell me some jokes.", termination_condition=StopMessageTermination())
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = RoundRobinGroupChat([agent1, agent2], termination_condition=termination)
|
||||
stream = team.run_stream("Tell me some jokes.")
|
||||
async for message in stream:
|
||||
print(message)
|
||||
|
||||
|
@ -112,10 +115,13 @@ class RoundRobinGroupChat(BaseGroupChat):
|
|||
asyncio.run(main())
|
||||
"""
|
||||
|
||||
def __init__(self, participants: List[ChatAgent]):
|
||||
def __init__(
|
||||
self, participants: List[ChatAgent], termination_condition: TerminationCondition | None = None
|
||||
) -> None:
|
||||
super().__init__(
|
||||
participants,
|
||||
group_chat_manager_class=RoundRobinGroupChatManager,
|
||||
termination_condition=termination_condition,
|
||||
)
|
||||
|
||||
def _create_group_chat_manager_factory(
|
||||
|
|
|
@ -169,6 +169,8 @@ class SelectorGroupChat(BaseGroupChat):
|
|||
must have unique names and at least two participants.
|
||||
model_client (ChatCompletionClient): The ChatCompletion model client used
|
||||
to select the next speaker.
|
||||
termination_condition (TerminationCondition, optional): The termination condition for the group chat. Defaults to None.
|
||||
Without a termination condition, the group chat will run indefinitely.
|
||||
selector_prompt (str, optional): The prompt template to use for selecting the next speaker.
|
||||
Must contain '{roles}', '{participants}', and '{history}' to be filled in.
|
||||
allow_repeated_speaker (bool, optional): Whether to allow the same speaker to be selected
|
||||
|
@ -187,10 +189,11 @@ class SelectorGroupChat(BaseGroupChat):
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
import asyncio
|
||||
from autogen_ext.models import OpenAIChatCompletionClient
|
||||
from autogen_agentchat.agents import AssistantAgent
|
||||
from autogen_agentchat.teams import SelectorGroupChat
|
||||
from autogen_agentchat.task import StopMessageTermination
|
||||
from autogen_agentchat.task import TextMentionTermination
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
@ -223,20 +226,24 @@ class SelectorGroupChat(BaseGroupChat):
|
|||
tools=[lookup_flight],
|
||||
description="Helps with flight booking.",
|
||||
)
|
||||
team = SelectorGroupChat([travel_advisor, hotel_agent, flight_agent], model_client=model_client)
|
||||
stream = team.run_stream("Book a 3-day trip to new york.", termination_condition=StopMessageTermination())
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = SelectorGroupChat(
|
||||
[travel_advisor, hotel_agent, flight_agent],
|
||||
model_client=model_client,
|
||||
termination_condition=termination,
|
||||
)
|
||||
stream = team.run_stream("Book a 3-day trip to new york.")
|
||||
async for message in stream:
|
||||
print(message)
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
A team with a custom selector function:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import asyncio
|
||||
from autogen_ext.models import OpenAIChatCompletionClient
|
||||
from autogen_agentchat.agents import AssistantAgent
|
||||
from autogen_agentchat.teams import SelectorGroupChat
|
||||
|
@ -273,15 +280,19 @@ class SelectorGroupChat(BaseGroupChat):
|
|||
return "Agent2"
|
||||
return None
|
||||
|
||||
team = SelectorGroupChat([agent1, agent2], model_client=model_client, selector_func=selector_func)
|
||||
termination = TextMentionTermination("Correct!")
|
||||
team = SelectorGroupChat(
|
||||
[agent1, agent2],
|
||||
model_client=model_client,
|
||||
selector_func=selector_func,
|
||||
termination_condition=termination,
|
||||
)
|
||||
|
||||
stream = team.run_stream("What is 1 + 1?", termination_condition=TextMentionTermination("Correct!"))
|
||||
stream = team.run_stream("What is 1 + 1?")
|
||||
async for message in stream:
|
||||
print(message)
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
asyncio.run(main())
|
||||
"""
|
||||
|
||||
|
@ -290,6 +301,7 @@ class SelectorGroupChat(BaseGroupChat):
|
|||
participants: List[ChatAgent],
|
||||
model_client: ChatCompletionClient,
|
||||
*,
|
||||
termination_condition: TerminationCondition | None = None,
|
||||
selector_prompt: str = """You are in a role play game. The following roles are available:
|
||||
{roles}.
|
||||
Read the following conversation. Then select the next role from {participants} to play. Only return the role.
|
||||
|
@ -301,7 +313,9 @@ Read the above conversation. Then select the next role from {participants} to pl
|
|||
allow_repeated_speaker: bool = False,
|
||||
selector_func: Callable[[Sequence[ChatMessage]], str | None] | None = None,
|
||||
):
|
||||
super().__init__(participants, group_chat_manager_class=SelectorGroupChatManager)
|
||||
super().__init__(
|
||||
participants, group_chat_manager_class=SelectorGroupChatManager, termination_condition=termination_condition
|
||||
)
|
||||
# Validate the participants.
|
||||
if len(participants) < 2:
|
||||
raise ValueError("At least two participants are required for SelectorGroupChat.")
|
||||
|
|
|
@ -56,6 +56,8 @@ class Swarm(BaseGroupChat):
|
|||
|
||||
Args:
|
||||
participants (List[ChatAgent]): The agents participating in the group chat. The first agent in the list is the initial speaker.
|
||||
termination_condition (TerminationCondition, optional): The termination condition for the group chat. Defaults to None.
|
||||
Without a termination condition, the group chat will run indefinitely.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -81,9 +83,10 @@ class Swarm(BaseGroupChat):
|
|||
"Bob", model_client=model_client, system_message="You are Bob and your birthday is on 1st January."
|
||||
)
|
||||
|
||||
team = Swarm([agent1, agent2])
|
||||
termination = MaxMessageTermination(3)
|
||||
team = Swarm([agent1, agent2], termination_condition=termination)
|
||||
|
||||
stream = team.run_stream("What is bob's birthday?", termination_condition=MaxMessageTermination(3))
|
||||
stream = team.run_stream("What is bob's birthday?")
|
||||
async for message in stream:
|
||||
print(message)
|
||||
|
||||
|
@ -91,8 +94,12 @@ class Swarm(BaseGroupChat):
|
|||
asyncio.run(main())
|
||||
"""
|
||||
|
||||
def __init__(self, participants: List[ChatAgent]):
|
||||
super().__init__(participants, group_chat_manager_class=SwarmGroupChatManager)
|
||||
def __init__(
|
||||
self, participants: List[ChatAgent], termination_condition: TerminationCondition | None = None
|
||||
) -> None:
|
||||
super().__init__(
|
||||
participants, group_chat_manager_class=SwarmGroupChatManager, termination_condition=termination_condition
|
||||
)
|
||||
# The first participant must be able to produce handoff messages.
|
||||
first_participant = self._participants[0]
|
||||
if HandoffMessage not in first_participant.produced_message_types:
|
||||
|
|
|
@ -148,10 +148,12 @@ async def test_round_robin_group_chat(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
coding_assistant_agent = AssistantAgent(
|
||||
"coding_assistant", model_client=OpenAIChatCompletionClient(model=model, api_key="")
|
||||
)
|
||||
team = RoundRobinGroupChat(participants=[coding_assistant_agent, code_executor_agent])
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = RoundRobinGroupChat(
|
||||
participants=[coding_assistant_agent, code_executor_agent], termination_condition=termination
|
||||
)
|
||||
result = await team.run(
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
termination_condition=TextMentionTermination("TERMINATE"),
|
||||
)
|
||||
expected_messages = [
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
|
@ -171,8 +173,9 @@ async def test_round_robin_group_chat(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
# Test streaming.
|
||||
mock.reset()
|
||||
index = 0
|
||||
await termination.reset()
|
||||
async for message in team.run_stream(
|
||||
"Write a program that prints 'Hello, world!'", termination_condition=TextMentionTermination("TERMINATE")
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
):
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
|
@ -244,10 +247,10 @@ async def test_round_robin_group_chat_with_tools(monkeypatch: pytest.MonkeyPatch
|
|||
tools=[tool],
|
||||
)
|
||||
echo_agent = _EchoAgent("echo_agent", description="echo agent")
|
||||
team = RoundRobinGroupChat(participants=[tool_use_agent, echo_agent])
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = RoundRobinGroupChat(participants=[tool_use_agent, echo_agent], termination_condition=termination)
|
||||
result = await team.run(
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
termination_condition=TextMentionTermination("TERMINATE"),
|
||||
)
|
||||
|
||||
assert len(result.messages) == 6
|
||||
|
@ -274,8 +277,9 @@ async def test_round_robin_group_chat_with_tools(monkeypatch: pytest.MonkeyPatch
|
|||
tool_use_agent._model_context.clear() # pyright: ignore
|
||||
mock.reset()
|
||||
index = 0
|
||||
await termination.reset()
|
||||
async for message in team.run_stream(
|
||||
"Write a program that prints 'Hello, world!'", termination_condition=TextMentionTermination("TERMINATE")
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
):
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
|
@ -345,13 +349,14 @@ async def test_selector_group_chat(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
agent1 = _StopAgent("agent1", description="echo agent 1", stop_at=2)
|
||||
agent2 = _EchoAgent("agent2", description="echo agent 2")
|
||||
agent3 = _EchoAgent("agent3", description="echo agent 3")
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = SelectorGroupChat(
|
||||
participants=[agent1, agent2, agent3],
|
||||
model_client=OpenAIChatCompletionClient(model=model, api_key=""),
|
||||
termination_condition=termination,
|
||||
)
|
||||
result = await team.run(
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
termination_condition=TextMentionTermination("TERMINATE"),
|
||||
)
|
||||
assert len(result.messages) == 6
|
||||
assert result.messages[0].content == "Write a program that prints 'Hello, world!'"
|
||||
|
@ -365,8 +370,9 @@ async def test_selector_group_chat(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
mock.reset()
|
||||
agent1._count = 0 # pyright: ignore
|
||||
index = 0
|
||||
await termination.reset()
|
||||
async for message in team.run_stream(
|
||||
"Write a program that prints 'Hello, world!'", termination_condition=TextMentionTermination("TERMINATE")
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
):
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
|
@ -395,13 +401,14 @@ async def test_selector_group_chat_two_speakers(monkeypatch: pytest.MonkeyPatch)
|
|||
|
||||
agent1 = _StopAgent("agent1", description="echo agent 1", stop_at=2)
|
||||
agent2 = _EchoAgent("agent2", description="echo agent 2")
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = SelectorGroupChat(
|
||||
participants=[agent1, agent2],
|
||||
termination_condition=termination,
|
||||
model_client=OpenAIChatCompletionClient(model=model, api_key=""),
|
||||
)
|
||||
result = await team.run(
|
||||
"Write a program that prints 'Hello, world!'",
|
||||
termination_condition=TextMentionTermination("TERMINATE"),
|
||||
)
|
||||
assert len(result.messages) == 5
|
||||
assert result.messages[0].content == "Write a program that prints 'Hello, world!'"
|
||||
|
@ -416,9 +423,8 @@ async def test_selector_group_chat_two_speakers(monkeypatch: pytest.MonkeyPatch)
|
|||
mock.reset()
|
||||
agent1._count = 0 # pyright: ignore
|
||||
index = 0
|
||||
async for message in team.run_stream(
|
||||
"Write a program that prints 'Hello, world!'", termination_condition=TextMentionTermination("TERMINATE")
|
||||
):
|
||||
await termination.reset()
|
||||
async for message in team.run_stream("Write a program that prints 'Hello, world!'"):
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
else:
|
||||
|
@ -466,14 +472,14 @@ async def test_selector_group_chat_two_speakers_allow_repeated(monkeypatch: pyte
|
|||
|
||||
agent1 = _StopAgent("agent1", description="echo agent 1", stop_at=1)
|
||||
agent2 = _EchoAgent("agent2", description="echo agent 2")
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = SelectorGroupChat(
|
||||
participants=[agent1, agent2],
|
||||
model_client=OpenAIChatCompletionClient(model=model, api_key=""),
|
||||
termination_condition=termination,
|
||||
allow_repeated_speaker=True,
|
||||
)
|
||||
result = await team.run(
|
||||
"Write a program that prints 'Hello, world!'", termination_condition=TextMentionTermination("TERMINATE")
|
||||
)
|
||||
result = await team.run("Write a program that prints 'Hello, world!'")
|
||||
assert len(result.messages) == 4
|
||||
assert result.messages[0].content == "Write a program that prints 'Hello, world!'"
|
||||
assert result.messages[1].source == "agent2"
|
||||
|
@ -483,9 +489,8 @@ async def test_selector_group_chat_two_speakers_allow_repeated(monkeypatch: pyte
|
|||
# Test streaming.
|
||||
mock.reset()
|
||||
index = 0
|
||||
async for message in team.run_stream(
|
||||
"Write a program that prints 'Hello, world!'", termination_condition=TextMentionTermination("TERMINATE")
|
||||
):
|
||||
await termination.reset()
|
||||
async for message in team.run_stream("Write a program that prints 'Hello, world!'"):
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
else:
|
||||
|
@ -527,12 +532,14 @@ async def test_selector_group_chat_custom_selector(monkeypatch: pytest.MonkeyPat
|
|||
else:
|
||||
return "agent1"
|
||||
|
||||
termination = MaxMessageTermination(6)
|
||||
team = SelectorGroupChat(
|
||||
participants=[agent1, agent2, agent3, agent4],
|
||||
model_client=OpenAIChatCompletionClient(model=model, api_key=""),
|
||||
selector_func=_select_agent,
|
||||
termination_condition=termination,
|
||||
)
|
||||
result = await team.run("task", termination_condition=MaxMessageTermination(6))
|
||||
result = await team.run("task")
|
||||
assert len(result.messages) == 6
|
||||
assert result.messages[1].source == "agent1"
|
||||
assert result.messages[2].source == "agent2"
|
||||
|
@ -564,8 +571,9 @@ async def test_swarm_handoff() -> None:
|
|||
second_agent = _HandOffAgent("second_agent", description="second agent", next_agent="third_agent")
|
||||
third_agent = _HandOffAgent("third_agent", description="third agent", next_agent="first_agent")
|
||||
|
||||
team = Swarm([second_agent, first_agent, third_agent])
|
||||
result = await team.run("task", termination_condition=MaxMessageTermination(6))
|
||||
termination = MaxMessageTermination(6)
|
||||
team = Swarm([second_agent, first_agent, third_agent], termination_condition=termination)
|
||||
result = await team.run("task")
|
||||
assert len(result.messages) == 6
|
||||
assert result.messages[0].content == "task"
|
||||
assert result.messages[1].content == "Transferred to third_agent."
|
||||
|
@ -576,7 +584,8 @@ async def test_swarm_handoff() -> None:
|
|||
|
||||
# Test streaming.
|
||||
index = 0
|
||||
stream = team.run_stream("task", termination_condition=MaxMessageTermination(6))
|
||||
await termination.reset()
|
||||
stream = team.run_stream("task")
|
||||
async for message in stream:
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
|
@ -648,8 +657,9 @@ async def test_swarm_handoff_using_tool_calls(monkeypatch: pytest.MonkeyPatch) -
|
|||
handoffs=[Handoff(target="agent2", name="handoff_to_agent2", message="handoff to agent2")],
|
||||
)
|
||||
agent2 = _HandOffAgent("agent2", description="agent 2", next_agent="agent1")
|
||||
team = Swarm([agent1, agent2])
|
||||
result = await team.run("task", termination_condition=TextMentionTermination("TERMINATE"))
|
||||
termination = TextMentionTermination("TERMINATE")
|
||||
team = Swarm([agent1, agent2], termination_condition=termination)
|
||||
result = await team.run("task")
|
||||
assert len(result.messages) == 7
|
||||
assert result.messages[0].content == "task"
|
||||
assert isinstance(result.messages[1], ToolCallMessage)
|
||||
|
@ -663,7 +673,8 @@ async def test_swarm_handoff_using_tool_calls(monkeypatch: pytest.MonkeyPatch) -
|
|||
agent1._model_context.clear() # pyright: ignore
|
||||
mock.reset()
|
||||
index = 0
|
||||
stream = team.run_stream("task", termination_condition=TextMentionTermination("TERMINATE"))
|
||||
await termination.reset()
|
||||
stream = team.run_stream("task")
|
||||
async for message in stream:
|
||||
if isinstance(message, TaskResult):
|
||||
assert message == result
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue