Skip to content

A programming framework for agentic AI

organize core submodule (#27)

Jack Gerritsafc1666d5bba
diff --git a/examples/futures.py b/examples/futures.py
index e82d88169..aa38157b6 100644
--- a/examples/futures.py
+++ b/examples/futures.py
@@ -2,10 +2,8 @@ import asyncio
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
diff --git a/examples/patterns.py b/examples/patterns.py
index 9dc0f6b35..f12adca79 100644
--- a/examples/patterns.py
+++ b/examples/patterns.py
@@ -4,7 +4,7 @@ from typing import Any
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
diff --git a/src/agnext/agent_components/type_routed_agent.py b/src/agnext/agent_components/type_routed_agent.py
index 3cf4df40d..ba471fca5 100644
--- a/src/agnext/agent_components/type_routed_agent.py
+++ b/src/agnext/agent_components/type_routed_agent.py
@@ -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")
diff --git a/src/agnext/application_components/__init__.py b/src/agnext/application_components/__init__.py
index 26874edf2..0f52606bf 100644
--- a/src/agnext/application_components/__init__.py
+++ b/src/agnext/application_components/__init__.py
@@ -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"]
diff --git a/src/agnext/application_components/single_threaded_agent_runtime.py b/src/agnext/application_components/_single_threaded_agent_runtime.py
similarity index 96%
rename from src/agnext/application_components/single_threaded_agent_runtime.py
rename to src/agnext/application_components/_single_threaded_agent_runtime.py
index 906b1dd03..6651509a8 100644
--- a/src/agnext/application_components/single_threaded_agent_runtime.py
+++ b/src/agnext/application_components/_single_threaded_agent_runtime.py
@@ -3,12 +3,9 @@ from asyncio import Future
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)
diff --git a/src/agnext/chat/agents/base.py b/src/agnext/chat/agents/base.py
index 14934f17d..5ee360528 100644
--- a/src/agnext/chat/agents/base.py
+++ b/src/agnext/chat/agents/base.py
@@ -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):
diff --git a/src/agnext/chat/agents/oai_assistant.py b/src/agnext/chat/agents/oai_assistant.py
index 27c6d01d3..7108f454a 100644
--- a/src/agnext/chat/agents/oai_assistant.py
+++ b/src/agnext/chat/agents/oai_assistant.py
@@ -3,8 +3,7 @@ import openai
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):
diff --git a/src/agnext/chat/agents/random_agent.py b/src/agnext/chat/agents/random_agent.py
index 1df2e17db..afe6bb601 100644
--- a/src/agnext/chat/agents/random_agent.py
+++ b/src/agnext/chat/agents/random_agent.py
@@ -2,7 +2,7 @@ import random
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
diff --git a/src/agnext/chat/patterns/group_chat.py b/src/agnext/chat/patterns/group_chat.py
index 08a6f762d..83d9f1ec8 100644
--- a/src/agnext/chat/patterns/group_chat.py
+++ b/src/agnext/chat/patterns/group_chat.py
@@ -2,8 +2,7 @@ from typing import Any, List, Protocol, Sequence
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
diff --git a/src/agnext/chat/patterns/orchestrator.py b/src/agnext/chat/patterns/orchestrator.py
index ca0902945..21eb03f49 100644
--- a/src/agnext/chat/patterns/orchestrator.py
+++ b/src/agnext/chat/patterns/orchestrator.py
@@ -4,8 +4,7 @@ from typing import Any, List, Sequence, Tuple
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
diff --git a/src/agnext/core/__init__.py b/src/agnext/core/__init__.py
index 786971c52..0a843c2c9 100644
--- a/src/agnext/core/__init__.py
+++ b/src/agnext/core/__init__.py
@@ -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"]
diff --git a/src/agnext/core/agent.py b/src/agnext/core/_agent.py
similarity index 94%
rename from src/agnext/core/agent.py
rename to src/agnext/core/_agent.py
index 01d8c599f..d50a1c06f 100644
--- a/src/agnext/core/agent.py
+++ b/src/agnext/core/_agent.py
@@ -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
diff --git a/src/agnext/core/agent_runtime.py b/src/agnext/core/_agent_runtime.py
similarity index 89%
rename from src/agnext/core/agent_runtime.py
rename to src/agnext/core/_agent_runtime.py
index e886a11a3..ca39479c2 100644
--- a/src/agnext/core/agent_runtime.py
+++ b/src/agnext/core/_agent_runtime.py
@@ -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
diff --git a/src/agnext/core/base_agent.py b/src/agnext/core/_base_agent.py
similarity index 92%
rename from src/agnext/core/base_agent.py
rename to src/agnext/core/_base_agent.py
index 51ef4f536..d0d4f2c88 100644
--- a/src/agnext/core/base_agent.py
+++ b/src/agnext/core/_base_agent.py
@@ -2,10 +2,10 @@ from abc import ABC, abstractmethod
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)
diff --git a/src/agnext/core/cancellation_token.py b/src/agnext/core/_cancellation_token.py
similarity index 100%
rename from src/agnext/core/cancellation_token.py
rename to src/agnext/core/_cancellation_token.py
diff --git a/src/agnext/core/exceptions.py b/src/agnext/core/exceptions.py
index c3b21b60e..4c4a70ded 100644
--- a/src/agnext/core/exceptions.py
+++ b/src/agnext/core/exceptions.py
@@ -1,3 +1,10 @@
+__all__ = [
+ "CantHandleException",
+ "UndeliverableException",
+ "MessageDroppedException",
+]
+
+
class CantHandleException(Exception):
"""Raised when a handler can't handle the exception."""
diff --git a/src/agnext/core/intervention.py b/src/agnext/core/intervention.py
index 4ceb016f7..e80edc86f 100644
--- a/src/agnext/core/intervention.py
+++ b/src/agnext/core/intervention.py
@@ -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
diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py
index 5473261b5..d82b40096 100644
--- a/tests/test_cancellation.py
+++ b/tests/test_cancellation.py
@@ -3,10 +3,10 @@ import pytest
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:
diff --git a/tests/test_intervention.py b/tests/test_intervention.py
index c712db97f..6e786bc0c 100644
--- a/tests/test_intervention.py
+++ b/tests/test_intervention.py
@@ -2,10 +2,10 @@ import pytest
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
diff --git a/tests/test_runtime.py b/tests/test_runtime.py
index 1935f8ab2..c69534d43 100644
--- a/tests/test_runtime.py
+++ b/tests/test_runtime.py
@@ -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: