-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplify handler decorator * add more tests * mypy * formatting * fix 3.10 and improve type handling of decorator * test fix * format
- Loading branch information
1 parent
ad513d5
commit 8cb530f
Showing
10 changed files
with
191 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from agnext.chat.patterns.group_chat import GroupChat, GroupChatOutput | ||
|
||
from ...core import AgentRuntime | ||
from ..agents.base import BaseChatAgent | ||
|
||
|
||
class TwoAgentChat(GroupChat): | ||
def __init__( | ||
self, | ||
name: str, | ||
description: str, | ||
runtime: AgentRuntime, | ||
agent1: BaseChatAgent, | ||
agent2: BaseChatAgent, | ||
num_rounds: int, | ||
output: GroupChatOutput, | ||
) -> None: | ||
super().__init__(name, description, runtime, [agent1, agent2], num_rounds, output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from types import NoneType | ||
from typing import Any, Optional, Union | ||
|
||
from agnext.components.type_routed_agent import AnyType, get_types, message_handler | ||
from agnext.core import CancellationToken | ||
|
||
|
||
def test_get_types() -> None: | ||
assert get_types(Union[int, str]) == (int, str) | ||
assert get_types(int | str) == (int, str) | ||
assert get_types(int) == (int,) | ||
assert get_types(str) == (str,) | ||
assert get_types("test") is None | ||
assert get_types(Optional[int]) == (int, NoneType) | ||
assert get_types(NoneType) == (NoneType,) | ||
assert get_types(None) == (NoneType,) | ||
|
||
|
||
def test_handler() -> None: | ||
|
||
class HandlerClass: | ||
@message_handler() | ||
async def handler(self, message: int, cancellation_token: CancellationToken) -> Any: | ||
return None | ||
|
||
@message_handler() | ||
async def handler2(self, message: str | bool, cancellation_token: CancellationToken) -> None: | ||
return None | ||
|
||
assert HandlerClass.handler.target_types == [int] | ||
assert HandlerClass.handler.produces_types == [AnyType] | ||
|
||
assert HandlerClass.handler2.target_types == [str, bool] | ||
assert HandlerClass.handler2.produces_types == [NoneType] | ||
|
||
class HandlerClass: | ||
@message_handler() | ||
async def handler(self, message: int, cancellation_token: CancellationToken) -> Any: | ||
return None |