diff --git a/core/dispatcher.py b/core/dispatcher.py index a297a26..e4164c7 100644 --- a/core/dispatcher.py +++ b/core/dispatcher.py @@ -11,7 +11,6 @@ from core.queue import WorkItem from core.coding_agent import CodingAgent from core.planning_agent import PlanningAgent from core.coordinator_agent import CoordinatorAgent, CoordinatorNoToolCalledError -from core.factory import AgentFactory from gitea.tools.coding_tools import CodingTools from gitea.tools.research_tools import ResearchTools diff --git a/core/factory.py b/core/factory.py deleted file mode 100644 index a9b27a8..0000000 --- a/core/factory.py +++ /dev/null @@ -1,94 +0,0 @@ -import logging -from gitea.client import GiteaClient -from core.interfaces import ( - IssuesClient, - PullRequestsClient, - FilesClient, - RefsClient, - ReposClient, -) -from core.coding_agent import CodingAgent -from core.agent import CavemanAgent -from core.coordinator_agent import CoordinatorAgent -from core.planning_agent import PlanningAgent -from core.notification_agent import NotificationReaderAgent -from gitea.workspace import WorkspaceManager - -logger: logging.Logger = logging.getLogger("core-factory") - - -class GiteaClientFactory: - """Factory for creating Gitea client components with dependency injection support.""" - - @staticmethod - def create_full_client() -> GiteaClient: - return GiteaClient() - - @staticmethod - def create_issues_client(client: GiteaClient | None = None) -> IssuesClient: - if client is None: - client = GiteaClient() - return client - - @staticmethod - def create_prs_client(client: GiteaClient | None = None) -> PullRequestsClient: - if client is None: - client = GiteaClient() - return client - - @staticmethod - def create_files_client(client: GiteaClient | None = None) -> FilesClient: - if client is None: - client = GiteaClient() - return client - - @staticmethod - def create_refs_client(client: GiteaClient | None = None) -> RefsClient: - if client is None: - client = GiteaClient() - return client - - @staticmethod - def create_repos_client(client: GiteaClient | None = None) -> ReposClient: - if client is None: - client = GiteaClient() - return client - - -class AgentFactory: - """Factory for creating AI agent instances.""" - - @staticmethod - def create_coding_agent(model_name: str) -> CodingAgent: - logger.info(f"Factory creating CodingAgent with model: {model_name}") - return CodingAgent(model_name) - - @staticmethod - def create_caveman_agent(model_name: str) -> CavemanAgent: - logger.info(f"Factory creating CavemanAgent with model: {model_name}") - return CavemanAgent(model_name) - - @staticmethod - def create_coordinator_agent(model_name: str) -> CoordinatorAgent: - logger.info(f"Factory creating CoordinatorAgent with model: {model_name}") - return CoordinatorAgent(model_name) - - @staticmethod - def create_planning_agent(model_name: str) -> PlanningAgent: - logger.info(f"Factory creating PlanningAgent with model: {model_name}") - return PlanningAgent(model_name) - - @staticmethod - def create_notification_reader_agent(model_name: str) -> NotificationReaderAgent: - logger.info(f"Factory creating NotificationReaderAgent with model: {model_name}") - return NotificationReaderAgent(model_name) - - - -class WorkspaceFactory: - """Factory for creating workspace manager instances.""" - - @staticmethod - def create_workspace() -> WorkspaceManager: - logger.info("Factory creating WorkspaceManager") - return WorkspaceManager() diff --git a/core/orchestrator.py b/core/orchestrator.py index bbf8f64..99f242e 100644 --- a/core/orchestrator.py +++ b/core/orchestrator.py @@ -14,9 +14,8 @@ from gitea.models import IssueModel, PullRequestModel, RepositoryModel from gitea.tools.gitea_tools import GiteaTools from gitea.config import AGENT_MODEL_ID, AGENT_MAX_RETRIES from gitea.workspace import WorkspaceManager -from core.factory import AgentFactory +from core.notification_agent import NotificationReaderAgent, NotificationNoToolCalledError from core.notification_tools import NotificationTools -from core.notification_agent import NotificationNoToolCalledError logger: logging.Logger = logging.getLogger("agent-orchestrator") @@ -36,7 +35,7 @@ class AgentOrchestrator: self._model_name = model_name self._work_queue = WorkQueue() self._dispatcher = AgentDispatcher(client, tools, model_name, max_retries) - self._notification_reader = AgentFactory.create_notification_reader_agent(model_name) + self._notification_reader = NotificationReaderAgent(model_name) self._max_retries = max_retries diff --git a/tests/test_orchestrator.py b/tests/test_orchestrator.py index e6aa866..3d16e48 100644 --- a/tests/test_orchestrator.py +++ b/tests/test_orchestrator.py @@ -21,9 +21,9 @@ def temp_state_file(tmp_path: Path) -> Path: @patch("core.orchestrator.AgentOrchestrator._get_state_file_path") @patch("core.orchestrator.AgentDispatcher") @patch("core.orchestrator.WorkspaceManager") -@patch("core.orchestrator.AgentFactory") +@patch("core.orchestrator.NotificationReaderAgent") async def test_poll_and_dispatch_no_notifications( - mock_factory: MagicMock, + mock_notification_reader_class: MagicMock, mock_workspace_class: MagicMock, mock_dispatcher_class: MagicMock, mock_get_path: MagicMock, @@ -46,9 +46,9 @@ async def test_poll_and_dispatch_no_notifications( @patch("core.orchestrator.AgentOrchestrator._get_state_file_path") @patch("core.orchestrator.AgentDispatcher") @patch("core.orchestrator.WorkspaceManager") -@patch("core.orchestrator.AgentFactory") +@patch("core.orchestrator.NotificationReaderAgent") async def test_poll_and_dispatch_with_notifications( - mock_factory: MagicMock, + mock_notification_reader_class: MagicMock, mock_workspace_class: MagicMock, mock_dispatcher_class: MagicMock, mock_get_path: MagicMock, @@ -66,7 +66,7 @@ async def test_poll_and_dispatch_with_notifications( notification_tools.skip_notification("Unrelated") return "Decided" mock_reader.decide_notification = AsyncMock(side_effect=mock_decide_notification) - mock_factory.create_notification_reader_agent.return_value = mock_reader + mock_notification_reader_class.return_value = mock_reader mock_client = MagicMock(spec=GiteaClient) mock_tools = MagicMock(spec=GiteaTools)