Skip to content

πŸ™Œ OpenHands: AI-Driven Development

(fix) confirmation mode bugfix for the EventStreamRuntime (#3695)

Mislav Balunovicf979d612ec3a
diff --git a/agenthub/codeact_agent/codeact_agent.py b/agenthub/codeact_agent/codeact_agent.py
index 79d0423e8e..497c923da8 100644
--- a/agenthub/codeact_agent/codeact_agent.py
+++ b/agenthub/codeact_agent/codeact_agent.py
@@ -17,6 +17,7 @@ from openhands.events.observation import (
AgentDelegateObservation,
CmdOutputObservation,
IPythonRunCellObservation,
+ UserRejectObservation,
)
from openhands.events.observation.error import ErrorObservation
from openhands.events.observation.observation import Observation
@@ -153,6 +154,10 @@ class CodeActAgent(Agent):
text = 'OBSERVATION:\n' + truncate_content(obs.content, max_message_chars)
text += '\n[Error occurred in processing last action]'
return Message(role='user', content=[TextContent(text=text)])
+ elif isinstance(obs, UserRejectObservation):
+ text = 'OBSERVATION:\n' + truncate_content(obs.content, max_message_chars)
+ text += '\n[Last action has been rejected by the user]'
+ return Message(role='user', content=[TextContent(text=text)])
else:
# If an observation message is not returned, it will cause an error
# when the LLM tries to return the next message
diff --git a/openhands/events/observation/reject.py b/openhands/events/observation/reject.py
index 3475b19319..16973c8083 100644
--- a/openhands/events/observation/reject.py
+++ b/openhands/events/observation/reject.py
@@ -6,7 +6,7 @@ from openhands.events.observation.observation import Observation
@dataclass
class UserRejectObservation(Observation):
- """This data class represents the result of a successful action."""
+ """This data class represents the result of a rejected action."""
observation: str = ObservationType.USER_REJECTED
diff --git a/openhands/runtime/client/runtime.py b/openhands/runtime/client/runtime.py
index 521a2a1caf..6be31fa059 100644
--- a/openhands/runtime/client/runtime.py
+++ b/openhands/runtime/client/runtime.py
@@ -13,6 +13,7 @@ from openhands.core.config import AppConfig
from openhands.core.logger import openhands_logger as logger
from openhands.events import EventStream
from openhands.events.action import (
+ ActionConfirmationStatus,
BrowseInteractiveAction,
BrowseURLAction,
CmdRunAction,
@@ -25,6 +26,7 @@ from openhands.events.observation import (
ErrorObservation,
NullObservation,
Observation,
+ UserRejectObservation,
)
from openhands.events.serialization import event_to_dict, observation_from_dict
from openhands.events.serialization.action import ACTION_TYPE_TO_CLASS
@@ -333,6 +335,12 @@ class EventStreamRuntime(Runtime):
with self.action_semaphore:
if not action.runnable:
return NullObservation('')
+ if (
+ hasattr(action, 'is_confirmed')
+ and action.is_confirmed
+ == ActionConfirmationStatus.AWAITING_CONFIRMATION
+ ):
+ return NullObservation('')
action_type = action.action # type: ignore[attr-defined]
if action_type not in ACTION_TYPE_TO_CLASS:
return ErrorObservation(f'Action {action_type} does not exist.')
@@ -340,6 +348,13 @@ class EventStreamRuntime(Runtime):
return ErrorObservation(
f'Action {action_type} is not supported in the current runtime.'
)
+ if (
+ hasattr(action, 'is_confirmed')
+ and action.is_confirmed == ActionConfirmationStatus.REJECTED
+ ):
+ return UserRejectObservation(
+ 'Action has been rejected by the user! Waiting for further user input.'
+ )
logger.info('Awaiting session')
self._wait_until_alive()