A programming framework for agentic AI
organize core submodule (#27)
Jack Gerritsafc1666d5bba
diff --git a/examples/futures.py b/examples/futures.pyindex e82d88169..aa38157b6 100644--- a/examples/futures.py+++ b/examples/futures.py@@ -2,10 +2,8 @@ import asynciofrom dataclasses import dataclassfrom 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@dataclassdiff --git a/examples/patterns.py b/examples/patterns.pyindex 9dc0f6b35..f12adca79 100644--- a/examples/patterns.py+++ b/examples/patterns.py@@ -4,7 +4,7 @@ from typing import Anyimport openaifrom 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 OpenAIAssistantAgentdiff --git a/src/agnext/agent_components/type_routed_agent.py b/src/agnext/agent_components/type_routed_agent.pyindex 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, CancellationTokenfrom agnext.core.exceptions import CantHandleExceptionReceivesT = TypeVar("ReceivesT")diff --git a/src/agnext/application_components/__init__.py b/src/agnext/application_components/__init__.pyindex 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.pysimilarity index 96%rename from src/agnext/application_components/single_threaded_agent_runtime.pyrename to src/agnext/application_components/_single_threaded_agent_runtime.pyindex 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 Futurefrom dataclasses import dataclassfrom 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.pyindex 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, BaseAgentclass BaseChatAgent(BaseAgent):diff --git a/src/agnext/chat/agents/oai_assistant.py b/src/agnext/chat/agents/oai_assistant.pyindex 27c6d01d3..7108f454a 100644--- a/src/agnext/chat/agents/oai_assistant.py+++ b/src/agnext/chat/agents/oai_assistant.py@@ -3,8 +3,7 @@ import openaifrom agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handlerfrom agnext.chat.agents.base import BaseChatAgentfrom 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, CancellationTokenclass OpenAIAssistantAgent(BaseChatAgent, TypeRoutedAgent):diff --git a/src/agnext/chat/agents/random_agent.py b/src/agnext/chat/agents/random_agent.pyindex 1df2e17db..afe6bb601 100644--- a/src/agnext/chat/agents/random_agent.py+++ b/src/agnext/chat/agents/random_agent.py@@ -2,7 +2,7 @@ import randomfrom agnext.agent_components.type_routed_agent import TypeRoutedAgent, message_handlerfrom agnext.chat.types import RespondNow, TextMessage-from agnext.core.cancellation_token import CancellationToken+from agnext.core import CancellationTokenfrom ..agents.base import BaseChatAgentdiff --git a/src/agnext/chat/patterns/group_chat.py b/src/agnext/chat/patterns/group_chat.pyindex 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, Sequencefrom agnext.chat.types import Reset, RespondNow-from ...core.agent_runtime import AgentRuntime-from ...core.cancellation_token import CancellationToken+from ...core import AgentRuntime, CancellationTokenfrom ..agents.base import BaseChatAgentdiff --git a/src/agnext/chat/patterns/orchestrator.py b/src/agnext/chat/patterns/orchestrator.pyindex 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, Tuplefrom ...agent_components.model_client import ModelClientfrom ...agent_components.type_routed_agent import TypeRoutedAgent, message_handlerfrom ...agent_components.types import AssistantMessage, LLMMessage, UserMessage-from ...core.agent_runtime import AgentRuntime-from ...core.cancellation_token import CancellationToken+from ...core import AgentRuntime, CancellationTokenfrom ..agents.base import BaseChatAgentfrom ..messages import ChatMessagediff --git a/src/agnext/core/__init__.py b/src/agnext/core/__init__.pyindex 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.pysimilarity index 94%rename from src/agnext/core/agent.pyrename to src/agnext/core/_agent.pyindex 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_checkablediff --git a/src/agnext/core/agent_runtime.py b/src/agnext/core/_agent_runtime.pysimilarity index 89%rename from src/agnext/core/agent_runtime.pyrename to src/agnext/core/_agent_runtime.pyindex e886a11a3..ca39479c2 100644--- a/src/agnext/core/agent_runtime.py+++ b/src/agnext/core/_agent_runtime.py@@ -1,8 +1,8 @@from asyncio import Futurefrom 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 - errordiff --git a/src/agnext/core/base_agent.py b/src/agnext/core/_base_agent.pysimilarity index 92%rename from src/agnext/core/base_agent.pyrename to src/agnext/core/_base_agent.pyindex 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, abstractmethodfrom asyncio import Futurefrom 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 AgentConsumesT = TypeVar("ConsumesT")ProducesT = TypeVar("ProducesT", covariant=True)diff --git a/src/agnext/core/cancellation_token.py b/src/agnext/core/_cancellation_token.pysimilarity index 100%rename from src/agnext/core/cancellation_token.pyrename to src/agnext/core/_cancellation_token.pydiff --git a/src/agnext/core/exceptions.py b/src/agnext/core/exceptions.pyindex 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.pyindex 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",+]@finaldiff --git a/tests/test_cancellation.py b/tests/test_cancellation.pyindex 5473261b5..d82b40096 100644--- a/tests/test_cancellation.py+++ b/tests/test_cancellation.py@@ -3,10 +3,10 @@ import pytestfrom dataclasses import dataclassfrom 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@dataclassclass MessageType:diff --git a/tests/test_intervention.py b/tests/test_intervention.pyindex c712db97f..6e786bc0c 100644--- a/tests/test_intervention.py+++ b/tests/test_intervention.py@@ -2,10 +2,10 @@ import pytestfrom dataclasses import dataclassfrom 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 CancellationTokenfrom agnext.core.exceptions import MessageDroppedExceptionfrom agnext.core.intervention import DefaultInterventionHandler, DropMessagediff --git a/tests/test_runtime.py b/tests/test_runtime.pyindex 1935f8ab2..c69534d43 100644--- a/tests/test_runtime.py+++ b/tests/test_runtime.py@@ -1,10 +1,10 @@from typing import Any, Sequenceimport 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 CancellationTokenclass NoopAgent(BaseAgent):def __init__(self, name: str, router: AgentRuntime) -> None: