Skip to content

Commit

Permalink
Rename message router to agent runtime (autogenhub#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits authored May 16, 2024
1 parent f32f9ee commit 0267512
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
10 changes: 5 additions & 5 deletions examples/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from dataclasses import dataclass

from agnext.core.agent import Agent
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.message import Message
from agnext.core.message_router import MessageRouter
from agnext.queue_message_router import QueueMessageRouter
from agnext.single_threaded_agent_runtime import SingleThreadedAgentRuntime
from agnext.type_routed_agent import TypeRoutedAgent, event_handler


Expand All @@ -15,7 +15,7 @@ class MessageType(Message):


class Inner(TypeRoutedAgent[MessageType]):
def __init__(self, name: str, router: MessageRouter[MessageType]) -> None:
def __init__(self, name: str, router: AgentRuntime[MessageType]) -> None:
super().__init__(name, router)

@event_handler(MessageType)
Expand All @@ -24,7 +24,7 @@ async def on_new_event(self, event: MessageType) -> MessageType:


class Outer(TypeRoutedAgent[MessageType]):
def __init__(self, name: str, router: MessageRouter[MessageType], inner: Agent[MessageType]) -> None:
def __init__(self, name: str, router: AgentRuntime[MessageType], inner: Agent[MessageType]) -> None:
super().__init__(name, router)
self._inner = inner

Expand All @@ -36,7 +36,7 @@ async def on_new_event(self, event: MessageType) -> MessageType:


async def main() -> None:
router = QueueMessageRouter[MessageType]()
router = SingleThreadedAgentRuntime[MessageType]()

inner = Inner("inner", router)
outer = Outer("outer", router, inner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Undeliverable - error


class MessageRouter(Protocol[T]):
class AgentRuntime(Protocol[T]):
def add_agent(self, agent: Agent[T]) -> None: ...

# Returns the response of the message
Expand Down
4 changes: 2 additions & 2 deletions src/agnext/core/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from asyncio import Future
from typing import List, Sequence, Type, TypeVar

from agnext.core.message_router import MessageRouter
from agnext.core.agent_runtime import AgentRuntime

from .agent import Agent
from .message import Message
Expand All @@ -11,7 +11,7 @@


class BaseAgent(ABC, Agent[T]):
def __init__(self, name: str, router: MessageRouter[T]) -> None:
def __init__(self, name: str, router: AgentRuntime[T]) -> None:
self._name = name
self._router = router

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from agnext.core.agent import Agent

from .core.agent_runtime import AgentRuntime
from .core.message import Message
from .core.message_router import MessageRouter

T = TypeVar("T", bound=Message)

Expand All @@ -28,7 +28,7 @@ class SendMessage(Generic[T]):
class ResponseMessage(Generic[T]): ...


class QueueMessageRouter(MessageRouter[T]):
class SingleThreadedAgentRuntime(AgentRuntime[T]):
def __init__(self) -> None:
self._event_queue: List[BroadcastMessage[T] | SendMessage[T]] = []
self._per_type_subscribers: Dict[Type[T], List[Agent[T]]] = {}
Expand Down
4 changes: 2 additions & 2 deletions src/agnext/type_routed_agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Awaitable, Callable, Dict, Sequence, Type, TypeVar

from agnext.core.agent_runtime import AgentRuntime
from agnext.core.base_agent import BaseAgent
from agnext.core.exceptions import CantHandleException
from agnext.core.message_router import MessageRouter

from .core.message import Message

Expand All @@ -19,7 +19,7 @@ def decorator(func: Callable[..., Awaitable[T]]) -> Callable[..., Awaitable[T]]:


class TypeRoutedAgent(BaseAgent[T]):
def __init__(self, name: str, router: MessageRouter[T]) -> None:
def __init__(self, name: str, router: AgentRuntime[T]) -> None:
super().__init__(name, router)

self._handlers: Dict[Type[Any], Callable[[T], Awaitable[T]]] = {}
Expand Down
21 changes: 21 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set -e

# Current script directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ "$VIRTUAL_ENV" == "" ]]
then
echo "Virtual environment is not activated"
exit 1
fi

cd $DIR

echo "--- Running ruff format ---"
ruff format
echo "--- Running ruff check ---"
ruff check
echo "--- Running ruff lint ---"
pyright
echo "--- Running ruff test ---"
mypy

0 comments on commit 0267512

Please sign in to comment.