π OpenHands: AI-Driven Development
Update event schema types to use enum pattern (#7498)
Calvin Smith78b67bc9d95e
diff --git a/openhands/core/schema/action.py b/openhands/core/schema/action.pyindex c3e59d2c07..d330c39e49 100644--- a/openhands/core/schema/action.py+++ b/openhands/core/schema/action.py@@ -1,87 +1,83 @@-from pydantic import BaseModel, Field+from enum import Enum-__all__ = ['ActionType']--class ActionTypeSchema(BaseModel):- MESSAGE: str = Field(default='message')+class ActionType(str, Enum):+ MESSAGE = 'message'"""Represents a message."""- START: str = Field(default='start')+ START = 'start'"""Starts a new development task OR send chat from the user. Only sent by the client."""- READ: str = Field(default='read')+ READ = 'read'"""Reads the content of a file."""- WRITE: str = Field(default='write')+ WRITE = 'write'"""Writes the content to a file."""- EDIT: str = Field(default='edit')+ EDIT = 'edit'"""Edits a file by providing a draft."""- RUN: str = Field(default='run')+ RUN = 'run'"""Runs a command."""- RUN_IPYTHON: str = Field(default='run_ipython')+ RUN_IPYTHON = 'run_ipython'"""Runs a IPython cell."""- BROWSE: str = Field(default='browse')+ BROWSE = 'browse'"""Opens a web page."""- BROWSE_INTERACTIVE: str = Field(default='browse_interactive')+ BROWSE_INTERACTIVE = 'browse_interactive'"""Interact with the browser instance."""- DELEGATE: str = Field(default='delegate')+ DELEGATE = 'delegate'"""Delegates a task to another agent."""- THINK: str = Field(default='think')++ THINK = 'think'"""Logs a thought."""- FINISH: str = Field(default='finish')+ FINISH = 'finish'"""If you're absolutely certain that you've completed your task and have tested your work,use the finish action to stop working."""- REJECT: str = Field(default='reject')+ REJECT = 'reject'"""If you're absolutely certain that you cannot complete the task with given requirements,use the reject action to stop working."""- NULL: str = Field(default='null')+ NULL = 'null'- PAUSE: str = Field(default='pause')+ PAUSE = 'pause'"""Pauses the task."""- RESUME: str = Field(default='resume')+ RESUME = 'resume'"""Resumes the task."""- STOP: str = Field(default='stop')+ STOP = 'stop'"""Stops the task. Must send a start action to restart a new task."""- CHANGE_AGENT_STATE: str = Field(default='change_agent_state')+ CHANGE_AGENT_STATE = 'change_agent_state'- PUSH: str = Field(default='push')+ PUSH = 'push'"""Push a branch to github."""- SEND_PR: str = Field(default='send_pr')+ SEND_PR = 'send_pr'"""Send a PR to github."""- RECALL: str = Field(default='recall')+ RECALL = 'recall'"""Retrieves content from a user workspace, microagent, or other source."""---ActionType = ActionTypeSchema()diff --git a/openhands/core/schema/observation.py b/openhands/core/schema/observation.pyindex 89cd6183d3..e10e5460b3 100644--- a/openhands/core/schema/observation.py+++ b/openhands/core/schema/observation.py@@ -1,56 +1,51 @@-from pydantic import BaseModel, Field+from enum import Enum-__all__ = ['ObservationType']--class ObservationTypeSchema(BaseModel):- READ: str = Field(default='read')+class ObservationType(str, Enum):+ READ = 'read'"""The content of a file"""- WRITE: str = Field(default='write')+ WRITE = 'write'- EDIT: str = Field(default='edit')+ EDIT = 'edit'- BROWSE: str = Field(default='browse')+ BROWSE = 'browse'"""The HTML content of a URL"""- RUN: str = Field(default='run')+ RUN = 'run'"""The output of a command"""- RUN_IPYTHON: str = Field(default='run_ipython')+ RUN_IPYTHON = 'run_ipython'"""Runs a IPython cell."""- CHAT: str = Field(default='chat')+ CHAT = 'chat'"""A message from the user"""- DELEGATE: str = Field(default='delegate')+ DELEGATE = 'delegate'"""The result of a task delegated to another agent"""- MESSAGE: str = Field(default='message')+ MESSAGE = 'message'- ERROR: str = Field(default='error')+ ERROR = 'error'- SUCCESS: str = Field(default='success')+ SUCCESS = 'success'- NULL: str = Field(default='null')+ NULL = 'null'- THINK: str = Field(default='think')+ THINK = 'think'- AGENT_STATE_CHANGED: str = Field(default='agent_state_changed')+ AGENT_STATE_CHANGED = 'agent_state_changed'- USER_REJECTED: str = Field(default='user_rejected')+ USER_REJECTED = 'user_rejected'- CONDENSE: str = Field(default='condense')+ CONDENSE = 'condense'"""Result of a condensation operation."""- RECALL: str = Field(default='recall')+ RECALL = 'recall'"""Result of a recall operation. This can be the workspace context, a microagent, or other types of information."""---ObservationType = ObservationTypeSchema()