import logging from typing import Any, Callable from core.agent import BaseAgent from core.prompts import NOTIFICATION_READER_SYSTEM_PROMPT from core.notification_tools import NotificationTools logger: logging.Logger = logging.getLogger("agent-notification-reader") class NotificationNoToolCalledError(Exception): """Raised when the Notification Reader Agent completes execution without calling any routing tool.""" pass class NotificationReaderAgent(BaseAgent): """AI agent that reviews Gitea notifications and decides how to route them.""" def __init__(self, model_name: str) -> None: super().__init__(model_name) self.system_prompt: str = NOTIFICATION_READER_SYSTEM_PROMPT async def decide_notification( self, mission: str, inspection_tools: list[Callable[..., Any]], notification_tools: NotificationTools, ) -> str: """Run the Notification Reader Agent and ensure a decision tool is called.""" decision_tools: list[Callable[..., Any]] = [ notification_tools.process_issue, notification_tools.process_pr, notification_tools.skip_notification, ] combined_tools: list[Callable[..., Any]] = inspection_tools + decision_tools logger.info("Running NotificationReaderAgent to decide action...") response_text: str = await self.run_with_tools(mission, combined_tools) if not notification_tools.tool_called: logger.warning("NotificationReaderAgent did not call any tools!") raise NotificationNoToolCalledError( "NotificationReaderAgent failed to call a routing tool during execution." ) return response_text