forked from autogenhub/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement intervention (autogenhub#8)
- Loading branch information
1 parent
5afbadb
commit 77c8cca
Showing
8 changed files
with
250 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import Awaitable, Callable, Protocol, Sequence, TypeVar, final | ||
|
||
from agnext.core.agent import Agent | ||
|
||
|
||
@final | ||
class DropMessage: ... | ||
|
||
|
||
T = TypeVar("T") | ||
|
||
InterventionFunction = Callable[[T], T | Awaitable[type[DropMessage]]] | ||
|
||
|
||
class InterventionHandler(Protocol[T]): | ||
async def on_send(self, message: T, *, sender: Agent[T] | None, recipient: Agent[T]) -> T | type[DropMessage]: ... | ||
async def on_broadcast(self, message: T, *, sender: Agent[T] | None) -> T | type[DropMessage]: ... | ||
async def on_response( | ||
self, message: T, *, sender: Agent[T], recipient: Agent[T] | None | ||
) -> T | type[DropMessage]: ... | ||
async def on_broadcast_response( | ||
self, message: Sequence[T], *, recipient: Agent[T] | None | ||
) -> Sequence[T] | type[DropMessage]: ... | ||
|
||
|
||
class DefaultInterventionHandler(InterventionHandler[T]): | ||
async def on_send(self, message: T, *, sender: Agent[T] | None, recipient: Agent[T]) -> T | type[DropMessage]: | ||
return message | ||
|
||
async def on_broadcast(self, message: T, *, sender: Agent[T] | None) -> T | type[DropMessage]: | ||
return message | ||
|
||
async def on_response(self, message: T, *, sender: Agent[T], recipient: Agent[T] | None) -> T | type[DropMessage]: | ||
return message | ||
|
||
async def on_broadcast_response( | ||
self, message: Sequence[T], *, recipient: Agent[T] | None | ||
) -> Sequence[T] | type[DropMessage]: | ||
return message |
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 |
---|---|---|
|
@@ -19,3 +19,5 @@ echo "--- Running pyright ---" | |
pyright | ||
echo "--- Running mypy ---" | ||
mypy | ||
echo "--- Running pytest ---" | ||
pytest |
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
Oops, something went wrong.