2024-05-27 16:33:28 -04:00
|
|
|
from typing import Any, Sequence
|
|
|
|
|
2024-06-05 15:48:14 -04:00
|
|
|
import pytest
|
2024-06-04 10:00:05 -04:00
|
|
|
from agnext.application import SingleThreadedAgentRuntime
|
2024-06-05 15:48:14 -04:00
|
|
|
from agnext.core import AgentRuntime, BaseAgent, CancellationToken
|
|
|
|
|
2024-05-27 16:33:28 -04:00
|
|
|
|
2024-06-09 12:11:36 -07:00
|
|
|
class NoopAgent(BaseAgent): # type: ignore
|
2024-06-17 10:44:46 -04:00
|
|
|
def __init__(self, name: str, runtime: AgentRuntime) -> None: # type: ignore
|
|
|
|
super().__init__(name, "A no op agent", [], runtime)
|
2024-05-27 16:33:28 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def subscriptions(self) -> Sequence[type]:
|
|
|
|
return []
|
|
|
|
|
2024-06-09 12:11:36 -07:00
|
|
|
async def on_message(self, message: Any, cancellation_token: CancellationToken) -> Any: # type: ignore
|
2024-05-27 16:33:28 -04:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_agent_names_must_be_unique() -> None:
|
2024-06-17 10:44:46 -04:00
|
|
|
runtime = SingleThreadedAgentRuntime()
|
2024-05-27 16:33:28 -04:00
|
|
|
|
2024-06-17 10:44:46 -04:00
|
|
|
_agent1 = NoopAgent("name1", runtime)
|
2024-05-27 16:33:28 -04:00
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
2024-06-17 10:44:46 -04:00
|
|
|
_agent1_again = NoopAgent("name1", runtime)
|
2024-05-27 16:33:28 -04:00
|
|
|
|
2024-06-17 10:44:46 -04:00
|
|
|
_agent3 = NoopAgent("name3", runtime)
|
2024-05-27 16:33:28 -04:00
|
|
|
|
|
|
|
|