Small refactor to improve (CodeAct)Agent extensibility (#8244)

This commit is contained in:
Chase
2025-05-04 10:21:54 -07:00
committed by GitHub
parent 2c085ae79e
commit fc32efb52e
4 changed files with 58 additions and 32 deletions

View File

@@ -8,6 +8,7 @@ if TYPE_CHECKING:
from openhands.core.config import AgentConfig
from openhands.events.action import Action
from openhands.events.action.message import SystemMessageAction
from openhands.utils.prompt import PromptManager
from litellm import ChatCompletionToolParam
from openhands.core.exceptions import (
@@ -19,9 +20,6 @@ from openhands.events.event import EventSource
from openhands.llm.llm import LLM
from openhands.runtime.plugins import PluginRequirement
if TYPE_CHECKING:
from openhands.utils.prompt import PromptManager
class Agent(ABC):
DEPRECATED = False
@@ -43,10 +41,16 @@ class Agent(ABC):
self.llm = llm
self.config = config
self._complete = False
self.prompt_manager: 'PromptManager' | None = None
self._prompt_manager: 'PromptManager' | None = None
self.mcp_tools: dict[str, ChatCompletionToolParam] = {}
self.tools: list = []
@property
def prompt_manager(self) -> 'PromptManager':
if self._prompt_manager is None:
raise ValueError(f'Prompt manager not initialized for agent {self.name}')
return self._prompt_manager
def get_system_message(self) -> 'SystemMessageAction | None':
"""
Returns a SystemMessageAction containing the system message and tools.