|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import pytest
- from autogen_agentchat.agents import StopMessage, TextMessage
- from autogen_agentchat.teams import MaxMessageTermination, StopMessageTermination, TextMentionTermination
-
-
- @pytest.mark.asyncio
- async def test_stop_message_termination() -> None:
- termination = StopMessageTermination()
- assert await termination([]) is None
- await termination.reset()
- assert await termination([TextMessage(content="Hello", source="user")]) is None
- await termination.reset()
- assert await termination([StopMessage(content="Stop", source="user")]) is not None
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="World", source="agent")])
- is None
- )
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), StopMessage(content="Stop", source="user")])
- is not None
- )
-
-
- @pytest.mark.asyncio
- async def test_max_message_termination() -> None:
- termination = MaxMessageTermination(2)
- assert await termination([]) is None
- await termination.reset()
- assert await termination([TextMessage(content="Hello", source="user")]) is None
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="World", source="agent")])
- is not None
- )
-
-
- @pytest.mark.asyncio
- async def test_mention_termination() -> None:
- termination = TextMentionTermination("stop")
- assert await termination([]) is None
- await termination.reset()
- assert await termination([TextMessage(content="Hello", source="user")]) is None
- await termination.reset()
- assert await termination([TextMessage(content="stop", source="user")]) is not None
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="stop", source="user")])
- is not None
- )
-
-
- @pytest.mark.asyncio
- async def test_and_termination() -> None:
- termination = MaxMessageTermination(2) & TextMentionTermination("stop")
- assert await termination([]) is None
- await termination.reset()
- assert await termination([TextMessage(content="Hello", source="user")]) is None
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="World", source="agent")])
- is None
- )
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="stop", source="user")])
- is not None
- )
-
-
- @pytest.mark.asyncio
- async def test_or_termination() -> None:
- termination = MaxMessageTermination(3) | TextMentionTermination("stop")
- assert await termination([]) is None
- await termination.reset()
- assert await termination([TextMessage(content="Hello", source="user")]) is None
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="World", source="agent")])
- is None
- )
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="stop", source="user")])
- is not None
- )
- await termination.reset()
- assert (
- await termination([TextMessage(content="Hello", source="user"), TextMessage(content="Hello", source="user")])
- is None
- )
- await termination.reset()
- assert (
- await termination(
- [
- TextMessage(content="Hello", source="user"),
- TextMessage(content="Hello", source="user"),
- TextMessage(content="Hello", source="user"),
- ]
- )
- is not None
- )
- await termination.reset()
- assert (
- await termination(
- [
- TextMessage(content="Hello", source="user"),
- TextMessage(content="Hello", source="user"),
- TextMessage(content="stop", source="user"),
- ]
- )
- is not None
- )
- await termination.reset()
- assert (
- await termination(
- [
- TextMessage(content="Hello", source="user"),
- TextMessage(content="Hello", source="user"),
- TextMessage(content="Hello", source="user"),
- TextMessage(content="stop", source="user"),
- ]
- )
- is not None
- )
|