Skip to content

Commit

Permalink
organize core submodule (autogenhub#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits authored May 27, 2024
1 parent f8f7418 commit afc1666
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 42 deletions.
6 changes: 2 additions & 4 deletions examples/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from dataclasses import dataclass

from agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handler
from agnext.application_components.single_threaded_agent_runtime import SingleThreadedAgentRuntime
from agnext.core.agent import Agent
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.cancellation_token import CancellationToken
from agnext.application_components import SingleThreadedAgentRuntime
from agnext.core import Agent, AgentRuntime, CancellationToken


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion examples/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import openai
from agnext.agent_components.model_client import OpenAI
from agnext.application_components.single_threaded_agent_runtime import (
from agnext.application_components import (
SingleThreadedAgentRuntime,
)
from agnext.chat.agents.oai_assistant import OpenAIAssistantAgent
Expand Down
4 changes: 1 addition & 3 deletions src/agnext/agent_components/type_routed_agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Any, Callable, Coroutine, Dict, NoReturn, Sequence, Type, TypeVar

from agnext.core.agent_runtime import AgentRuntime
from agnext.core.base_agent import BaseAgent
from agnext.core.cancellation_token import CancellationToken
from agnext.core import AgentRuntime, BaseAgent, CancellationToken
from agnext.core.exceptions import CantHandleException

ReceivesT = TypeVar("ReceivesT")
Expand Down
4 changes: 4 additions & 0 deletions src/agnext/application_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
The :mod:`agnext.application_components` module provides implementations of core components that are used to compose an application
"""

from ._single_threaded_agent_runtime import SingleThreadedAgentRuntime

__all__ = ["SingleThreadedAgentRuntime"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
from dataclasses import dataclass
from typing import Any, Awaitable, Dict, List, Set

from agnext.core.cancellation_token import CancellationToken
from agnext.core.exceptions import MessageDroppedException
from agnext.core.intervention import DropMessage, InterventionHandler

from ..core.agent import Agent
from ..core.agent_runtime import AgentRuntime
from ..core import Agent, AgentRuntime, CancellationToken
from ..core.exceptions import MessageDroppedException
from ..core.intervention import DropMessage, InterventionHandler


@dataclass(kw_only=True)
Expand Down
3 changes: 1 addition & 2 deletions src/agnext/chat/agents/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.base_agent import BaseAgent
from agnext.core import AgentRuntime, BaseAgent


class BaseChatAgent(BaseAgent):
Expand Down
3 changes: 1 addition & 2 deletions src/agnext/chat/agents/oai_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handler
from agnext.chat.agents.base import BaseChatAgent
from agnext.chat.types import Reset, RespondNow, TextMessage
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.cancellation_token import CancellationToken
from agnext.core import AgentRuntime, CancellationToken


class OpenAIAssistantAgent(BaseChatAgent, TypeRoutedAgent):
Expand Down
2 changes: 1 addition & 1 deletion src/agnext/chat/agents/random_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handler
from agnext.chat.types import RespondNow, TextMessage
from agnext.core.cancellation_token import CancellationToken
from agnext.core import CancellationToken

from ..agents.base import BaseChatAgent

Expand Down
3 changes: 1 addition & 2 deletions src/agnext/chat/patterns/group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from agnext.chat.types import Reset, RespondNow

from ...core.agent_runtime import AgentRuntime
from ...core.cancellation_token import CancellationToken
from ...core import AgentRuntime, CancellationToken
from ..agents.base import BaseChatAgent


Expand Down
3 changes: 1 addition & 2 deletions src/agnext/chat/patterns/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from ...agent_components.model_client import ModelClient
from ...agent_components.type_routed_agent import TypeRoutedAgent, message_handler
from ...agent_components.types import AssistantMessage, LLMMessage, UserMessage
from ...core.agent_runtime import AgentRuntime
from ...core.cancellation_token import CancellationToken
from ...core import AgentRuntime, CancellationToken
from ..agents.base import BaseChatAgent
from ..messages import ChatMessage

Expand Down
7 changes: 7 additions & 0 deletions src/agnext/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
The :mod:`agnext.core` module provides the foundational generic interfaces upon which all else is built. This module must not depend on any other module.
"""

from ._agent import Agent
from ._agent_runtime import AgentRuntime
from ._base_agent import BaseAgent
from ._cancellation_token import CancellationToken

__all__ = ["Agent", "AgentRuntime", "BaseAgent", "CancellationToken"]
2 changes: 1 addition & 1 deletion src/agnext/core/agent.py → src/agnext/core/_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Protocol, Sequence, runtime_checkable

from agnext.core.cancellation_token import CancellationToken
from agnext.core._cancellation_token import CancellationToken


@runtime_checkable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asyncio import Future
from typing import Any, Protocol

from agnext.core.agent import Agent
from agnext.core.cancellation_token import CancellationToken
from agnext.core._agent import Agent
from agnext.core._cancellation_token import CancellationToken

# Undeliverable - error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from asyncio import Future
from typing import Any, Sequence, TypeVar

from agnext.core.agent_runtime import AgentRuntime
from agnext.core.cancellation_token import CancellationToken
from agnext.core._agent_runtime import AgentRuntime
from agnext.core._cancellation_token import CancellationToken

from .agent import Agent
from ._agent import Agent

ConsumesT = TypeVar("ConsumesT")
ProducesT = TypeVar("ProducesT", covariant=True)
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions src/agnext/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
__all__ = [
"CantHandleException",
"UndeliverableException",
"MessageDroppedException",
]


class CantHandleException(Exception):
"""Raised when a handler can't handle the exception."""

Expand Down
9 changes: 8 additions & 1 deletion src/agnext/core/intervention.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from typing import Any, Awaitable, Callable, Protocol, Sequence, final

from agnext.core.agent import Agent
from agnext.core import Agent

__all__ = [
"DropMessage",
"InterventionFunction",
"InterventionHandler",
"DefaultInterventionHandler",
]


@final
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from dataclasses import dataclass

from agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handler
from agnext.application_components.single_threaded_agent_runtime import SingleThreadedAgentRuntime
from agnext.core.agent import Agent
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.cancellation_token import CancellationToken
from agnext.application_components import SingleThreadedAgentRuntime
from agnext.core import Agent
from agnext.core import AgentRuntime
from agnext.core import CancellationToken

@dataclass
class MessageType:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_intervention.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from dataclasses import dataclass

from agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handler
from agnext.application_components.single_threaded_agent_runtime import SingleThreadedAgentRuntime
from agnext.core.agent import Agent
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.cancellation_token import CancellationToken
from agnext.application_components import SingleThreadedAgentRuntime
from agnext.core import Agent
from agnext.core import AgentRuntime
from agnext.core import CancellationToken
from agnext.core.exceptions import MessageDroppedException
from agnext.core.intervention import DefaultInterventionHandler, DropMessage

Expand Down
8 changes: 4 additions & 4 deletions tests/test_runtime.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Any, Sequence
import pytest

from agnext.application_components.single_threaded_agent_runtime import SingleThreadedAgentRuntime
from agnext.core.agent_runtime import AgentRuntime
from agnext.core.base_agent import BaseAgent
from agnext.core.cancellation_token import CancellationToken
from agnext.application_components import SingleThreadedAgentRuntime
from agnext.core import AgentRuntime
from agnext.core import BaseAgent
from agnext.core import CancellationToken

class NoopAgent(BaseAgent):
def __init__(self, name: str, router: AgentRuntime) -> None:
Expand Down

0 comments on commit afc1666

Please sign in to comment.